video_writer_linux_ubuntu
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sankarganesh P
le 25 Fév 2023
Commenté : Sankarganesh P
le 28 Fév 2023
%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);
0 commentaires
Réponse acceptée
Aditya
le 27 Fév 2023
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/..
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!