OpenCV remap tables to vx_remap

Hi,

Looking for help creating OpenVX remap tables (vx_remap) from the output of cv::initUndistortRectifyMap. I am currently doing this as follows:

cv::Size size(cameras->frameWidth, cameras->frameHeight);
cv::initUndistortRectifyMap(cameras->getCameraMatrix(),
			    cameras->getDistCoeffs(),
			    R, P,
			    size,
			    CV_32FC1,
			    remapX, remapY);
cv::initUndistortRectifyMap(cameras->getCameraMatrix(),
			    cameras->getDistCoeffs(),
			    R, P,
			    size,
			    CV_32FC1,
			    remapX, remapY);

int sfw = size.width, sfh = size.height;
int dfw = size.width, dfh = size.height;
remapTable  = vxCreateRemap(context, sfw, sfh, dfw, dfh);
remapTable = vxCreateRemap(context, sfw, sfh, dfw, dfh);

vx_status status;
for(int y = 0; y < dfh; y++) {
  for(int x = 0; x < dfw; x++) {
    status = vxSetRemapPoint(remapTable,
			     x, y,
			     (vx_float32)remapX.at<float>(y, x),
			     (vx_float32)remapY.at<float>(y, x));
    status = vxSetRemapPoint(remapTable,
			     x, y,
			     (vx_float32)remapX.at<float>(y, x),
			     (vx_float32)remapY.at<float>(y, x));
  }
}

When I subsequently try to rectify images using cv::remap(), all is fine. However, when I try to rectify using vxuRemap() with the remapTable I built above, the images are not correct (i.e, there are striped lines, mirroring, distortion, etc.). So Iā€™m obviously not converting the remap tables correctly. Any help here would be appreciated.

Thanks!

Did you try inverting x & y like this ? :

status = vxSetRemapPoint(remapTable,
			     x, y,
			     (vx_float32)remapX.at<float>(x, y),
			     (vx_float32)remapY.at<float>(x, y));

In the OpenCV documentation I see:

C++: template<typename T> T& Mat::at(int i, int j)
Parameters:
    i ā€“ Index along the dimension 0
    j ā€“ Index along the dimension 1

@tlepley. Thanks, it turns out it was something completely unrelated. The remap is working fine.

1 Like