video_writ​er_linux_u​buntu

조회 수: 11 (최근 30일)
Sankarganesh P
Sankarganesh P 2023년 2월 25일
댓글: Sankarganesh P 2023년 2월 28일
%Hello friends,
%i am very new to matlab. i am using linux ubuntu 22.10. i have to create video for the matrix A(x,y,t). but i facing the the following issues.
%1.The specified folder, resiliente@resiliente-S2600STB:, does not exist
%2.if i used the path like E:\newfile.avi , am getting error like -IMG must be of one of the following classes: double, single, uint8
%kindly help me to resolve this issuse. thanks in advance
x1 = randi([0, 5], [4,4])
x2 = randi([0, 5], [4,4])
x3 = randi([0, 5], [4,4])
A(:,:,1)=x1;
A(:,:,2)=x2;
A(:,:,3)=x3;
figure
Q = size(A,3);
W = A(:,:,1);
h = pcolor(W);
drawnow();
pause(0.3);
for K = 2 : Q
W = A(:,:,K);
set(h, 'CData', W);
drawnow();
end
video = VideoWriter('resiliente@resiliente-S2600STB:/home:\newfile.avi');
video.FrameRate = 10;
open(video)
writeVideo(video, h);
close(video);

채택된 답변

Aditya
Aditya 2023년 2월 27일
Hi,
I understand that you are trying to create a video from images that are coming in the loop. There are multiple issues related to usage to video writer and so on.
Majorly, whenever a call is made to writeVideo, it is expecting an image frame. However, you are passing h, which is a handle to a pcolor object. Hence, you are getting the error: IMG must be of one of the following classes: double, single, uint8.
The way you can solve it is, draw pcolor on an axes and then get the image from that axes for each frame. Once, you get that image, write it to the video.
Here is a full working example,
x1 = randi([0, 5], [4,4]);
x2 = randi([0, 5], [4,4]);
x3 = randi([0, 5], [4,4]);
A(:,:,1)=x1;
A(:,:,2)=x2;
A(:,:,3)=x3;
f = figure;
ax = axes(f);
Q = size(A,3);
W = A(:,:,1);
h = pcolor(ax,W);
drawnow();
pause(0.3);
video = VideoWriter('newfile.avi');
video.FrameRate = 10;
open(video);
for K = 2 : Q
W = A(:,:,K);
set(h, 'CData', W);
drawnow();
img = getframe(f);
writeVideo(video, img);
end
close(video);
Regarding the error resiliente@resiliente-S2600STB:, does not exist.
On a linux machine, the prompt is something like this: "username@machine: path"
You only need to pick up the path from it. The path would be something like /home/..
  댓글 수: 1
Sankarganesh P
Sankarganesh P 2023년 2월 28일
This solution works for me as well, thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by