简体   繁体   English

Opencv undistortPoints断言失败

[英]Opencv undistortPoints Assertion failed

I am triyng to undistort an image with opencv undistortPoints function. 我正在尝试使用opencv undistortPoints函数使图像不失真。 I get the following assertion. 我得到以下断言。

OpenCV Error: Assertion failed (src.isContinuous() && (src.depth() == CV_32F || src.depth() == CV_64F) && ((src.rows == 1 && src.channels() == 2) || src.cols*src.channels() == 2)) in cv::undistortPoints, file D:\\OpenCV\\2.4.11\\opencv\\sources\\modules\\imgproc\\src\\undistort.cpp, line 394 OpenCV错误:断言失败(src.isContinuous()&&(src.depth()== CV_32F || src.depth()== CV_64F)&&(((src.rows == 1 && src.channels()== 2 )||| src.cols * src.channels()== 2))在cv :: undistortPoints中,文件D:\\ OpenCV \\ 2.4.11 \\ opencv \\ sources \\ modules \\ imgproc \\ src \\ undistort.cpp,第394行

I can't firgure out why I get this assertion. 我无法弄清楚为什么我得到这个主张。 Here is the code: 这是代码:

    cv::Mat pixel_locations_src = cv::Mat(src.size(), CV_32FC2);

    for (int i = 0; i < src.size().height; i++) 
    {
        for (int j = 0; j < src.size().width; j++) 
        {
            pixel_locations_src.at<cv::Point2f>(i,j) = cv::Point2f(j,i);
        }
    }

    cv::Mat pixel_locations_dst = cv::Mat(src.size(), CV_32FC2);

    std::cout<<cameraMatrix<<std::endl;
    std::cout<<distCoeffs<<std::endl;

    cv::undistortPoints(pixel_locations_src, pixel_locations_dst, cameraMatrix, distCoeffs);

This is what the input arguments look like: 输入参数如下所示:

pixel_locations_src is a 1920x1080 matrix. pixel_locations_src是1920x1080矩阵。 cameraMatrix is 3x3. cameraMatrix是3x3。 distCoeffs is 8x1. distCoeffs是8x1。

console output 控制台输出

Thanks for any help. 谢谢你的帮助。

you have to do a proper fisheye calibration, to get the appropriate distortion coeffs. 您必须进行适当的鱼眼校准,以获得适当的失真系数。

if you're using opencv's calibration sample, enable it here (they are some configs for opencv) 如果您使用的是opencv的校准样本,请在此处启用它(它们是opencv的一些配置)

then try again with the new distortion coeffs. 然后使用新的失真系数再试一次。 (thanks to Berak) (感谢Berak)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM