how to increase getframe dimensions and quality ?

104 ビュー (過去 30 日間)
Osama Alkurdi
Osama Alkurdi 2020 年 4 月 22 日
編集済み: Adnan 2023 年 6 月 1 日
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 件のコメント
Osama Alkurdi
Osama Alkurdi 2020 年 4 月 22 日
@darova
thank you :)
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?
darova
darova 2020 年 4 月 22 日
Osama Al-Kurdi carefully

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by