Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Vision

priv/vision.livemd

Vision

Mix.install([{:evision, "~> 0.1"}])

Section

model =
  Evision.Zoo.FaceDetection.YuNet.init(:default_model,
    top_k: 5000,
    nms_threshold: 0.3,
    conf_threshold: 0.9,
    backend: Evision.cv_DNN_BACKEND_OPENCV(),
    target: Evision.cv_DNN_TARGET_CPU()
  )

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

form
|> Kino.Control.stream()
|> Stream.filter(& &1.data.image)
|> Kino.listen(fn %{data: %{image: image}} ->
  Kino.Frame.render(frame, Kino.Markdown.new("Running..."))
  image = Evision.Mat.from_binary(image.data, {:u, 8}, image.height, image.width, 3)
  results = Evision.Zoo.FaceDetection.YuNet.infer(model, image)
  image = Evision.cvtColor(image, Evision.cv_COLOR_RGB2BGR())

  Evision.Zoo.FaceDetection.YuNet.visualize(image, results)
  |> then(&Kino.Frame.render(frame, Kino.Image.new(Evision.imencode(".png", &1), :png)))
end)

Kino.Layout.grid([form, frame], boxed: true, gap: 16)