I'm using the OpenCV C APIs. Now I need to implement the following Matlab code in C using OpenCV.
Matlab Code:
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;
Step 1 is very easily done. I just set the ROI of the image.
Now for Step 2, I need to square each element of the IplImage's imageData element as follows:
for(i = 0; i < subvx->width * subvx->height; i++) {
?????
}
What should I write in place of ????? to square each element of imageData? imageData is char*, so max limit of each element would be 255. Squares of each element would most likely exceed this value.
How do I implement the above Matlab code in C in this case?
Also for Step 3, how do I create a transpose of imageData (considered as 2-dim matrix)?