Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First of all, which type is the matrix returned by remap? You can check the camImage.type() after calling remap (see the snippet below, I suggest you to write a utility function to retrieve it)

Secondly, you are accessing a camMapX, that from the documentation is the following parameter

map1 – The first map of either (x,y) points or just x values having the type CV_16SC2 , CV_32FC1 , or CV_32FC2 .

From the documentation, this matrix are at least CV_16S, but usually they are CV_32F or CV_64F. In addition .at access method want the coordinates in (x,y) format, while you gave them as y and x.

If you are using the formula from the documentation (x,y) = src(map_x(x,y), map_y(x,y)) supposing that you have an inputPoint in x and y coordinate:

 outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
 outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);

Most of the OpenCV function that perform this kind of operation (remap, undistort etc) retrieve a CV_64F or CV_32F to avoid the loss of information, so I suggest you to try with float or double.

Briefly you can try something really similar to that:

remap(camImage, camImage, camMapX, camMapY, cv::INTER_LINEAR);

uchar depth = camImage.type() & CV_MAT_DEPTH_MASK;
if(depth == CV_32F)
 {
      outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }
 else if (depth == CV_64F)
 {
      outputPoint.x = camMapX.at<double>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<double>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }

Once you have find which of the two is correct you can remove the if statement and leave the correct one.

First of all, which type is the matrix returned by remap? You can check the camImage.type() after calling remap (see the snippet below, I suggest you to write a utility function to retrieve it)

Secondly, you are accessing a camMapX, camMapX (we can say the same for camMapY), that from the documentation is the following parameter

map1 – The first map of either (x,y) points or just x values having the type CV_16SC2 , CV_32FC1 , or CV_32FC2 .

From the documentation, this matrix are at least CV_16S, CV_16S, but usually they are CV_32F CV_32F or CV_64F. CV_64F. In addition .at access method want the coordinates in (x,y) (x,y) format, while you gave them as y and x.

If you are using the formula from the documentation (x,y) = src(map_x(x,y), map_y(x,y)) supposing that you have an inputPoint in x and y coordinate:

 outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
 outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);

Most of the OpenCV function that perform this kind of operation (remap, undistort etc) retrieve a CV_64F CV_64F or CV_32F CV_32F to avoid the loss of information, so I suggest you to try with float or double.

Briefly you can try something really similar to that:

remap(camImage, camImage, camMapX, camMapY, cv::INTER_LINEAR);

uchar depth = camImage.type() & CV_MAT_DEPTH_MASK;
if(depth == CV_32F)
 {
      outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }
 else if (depth == CV_64F)
 {
      outputPoint.x = camMapX.at<double>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<double>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }

Once you have find which of the two is correct you can remove the if statement and leave the correct one.

First of all, which type is the matrix returned by remap? You can check the camImage.type() after calling remap (see the snippet below, I suggest you to write a utility function to retrieve it)

Secondly, you are accessing a camMapX (we can say the same for camMapY), that from the documentation is the following parameter

map1 – The first map of either (x,y) points or just x values having the type CV_16SC2 , CV_32FC1 , or CV_32FC2 .

From the documentation, this matrix are at least CV_16S, but usually they are CV_32F or CV_64F. In addition .at access method want the coordinates in (x,y) format, while you gave them as y and x.

If you are using the formula from the documentation (x,y) = src(map_x(x,y), map_y(x,y)) supposing that you have an inputPoint in x and y coordinate:

 outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
 outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);

Most of the OpenCV function that perform this kind of operation (remap, undistort etc) retrieve a CV_64F or CV_32F to avoid the loss of information, so I suggest you to try with float or double.

Briefly you can try something really similar to that:

remap(camImage, camImage, camMapX, camMapY, cv::INTER_LINEAR);

uchar depth = camImage.type() & CV_MAT_DEPTH_MASK;
if(depth == CV_32F)
 {
      outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }
 else if (depth == CV_64F)
 {
      outputPoint.x = camMapX.at<double>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<double>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }

Remember that this snippet take into account an arbitrary inputPoint, if you have an array or other structure you have to change it accordingly! The access mode is always x,y, don't forget that! Once you have find which of the two is correct you can remove the if statement and leave the correct one.

First of all, which type is the matrix returned by remap? You can check the camImage.type() after calling remap (see the snippet below, I suggest you to write a utility function to retrieve it)

Secondly, you are accessing a camMapX (we can say the same for camMapY), that from the documentation is the following parameter

map1 – The first map of either (x,y) points or just x values having the type CV_16SC2 , CV_32FC1 , or CV_32FC2 .

From the documentation, this matrix are is at least CV_16S, but usually they are CV_32F or CV_64F. In addition .at access method want the coordinates in (x,y) format, while you gave them as y and x.

If you are using the formula from the documentation (x,y) = src(map_x(x,y), map_y(x,y)) supposing that you have an inputPoint in x and y coordinate:

 outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
 outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);

Most of the OpenCV function that perform this kind of operation (remap, undistort etc) retrieve a CV_64F or CV_32F to avoid the loss of information, so I suggest you to try with float or double.

Briefly you can try something really similar to that:

remap(camImage, camImage, camMapX, camMapY, cv::INTER_LINEAR);

uchar depth = camImage.type() & CV_MAT_DEPTH_MASK;
if(depth == CV_32F)
 {
      outputPoint.x = camMapX.at<float>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<float>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }
 else if (depth == CV_64F)
 {
      outputPoint.x = camMapX.at<double>(inputPoint.x, inputPoint.y);
      outputPoint.y = camMapY.at<double>(inputPoint.x, inputPoint.y);
      __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "in: (%f, %f)  o: (%f, %f)",inputPoints.x, inputPoints.y, outputPoint.x, outputPoint.y);
 }

Remember that this snippet take into account an arbitrary inputPoint, if you have an array or other structure you have to change it accordingly! The access mode is always x,y, don't forget that! Once you have find which of the two is correct you can remove the if statement and leave the correct one.