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

opencv_dl_ch5

opencv_dnn_ch5.livemd

opencv_dl_ch5

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

setup

alias Evision, as: Ev
base = "/Users/shou/livebook_samples/images/"

to_img = fn mat ->
  Ev.imencode(".png", mat) |> Kino.Image.new(:png)
end

ch5/5.1/load_movie

cap = Ev.VideoCapture.videoCapture(base <> "test.mp4")

Kino.animate(10, fn _i ->
  mat = Ev.VideoCapture.read(cap)

  if mat do
    to_img.(mat)
  else
    Ev.VideoCapture.release(cap)
    :halt
  end
end)

ch5/5.1/movie

cap = Ev.VideoCapture.videoCapture(base <> "movie.mp4")
total_frames = Ev.VideoCapture.get(cap, Ev.cv_CAP_PROP_FRAME_COUNT())

Kino.animate(10, fn _i ->
  mat = Ev.VideoCapture.read(cap)
  current_frame = Ev.VideoCapture.get(cap, Ev.cv_CAP_PROP_POS_FRAMES())

  cond do
    current_frame > total_frames ->
      Ev.VideoCapture.release(cap)
      :halt

    mat == false ->
      Ev.VideoCapture.release(cap)
      :halt

    true ->
      to_img.(mat)
  end
end)

ch5/5.2/writer

cap = Ev.VideoCapture.videoCapture(base <> "movie.mp4")

width = Ev.VideoCapture.get(cap, Ev.cv_CAP_PROP_FRAME_WIDTH())
height = Ev.VideoCapture.get(cap, Ev.cv_CAP_PROP_FRAME_HEIGHT())
fps = Ev.VideoCapture.get(cap, Ev.cv_CAP_PROP_FPS())

fourcc = Evision.VideoWriter.fourcc(109, 112, 52, 118)
# writer = Ev.VideoWriter.videoWriter("output_%05d.jpg", 0, fps, {width, height})
# videoWriterが動かないのでskip