Displaying Multiple Images With a Loop
9 views (last 30 days)
Show older comments
I'm trying to display an image from a camera feed each time through the loop, but right now it only displays a blank figure each time through and then only displays the image once the loop terminates.
while 1
frame = getsnapshot(vid);
newFaceList = faceRecog(frame, kernel, prevFaceList);
for i = 1:size(newFaceList)
face = newFaceList(i);
rowshift = uint32( face.pos(1) - (face.face_size(1)) );
colshift = uint32( face.pos(2) - (face.face_size(2)) );
if face.type == 2
zombieResize = imresize(zombieFace, [face.face_size(1) face.face_size(2)]);
zsize = size( zombieResize );
frame( uint32(1:zsize(1) )+rowshift, uint32(1:zsize(2) )+colshift, :) = zombieResize;
elseif face.type == 1
humanResize = imresize(humanFace, [face.face_size(1) face.face_size(2)]);
frame((1:size(zombieResize,1))+rowshift, (1:size(zombieResize,2))+colshift, :) = humanResize;
end
end
imshow(frame)
prevFaceList = newFaceList;
end
How can I get the program to display the most recent image for each iteration?
0 Comments
Accepted Answer
Jan
on 27 Oct 2012
Does inserting a drawnow after imshow help?
2 Comments
Matt Kindig
on 29 Oct 2012
One way that might speed up the program is to only modify the 'CData' (the actual image content) each time, rather than calling imshow (which actually creates a new image object). Outside your while loop, call imshow with the first frame data, and save the handle. Then instead of the imshow() call, just set the 'CData' property for that handle. Something like this:
himg = imshow( first_frame);
while 1,
frame = getsnapshot(vid);
%all your other code here
set(himg, 'CData', himg); %instead of imshow
drawnow;
prevFaceList = newFaceList;
end
Again, I'm not sure what kind of speed benefits you get, but might be worth a shot.
More Answers (1)
Image Analyst
on 28 Oct 2012
Can the camera go live? If so, why don't you just use the preview() function?
2 Comments
Image Analyst
on 28 Oct 2012
Edited: Image Analyst
on 28 Oct 2012
What's the class of humanface and humanresize? Is it single or double? If so, try
cla; % Prevent stuffing too many images into the axes.
imshow(frame, []);
drawnow;
pause(0.5); % Pause for 1/2 second before next frame blows it away.
to scale it properly for display.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!