how do you output a live annotated video from the webcam?

4 views (last 30 days)
hi
i have made a working facial recognition program and i am trying to make it so it can operate in real-time time. however i dont know how... im am using the image acquisition toolbox to get data from the webcam.
the problem is that every time i call the function to get a new image
image = getsnapshot(vid);
Matlab restarts the camera every time making it slow. i tried the function
start(vid);
at the start of my program but when i run the program, i don't get any output... on the command windows i can see its processing fine (and a lot quicker!)... but there is no output :S
can someone please help me!
thanks in advance :)
  2 Comments
Walter Roberson
Walter Roberson on 10 Sep 2012
Are there particular indications that getsnapshot() is restarting the camera? getsnapshot() is not fast; is it possible that it is simply taking longer than you expect but not restarting the camera?
r maher
r maher on 11 Sep 2012
Edited: r maher on 11 Sep 2012
i can tell its restarting because im using a mac. when the camera is in use, a light is turned on next to the camera indicating it is initialized (this is the same for most laptops).
the light keeps turning off/on periodically and judging by the output on the command window, it happens when the getsnapshot() is called. i dont get the light turning off/on when i call the preview(vid) command, but i cant add annotation on top of the output.
you say "getsnapshot() is not fast"... is there another command that can get frames from the camera instantly? (or at least more instantly than getsnapshot() )?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 10 Sep 2012
Try preview instead of start:
% Get the handle to the image in the axes.
hImage = findobj(handles.axesImage, 'Type', 'image');
% Turn on the live video.
preview(videoObject, hImage);
  4 Comments
r maher
r maher on 14 Sep 2012
hi sorry to annoy you but i hope you can help. i am still stuck with the same problem. how can i use plot() and text() with the preview window? when i try i get a grid with no plotting and a preview windows that remains blank.
suppose i need to draw a line from x1y1 to x2y2... how can i draw that on the preview window?
shivam verma
shivam verma on 26 Jun 2019
you should use the function text(x,y,'your string')
before the preview function so that it can show the data on the preview-
example-
// sending a program to snap of 10 frames with data;
handles.output = hObject;
axes(handles.axes1);
vid=videoinput('winvideo');
hImage=image(zeros(120,160,3),'parent',handles.axes1);
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb');
for i=1:1:10
data = getsnapshot(vid);
figure(i)
imshow(data);
imwrite(data,'E:\New Folder\myg.jpeg');
text(20*pi,10,'my data')
preview(vid,hImage);
end %%hope this will help you getting your string data

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!