微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在MATLAB中制作动画时如何修复帧大小错误

如何解决在MATLAB中制作动画时如何修复帧大小错误

我有这个代码来创建动画:

array

它给了我以下错误

const arr = [{ a: 1,b: 2 },{ a: 3,b: "hello" },{ a: 6,c: true }];

console.log(sumBy(arr,"a")) // 10
sumBy(arr,"b") // error! Types of property 'b' are incompatible. string is not number
sumBy(arr,"c") // error! Types of property 'c' are incompatible. undefined is not number

我知道我的视频尺寸已关闭,但我不确定需要更改代码的哪一部分才能解决此问题。

解决方法

可能的尺寸不匹配

我认为一个可能的问题是合并到视频文件中的图像的分辨率/尺寸大小可能不匹配。下面是一个示例脚本,它根据内置的 MATLAB 图像创建视频文件。这里所有的图像都写成 500 x 500 的大小。如果其中一个图像不匹配,则会抛出错误。它们有两种处理问题的方法,使用 imresize() 函数调整图像大小或使用 imcrop() 函数或索引裁剪图像(这可以在 for 循环中完成)。下面脚本中的 500 维度之一是否会引发相同的错误,这可能表明此问题。

%Creating test images to combine into video file%
Folder_Path = "";
Image = imresize(imread('moon.tif'),[500 500]);
imwrite(Image,fullfile(Folder_Path,"Image_1.tif"));
Image = imresize(imread('circuit.tif'),"Image_2.tif"));
Image = imresize(imread('autumn.tif'),"Image_3.tif"));

%Starting to create video%
Pictures = dir(fullfile(Folder_Path,'*.tif'));
    
%Creating a video object to save the video structure to%
Video_Object = VideoWriter('Saved_Video.mp4','MPEG-4'); 
Video_Object.FrameRate = 1; 
Video_Object.Quality = 100;
Number_Of_Frames = length(Pictures);
open(Video_Object);


%Scanning the frames into the video structure%
for Frame_Index = 1: Number_Of_Frames
    writeVideo(Video_Object,imread(fullfile(Folder_Path,Pictures(Frame_Index).name)));
end

close(Video_Object);
implay('Saved_Video.mp4');

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。