Displaying Multiple Images With a Loop
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Jan
il 27 Ott 2012
Does inserting a drawnow after imshow help?
2 Commenti
Matt Kindig
il 29 Ott 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.
Più risposte (1)
Image Analyst
il 28 Ott 2012
Can the camera go live? If so, why don't you just use the preview() function?
2 Commenti
Image Analyst
il 28 Ott 2012
Modificato: Image Analyst
il 28 Ott 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.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!