Problem with getframe with trisurf when making movie

I want to make a movie use getframe and VideoWriter to view a 3D dataset at different view angle. First, i use scatter3 to plot 3D dataset, and use getframe and VideoWriter. It works perfect. However, when i use trisurf to plot the surface of dataset,and use exactly the same code to as above. But i found the the frame in this movie does not change over time, and it is a 2D image instead of 3D.
Are there some meet the same problem? Many thanks.
writerObj = VideoWriter('ColorGamutDTri.avi');
writerObj.FrameRate = 80;
open(writerObj);
n=-180;
while(n<180)
view(n,10);
n=n+1;
pause(0.1);
frame = getframe(gcf);
writeVideo(writerObj, frame);
end
close(writerObj);

8 comentarios

Geoff Hayes
Geoff Hayes el 16 de Sept. de 2014
Renbo - I used the example from trisurf to create a surface plot, and then ran your code. When I viewed the movie, the frames did rotate and so appeared as expected. When you viewed your video, are you sure that there is more than one frame in it?
Renbo
Renbo el 19 de Sept. de 2014
Hi Geoff, thanks for your response.
I indeed got the same result as you got. No rotation in movie at all. So i don't know what happened? It seems that only one frame in the movie.
Renbo - please clarify I indeed got the same result as you got. No rotation in movie at all because I did see the rotation when I ran the example from the trisurf link with your above code.
[x,y] = meshgrid(1:15,1:15);
tri = delaunay(x,y);
z = peaks(15);
trisurf(tri,x,y,z);
writerObj = VideoWriter('ColorGamutDTri.avi');
writerObj.FrameRate = 80;
open(writerObj);
n=-180;
while(n<180)
view(n,10);
n=n+1;
pause(0.1);
frame = getframe(gcf);
writeVideo(writerObj, frame);
end
close(writerObj);
On the video that you have created, type the following in the Command Window
obj = VideoReader('ColorGamutDTri.avi');
get(obj)
which will return information like
General Settings:
Duration = 4.5
Name = ColorGamutDTri.avi
Path = /Users/geoff/Development/bitbucket_repos/matlab/testing
Tag =
Type = VideoReader
UserData = []
Video Settings:
BitsPerPixel = 24
FrameRate = 80
Height = 420
NumberOfFrames = 360
VideoFormat = RGB24
Width = 560
What do you see for the NumberOfFrames for your video? (The above output was taken from the above code pasted in this comment.)
Renbo
Renbo el 21 de Sept. de 2014
Editada: Renbo el 21 de Sept. de 2014
Hi Geoff, Sorry for the confusion and thanks for the detailed answers.
1. I run your code, and i get the 'perfect' video. The figure in the video is rotating.
2. However, when i was running my own data as attached LabCCDT.mat, though i can get a video and the length looks norm, but the figure did not rotate as it did in Matlab.
3. Could you run two trisurf plots in the same figure, it seems that the figure in the video does not rotate.
I attached the code you provided and my own data, thanks for you help.
figure;
% load ('LabCCDT.mat');
% XYZ = LabCCDT;
XYZ = randn(100,3);
tri = delaunay(XYZ);
H1 = trisurf(tri,XYZ(:,1),XYZ(:,2),XYZ(:,3),'facecolor', 'b', 'edgecolor','b');
hold on;
XYZ2 = randn(200,3);
tri2 = delaunay(XYZ2);
z2 = peaks(20);
H2= trisurf(tri2,XYZ2(:,1),XYZ2(:,2),XYZ2(:,3),'facecolor', 'r', 'edgecolor','r');
hold off;
writerObj = VideoWriter('ColorGamutDTri.avi');
writerObj.FrameRate = 80;
open(writerObj);
n=-180;
while(n<180)
view(n,10);
n=n+5;
pause(0.1);
frame = getframe(gcf);
writeVideo(writerObj, frame);
end
close(writerObj);
Hi Renbo - I ran the GamtTest.m script (as is) and it worked fine - the video was rotating. I then uncommented your code so that it would read from file, and again the video showed the big blue and small red "structures" rotate around each other, just at a faster rate than the MATLAB plot. You've added a pause of 0.1 seconds after every view change (frame), so I changed the frame rate of the video to 6, replacing
writerObj.FrameRate = 80;
with
writerObj.FrameRate = 6;
I don't know why you are not seeing the rotation. Try changing the frame rate (as above) and see what happens again.
Renbo
Renbo el 22 de Sept. de 2014
Editada: Renbo el 22 de Sept. de 2014
Hi Geoff, I run my code in another computer, it indeed works and the figure in the video rotates. Though i changed the framerate, it still does not work on my own computer(as attached video). But i found another useful link, VideoWriter
I add set(gcf,'renderer','zbuffer'), it works finally.
I think it is the frame rate problem you mentioned. Many thanks and really appreciate your help.
Geoff Hayes
Geoff Hayes el 22 de Sept. de 2014
Glad that you got it tow work, Renbo!
Renbo
Renbo el 22 de Sept. de 2014
I can't make it without your help. Thanks. Cheers.

Iniciar sesión para comentar.

Respuestas (0)

Preguntada:

el 16 de Sept. de 2014

Comentada:

el 22 de Sept. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by