getframe not updating when outputting video/images

Hello, thanks for reading this,
I have a image that I'm outputting to a gif/avi video, and neither one seems to work.
When I use the code:
lseg = getframe(h);
set(gcf,'InvertHardCopy','off')
imwrite(lseg.cdata, outputFileName, 'WriteMode', 'append');
camorbit(1, 0, 'data', [0 0 1])
drawnow
and see my image stack, they're all the same image: the lseg frame never gets updated when I rotate with camorbit. Additionally, when I try to make a video with:
fps = 60; sec = 10;
vidObj = VideoWriter('newfile.avi');
vidObj.Quality = 100;
vidObj.FrameRate = fps;
open(vidObj);
for i=1:fps*sec
camorbit(0.9,-0.1);
writeVideo(vidObj,getframe(gcf));
end
close(vidObj);
I get a 10 second video of a static frame: again, getframe never gets updated to the frame rotated by camorbit.
When I view the image as its writing, I can see the figure rotating. Its just when MATLAB writes to file, the written file frames are not updated.
Any ideas?

댓글 수: 1

Actually, I got the video export to work by including the line
drawnow
after camorbit.

댓글을 달려면 로그인하십시오.

 채택된 답변

Brian
Brian 2014년 7월 21일

0 개 추천

Use drawnow after camorbit and it works.

추가 답변 (1개)

Chad Greene
Chad Greene 2014년 7월 21일
I've had troubles with getframe in the past. I've had better luck using export_fig . The syntax would be
frame = export_fig(gcf);
writeVideo(vidObj,frame);

댓글 수: 3

Brian
Brian 2014년 7월 21일
Thanks, I tried out this function but I got a different error: this one pertaining to frame dimensions.
I think my frame size must change during the animation, because a few frames in I get the error: Frame must be 435 by 344.
Is it possible to force my current axes handle to a set resolution?
Brian
Brian 2014년 7월 21일
Just a update, I manually switched the axis to a value, and while it ran a bit longer, I wasn't able to get a full 360 degree turn, it stopped midway.
Why would the resolution of the movie suddenly change?
I think you'd need the -nocrop option in export_fit. That's because by default export_fig crops the frame to the dimensions of where plotted objects appear on the figure. If some data being plotted in your figure starts to go near the edge of the frame, export_fig will increase need to increase the size of the frame. Using the -nocrop option prevents the automatic frame sizing.

댓글을 달려면 로그인하십시오.

질문:

2014년 7월 21일

댓글:

2014년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by