gpt4 book ai didi

matlab - 使用 MATLAB Function 模块进行几何变换

转载 作者:行者123 更新时间:2023-12-02 02:08:37 26 4
gpt4 key购买 nike

我尝试使用 Simulink 中的 MATLAB Function 模块对视频应用几何变换。我将“From Multimedia File”模块连接到 MATLAB Function 模块,并将其输出连接到“To Video Display”模块。在 MATLAB 函数 block 内这段代码:

function outputImage = fcn(inputImage,theta)


coder.extrinsic('affine2d')
coder.extrinsic('imwarp')
outputImage = coder.nullcopy(inputImage);


tform = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1]);

outputImage = imwarp(inputImage,tform);

其中角度 theta 是 10 的常数 block 。上面的代码是“affine2d”函数示例中的示例。它返回给我以下错误:

Size mismatch for MATLAB expression 'imwarp'. Expected = 120x160x3 Actual = 146x179x3 Block MATLAB Function (#108) While executing: State During Action 

但我不明白错误在哪里(为什么 Actual=146x179x3)。输入视频是来自 CV 工具箱演示的 RGB 视频文件 ('vipmen.avi')。

编辑:我解决了它:我使用Apply Geometric Transformation block 进行平移,使用Rotate block 进行旋转:

H = [1 0; 0 1; Ox-X  Oy-Y] %where Ox,Oy are image framework origin coordinates and X,Y are offset coordinates. 

事实上,平移后,"new"图像框架原点是 (X,Y) 点,旋转 block 将其绕 (X,Y) 旋转。

最佳答案

计算机视觉系统工具箱包含一个名为 Apply Geometric Transformation 的 block ,这将满足您的需要,并省去您使用 MATLAB 函数 block 的麻烦。

编辑:自 R2015b 版本起,Apply Geometric Transformation block 已被弃用。请使用Warp而是阻止。

关于matlab - 使用 MATLAB Function 模块进行几何变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21652086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com