3

I am currently trying to make a video using the writeVideo function in MATLAB. I have made a GUI using GUIDE which includes a slider, a few checkboxs, and a single axes (tagged as axes1). When I move the slider, the axes will plot certain shapes that change according to the slider value.

What I am trying to do is record a video of the GUI being used to show the functionality in a presentation. However, when I play back the video (after making it using writeVideo), it shows the slider value moving and the checkboxes being checked correctly, but the plot never changes (i.e. it will only show the original shape). This seems to be some refresh error, however, anything I have tried has not worked (refresh, drawnow, etc.)

Any idea why this is happening? The following is the code I am trying to implement:

vidObj = VideoWriter('test.avi','Motion JPEG AVI');
open(vidObj);
flag = 0;
if flag<12 %movie will be 12 frames long
    flag = flag+1;
    if slider<1  
        plot something...
    elseif slider>=1 && slider<2
        plot something else...
    etc...
    elseif slider<=5
        plot something else...
    end

    hFigure = findobj('Name','gui');
    currFrame = getframe(hFigure);
    writeVideo(vidObj,currFrame);

    clear hfigure currFrame image;
else
    fprintf('done\n')
    close(vidObj);   
end

As stated, I can then use implay to play back the test.avi file, however, the plot never updates.

Thanks in advance

Note: I am using MATLAB R2012b

EDIT:

The following is how I ended up creating my video: maybe this will help someone who was facing similar issues to the one stated above.

I basically gave up on using getframe and decided to 1) get screenshots, then 2) turn the screenshots into a movie. To get the screenshots, I first ran my program then, in the command window, invoked the following code using the java toolkit

i = 1;
while true
    robo = java.awt.Robot;
    t = java.awt.Toolkit.getDefaultToolkit();

    %# Set screen size
    rectangle = java.awt.Rectangle(0,0,1000,640);

    %# Get the capture
    image = robo.createScreenCapture(rectangle);

    %# Save it to file
    filehandle = java.io.File(sprintf('capture%d.jpg', i));
    javax.imageio.ImageIO.write(image,'jpg',filehandle);

    pause(.4) %# Wait for 0.4 seconds
    i = i + 1;
end

This then continually ran in the background and took snap shots of the screen and stored them into the current directory. to stop it from running, just use Ctrl C. Once I had the screen shots, I used the following code to create the movie:

vidObj = VideoWriter('test.avi','Motion JPEG AVI');
open(vidObj);
for i=7:87 %these are the frames I wanted in my movie
    x = num2str(i);
    im = horzcat('capture',x);
    im1 = horzcat(im,'.jpg')
    imdata = imread(im1);
    writeVideo(vidObj,imdata);
end
close(vidObj); 
4

2 回答 2

1

getframe 有时会出现问题。我不确定我能给出答案,而且由于我的声誉,我不能简单地发表评论,但这个链接 可能会有所帮助。从 GUI 中获取图形后,将其转换为图像,然后再转换为框架。值得一试。

于 2013-04-11T15:28:43.907 回答
0

如果您将显示器设置更改为 16 位颜色,它将解决您遇到的问题。这已记录在提供的链接上。我之前的答案已被删除,因为我只提供了链接并告诉您如何解决问题(对不起),但是如果您实际单击链接并查看他们所说的内容或将显示器设置更改为 16 位颜色,一切都会正常工作。从链接中您可以看到人们自 2009 年以来就遇到了这个问题,但它在 2013 年 4 月进行了更新,所以它仍然是一个问题,将显示器设置更改为 16 位颜色仍然是一个解决方案。

希望这可以帮助!

http://www.mathworks.com/matlabcentral/newsreader/view_thread/257389

于 2013-09-11T22:12:00.847 回答