Overlay an image in preview video

I would like to overlay an image when I preview video.
By trying this :
vid = videoinput('winvideo');
preview(vid)
I can preview the video of my installed camera. How can I have overlay on top of the live video an image?
I want the live video to be at the background and the image at the foreground.
Thank you.

回答 (2 件)

Youssef  Khmou
Youssef Khmou 2013 年 9 月 29 日

0 投票

TRY :
figure, imshow( Your foreground), hold on, preview(vid) ;

2 件のコメント

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013 年 9 月 29 日
Thank you Youssef KHMOU, but the preview(vid) open in a new figure
Youssef  Khmou
Youssef Khmou 2013 年 9 月 29 日
i checked the descriptor h=preview(vid) and its hard to do the task, but you can perform it indirectly, after acquiring the data with getdata(vid) you have M-N-3-Samples, you can choose a an image and add it to the whole video....

サインインしてコメントする。

Image Analyst
Image Analyst 2013 年 9 月 29 日

0 投票

I don't think you can blend a live image with a stored image but maybe there's some trick to it, like by using an alpha channel or something. Call them and ask them. I know you can put up graphics over a live image, like text, circles, boxes, lines, that sort of thing. Would that work for you or must it be two blended color images? If it must be a blended image and the alpha channel doesn't pan out then you'll have to get in a loop where you call get snapshot and average it with your stored image and then display that. I'm sure the frame rate will be lower though.

4 件のコメント

Youssef  Khmou
Youssef Khmou 2013 年 9 月 29 日
maybe i saw that feature in some openCV tutorials
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013 年 9 月 30 日
Thank you Image Analyst! That would also work. My actually image is a set of boxes. Therefore a box will do the job.
Can you help me do that?
Thank you!!!
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2013 年 10 月 1 日
I have managed to insert a square when the camera is capturing. What I did is the following:
vid = videoinput('winvideo',1);
set(vid, 'framesperTrigger', 20, 'TriggerRepeat', Inf);
nBands = get(vid, 'NumberOfBands');
res=get(vid, 'Videoresolution');
start(vid);
prepstream = imshow(zeros([res nBands] ));
while islogging(vid)
stream = getdata(vid,1);
flushdata(vid);
set(prepstream, 'Cdata', stream);
drawnow;
hold on;
h_g = plot(90+[0 460 460 0 0],10+[0 0 460 460 0],'g');
end
The problem is that it consumes a lot of resources. I can hear the fan spinning like crazy. I was wondering if there is any other alternative.
If I preview(vid) I cannot insert the square inside the streaming video. However, preview does not stress the cpu.
Thank you.
Image Analyst
Image Analyst 2013 年 10 月 2 日
I just do this:
% Turn on the live video.
preview(vidobj, handleToImageInAxes);
then call plot() to plot some outline. It doesn't stress the CPU and cause the fan to go on and the CPU to get all hot.

サインインしてコメントする。

質問済み:

2013 年 9 月 29 日

コメント済み:

2013 年 10 月 2 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by