Displaying Multiple Images With a Loop

9 Ansichten (letzte 30 Tage)
Michael Plante
Michael Plante am 27 Okt. 2012
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?

Akzeptierte Antwort

Jan
Jan am 27 Okt. 2012
Does inserting a drawnow after imshow help?
  2 Kommentare
Michael Plante
Michael Plante am 29 Okt. 2012
It does make the images appear with each iteration, but it does seem to slow down the program significantly. I'd like to avoid that if at all possible.
Matt Kindig
Matt Kindig am 29 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 28 Okt. 2012
Can the camera go live? If so, why don't you just use the preview() function?
  2 Kommentare
Michael Plante
Michael Plante am 28 Okt. 2012
There was more code between getting the snapshot and displaying it concerning facial recognition and overlaying other image data depending on the results of the facial recognition, so I need individual frames instead of just a video feed. I'll edit the question and include that part.
Image Analyst
Image Analyst am 28 Okt. 2012
Bearbeitet: Image Analyst am 28 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by