Displaying Multiple Images With a Loop

9 ビュー (過去 30 日間)
Michael Plante
Michael Plante 2012 年 10 月 27 日
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?

採用された回答

Jan
Jan 2012 年 10 月 27 日
Does inserting a drawnow after imshow help?
  2 件のコメント
Michael Plante
Michael Plante 2012 年 10 月 29 日
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 2012 年 10 月 29 日
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.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2012 年 10 月 28 日
Can the camera go live? If so, why don't you just use the preview() function?
  2 件のコメント
Michael Plante
Michael Plante 2012 年 10 月 28 日
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 2012 年 10 月 28 日
編集済み: Image Analyst 2012 年 10 月 28 日
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.

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

Community Treasure Hunt

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

Start Hunting!

Translated by