我正在使用 OpenCV C API。现在我需要使用 OpenCV 在 C 中实现以下 Matlab 代码。
Matlab代码:
function [cx, cy] = foe(Vx, Vy)
ofs = 10;
% get sub image (using offsets at border) --> STEP 1
subVx = Vx(ofs:end-ofs, ofs:end-ofs);
subVy = Vy(ofs:end-ofs, ofs:end-ofs);
% compute vertical and horizontal magnitudes --> STEP 2
subVx = subVx.^2;
subVy = subVy.^2;
% find index of minimum sums for vertical and horizontal magnitudes --> STEP 3
[v, cy] = min(sum(subVx'));
[v, cx] = min(sum(subVy));
% Calculate the Focus Of Expansion --> STEP 4
cy = cy + ofs;
cx = cx + ofs;
第 1 步很容易完成。我只是设置了图像的 ROI。
现在对于第 2 步,我需要对 IplImage 的 imageData 元素的每个元素进行平方,如下所示:
for(i = 0; i < subvx->width * subvx->height; i++) {
?????
}
我应该写什么来代替??????平方imageData的每个元素?imageData 是 char*,因此每个元素的最大限制为 255。每个元素的平方很可能会超过此值。
在这种情况下,如何在 C 中实现上述 Matlab 代码?
同样对于第 3 步,如何创建 imageData 的转置(视为 2-dim 矩阵)?