-
I have a function which will take an Evision image, and return an Evision image. I want to pass it a camera frame and then take the frame and display that frame. How do I go about doing this? I tried with livebook and kino render stuff, that did work but was very slow. I want to use Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi @tusqasi, sorry I only have an Erlang demo for that at the moment, evision_erlang_dnn_demo.erl. I plan to rewrite it in Elixir next week or so. I think the following code fragments might help you write an Elixir one, and they are basically converting https://github.com/cocoa-xu/evision/blob/main/examples/evision_erlang_dnn_demo.erl#L235-L244 {ok, NewFrame} = evision:resize(ResultFrame, [W, H]),
{ok, RGBFrame} = evision:cvtColor(NewFrame, evision:cv_COLOR_BGR2RGB()),
{ok, Binary} = evision_mat:to_binary(RGBFrame),
Img = wxImage:new(W, H, Binary),
Bmp = wxBitmap:new(Img),
Fun = fun(DC) ->
wxDC:clear(DC),
wxDC:drawBitmap(DC, Bmp, {0, 0})
end,
draw(State#state.canvas, State#state.bitmap, Fun), https://github.com/cocoa-xu/evision/blob/main/examples/evision_erlang_dnn_demo.erl#L284-L293 draw(Canvas, Bitmap, Fun) ->
MemoryDC = wxMemoryDC:new(Bitmap),
Fun(MemoryDC),
CDC = wxWindowDC:new(Canvas),
wxDC:blit(CDC, {0,0},
{wxBitmap:getWidth(Bitmap), wxBitmap:getHeight(Bitmap)},
MemoryDC, {0,0}),
wxWindowDC:destroy(CDC),
wxMemoryDC:destroy(MemoryDC). |
Beta Was this translation helpful? Give feedback.
-
Elixir rewrite is going to be a huge help!
To clarify, I meant the PS. Do you get very low frame rates when using camera capture from livebook? Is that expected? |
Beta Was this translation helpful? Give feedback.
-
tl;drYes, because rendering in livebook with kino is basically encoding each frame as a jpeg/png (depends on your settings) image and pass it to the browser, where it gets decoded and displayed. Therefore, it is expected to be slow at the moment. As for def show_video(cap) do
case Evision.VideoCapture.read(cap) do
%Evision.Mat{}=frame ->
# as along as you're using the same window title,
# the frame will be plotted in the same window
Evision.Wx.imshow("window title", frame)
show_video(cap)
_ ->
# video has ended or an error occurred
:no_more_frames
end
end More informationAnd to achieve a smooth experience in livebook, it would effectively require at least a stream encoder (which encodes the video stream to HLS or other live format) on the Elixir side and serving it on another port. I'm not planing to implement this any time soon (either in Evision or as another standalone library). However, if you're okay with gstreamer, then one possible way is to build it from source (OpenCV will detect and compile gstreamer related code if gstreamer library and headers are available on your machine). Then you can set up a gstreamer pipeline, and receive the video stream in another browser tab or other video player that supports it. For example,
|
Beta Was this translation helpful? Give feedback.
-
Wowww!!!! I don't know what was I thinking when spawning processes just to render images 😅 |
Beta Was this translation helpful? Give feedback.
tl;dr
Yes, because rendering in livebook with kino is basically encoding each frame as a jpeg/png (depends on your settings) image and pass it to the browser, where it gets decoded and displayed. Therefore, it is expected to be slow at the moment.
As for
Evision.Wx.imshow
, perhaps you can do something likeMore information
And to achieve …