Displaying Multiple Images With a Loop
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Jan
am 27 Okt. 2012
Does inserting a drawnow after imshow help?
2 Kommentare
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.
Weitere Antworten (1)
Image Analyst
am 28 Okt. 2012
Can the camera go live? If so, why don't you just use the preview() function?
2 Kommentare
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.
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!