how to increase getframe dimensions and quality ?
조회 수: 134 (최근 30일)
이전 댓글 표시
hi.
I have a code that plots data and moving it.
and I used getframe to save the plots for making a movie later from it.
the problem is that the output movie comes with very low quality and dimensions of 700x525.
what I have to change in my script code to get HD Quality 1280x720?
by the way this is my code, and I will attach the function raafabdshm1 and the script so you can run it on your computer.
f=figure;plotLocation=axes(f);
hold(plotLocation,'on')
counter=0;
fixedAxisOfRotation=[0,0];
linkLength=5;
startingEndingAngularPositions=[0,pi];
periodicTime=3;
exponentialDecay=0.6;
pathStatus=true;
instantaneousAngularPosition=zeros(25,1);
instantaneousAngularVelocity=zeros(25,1);
instantaneousAngularAcceleration=zeros(25,1);
M = struct('cdata',cell(25,1),'colormap',cell(25,1));
for instantaneousTime=0:0.04:0.96
counter=counter+1;
[instantaneousAngularPosition(counter),...
instantaneousAngularVelocity(counter),...
instantaneousAngularAcceleration(counter)]=...
raafabdshm1(fixedAxisOfRotation,linkLength,...
startingEndingAngularPositions,periodicTime,exponentialDecay,...
pathStatus,instantaneousTime,plotLocation);
axis(plotLocation,[-20,20,-10,10])
pbaspect(plotLocation,[2,1,1])
M(counter)=getframe(f);
cla(plotLocation)
end
myVideo=VideoWriter('animationVideo');
myVideo.FrameRate=25;
open(myVideo)
writeVideo(myVideo,M)
close(myVideo)
close(f)
댓글 수: 0
답변 (2개)
darova
2020년 4월 22일
Try this madness
clc,clear,cla
wobj = VideoWriter('test1.avi');
wobj.FrameRate = 10; % frames per second (video speed)
open(wobj); % open file
t = linspace(0,2*pi);
[x,y] = pol2cart(t,1); % simpe circle
plot(x,y)
axis equal
mkdir('test')
set(0,'defaultlinelinesmoothing')
for i = 1:1:length(x)-1
line(x(i:i+1),y(i:i+1),'linew',2) % add line
fname = ['test\test' num2str(i)]; % full name of image
print('-djpeg','-r200',fname) % save image with '-r200' resolution
I = imread([fname '.jpg']); % read saved image
frame = im2frame(I); % convert image to frame
writeVideo(wobj,frame); % save frame into video
end
close(wobj); % close file
댓글 수: 8
Adnan
2023년 6월 1일
편집: Adnan
2023년 6월 1일
Changing the for loop to the following also works:
for i = 1:1:length(x)-1
line(x(i:i+1),y(i:i+1),'linew',2) % add line
cdata = print('-RGBImage','-r600','-noui'); % increased dpi to 600 (beware)
frame = im2frame(cdata); % convert image to frame
writeVideo(wobj,frame); % save frame into video
end
Image Analyst
2020년 4월 22일
편집: darova
2020년 4월 22일
Since getframe() essentially gets a screenshot bitmap of what's in your display adapter, the resolution is whatever it is when it's displayed on your scree. To get that as high as possible, you need to maximize your figure window and use 'tight' option if you use imshow:
hFig = figure; % Bring up new figure
imshow('board.tif','Border','tight') % The axes will fill up the entire figure as much as possible without changing aspect ratio.
hFig.WindowState = 'maximized'; % Maximize the figure to your whole screen.
thisFrame = getframe(); % This is as large as you can get.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!