how to increase getframe dimensions and quality ?

108 次查看(过去 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)

回答(2 个)

darova
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
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
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.
  2 个评论
Osama Alkurdi
Osama Alkurdi 2020-4-22
I don't know how this will resolve my problem and how I would implement it in my code, are you shure you read my question well? can you explain more clearly please?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by