cocoa-xu / evision

Evision: An OpenCV-Erlang/Elixir binding
https://evision.app
Apache License 2.0
322 stars 22 forks source link

Zoo smartcell fails face detection because Kino.Input.image changed its return structure #222

Closed jshprentz closed 7 months ago

jshprentz commented 7 months ago

Summary

Using an OpenCV Zoo smartcell with a photo captured from a webcam, face detection with YuNet failed with this message:

06:54:38.336 [error] Kino.listen with #Function<42.105768164/1 in :erl_eval.expr/6> failed with reason:

** (KeyError) key :data not found in: %{
  format: :rgb,
  width: 640,
  file_ref: {:file, "kksimljojmumjk44xlwhpv24n2cf3ivv"},
  height: 480
}
    (elixir 1.15.7) src/elixir.erl:396: :elixir.eval_external_handler/3
    (stdlib 5.1.1) erl_eval.erl:750: :erl_eval.do_apply/7
    (stdlib 5.1.1) erl_eval.erl:1026: :erl_eval.expr_list/7
    (stdlib 5.1.1) erl_eval.erl:456: :erl_eval.expr/6
    (stdlib 5.1.1) erl_eval.erl:494: :erl_eval.expr/6
    (stdlib 5.1.1) erl_eval.erl:136: :erl_eval.exprs/6
    (kino 0.11.3) lib/kino.ex:320: Kino.safe_apply/3

Likely Cause

The smart cell generates code using a Kino.Image.input to accept an image from the user.

image_input = Kino.Input.image("Image")
form = Kino.Control.form([image: image_input], submit: "Run")

The code expects the image input structure to include a data field containing the binary image data. For example:

form
|> Kino.Control.stream()
|> Stream.filter(& &1.data.image)
|> Kino.listen(fn %{data: %{image: image}} ...

Starting with Kino version 11.0, the image input structure instead contains a file_ref field. Applications can access the image data with file_path/1.

Environment

I am running LiveBook 0.11.4 with Elixir 1.15.7 from a downloaded Docker image on Windows 11. The notebook setup cell contains:

Mix.install(
  [
    {:kino, "~> 0.7"},
    {:evision, "~> 0.1.33"}
  ]
)

The Hex dependencies were resolved with these versions:

  castore 1.0.4
  cc_precompiler 0.1.9
  complex 0.5.0
  dll_loader_helper 0.1.11
  elixir_make 0.7.7
  evision 0.1.33
  fss 0.1.1
  kino 0.11.3
  nx 0.6.4
  table 0.1.2
  telemetry 1.2.1
cocoa-xu commented 7 months ago

Hi @jshprentz, thanks for reporting this issue. This issue should be addressed in #221 but I haven't got time to release a new version of evision. I'll do that now and hopefully it should be done in about 6 hours (sorry that precompiling this library for main-stream platforms will take this long to complete). I'll let you know when it's done.

cocoa-xu commented 7 months ago

v0.1.34 is shipped and it should work as expected.

jshprentz commented 7 months ago

Thanks, @cocoa-xu. Version 1.34 works as expected.

jshprentz commented 7 months ago

Case closed.