OpenCV的IplImage中imageData的每个元素的平方

时间:2012-09-10 09:39:51

标签: ios matlab image-processing opencv iplimage

我正在使用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矩阵)?

0 个答案:

没有答案