ksivakumar
ksivakumar

Reputation: 481

Assertion Failed when using fisheye undistortPoints

I am trying to undistort a fisheye image taken from a camera. I have already gotten the camera parameters needed. However, when I run the code below:

Mat cammatrix = cv::Mat::zeros(3,3, CV_64F);
cammatrix.at<double>(0,0) = 3.7089418826568277e+002;
cammatrix.at<double>(1,1) = 3.7179355652545451e+002;
cammatrix.at<double>(0,2) = 3.4450520804288089e+002;
cammatrix.at<double>(1,2) = 2.5859133287932718e+002;
cammatrix.at<double>(2,2) = 1.0;
std::vector<double> distortcoeff;
double tempdoub = -2.2022994789941803e+000;
distortcoeff.push_back(tempdoub);
tempdoub = 4.4652133910671958e+000;
distortcoeff.push_back(tempdoub);
tempdoub = 6.8050071879644780e-001;
distortcoeff.push_back(tempdoub);
tempdoub = -1.7697153575434696e+000;
distortcoeff.push_back(tempdoub);

// Process images here (optional)
    Mat img_scene (current);

    if(!img_scene.data )
    { std::cout<< " --(!) Error reading images " << std::endl; return -1; }
    img_scene.convertTo(img_scene, CV_32FC2);
    cv::fisheye::undistortPoints(img_scene, img_scene, cammatrix, distortcoeff);

I get this error:

OpenCV Error: Assertion failed (distorted.type() == CV_32FC2 || distorted.type() == CV_64FC2) in undistortPoints

Not sure why this is happening because I have the .convertTo line right before converting it to CV_32FC2. If anyone could help me fix this error, I would really appreciate it!

Upvotes: 0

Views: 1191

Answers (1)

Shmuel Fine
Shmuel Fine

Reputation: 351

undistortPoints() function is retrieving undistorted pixel location, given it's current distorted location on the image. i.e it operates on points, not on images. use fisheye::undistortImage for images.

Upvotes: 1

Related Questions