how to use undistort proper

asked 2015-05-07 08:56:17 -0600

Pellaeon gravatar image

updated 2015-05-07 09:13:08 -0600

I want toshow an undistorted camera image in my application and found the opencv function "undistort". I created a matrix and filled it with the intrinsic parameters. But when I start my application the image is wrong. Looks like when there is a shift with the color channels. And what is the proper matrix size for the distortion coefficients? E.g. a (4,1) matrix or a (1,4) matrix?

auto cvFormat = getOpenCVFormat(format);
if (cvFormat != -1)
{
    //create source matrix
    cv::Mat srcImg(res.first, res.second, cvFormat, const_cast<char*>(pImg));

    cv::Mat cam(3, 3, cv::DataType<float>::type);
    cam.at<float>(0, 0) = 1.9191881071077680e+003f;
    cam.at<float>(0, 1) = 0.0f;
    cam.at<float>(0, 2) = 9.9180029393125994e+002f;

    cam.at<float>(1, 0) = 0.0f;
    cam.at<float>(1, 1) = 1.9199004896008303e+003f;
    cam.at<float>(1, 2) = 4.8762694385566999e+002f;

    cam.at<float>(2, 0) = 0.0f;
    cam.at<float>(2, 1) = 0.0f;
    cam.at<float>(2, 2) = 1.0f;

    cv::Mat dist(5, 1, cv::DataType<float>::type);  
    dist.at<float>(0, 0) = -6.0966622082132604e-001f;
    dist.at<float>(1, 0) = 1.1527185014286182e+001f;
    dist.at<float>(2, 0) = -5.2601963039546193e-003f;
    dist.at<float>(3, 0) = 1.8731645453405020e-003f;
    dist.at<float>(4, 0) = -8.6013254063968844e+001;

    cv::undistort(srcImg, *m_undistImg, cam, dist);

    m_pImgRender = reinterpret_cast<char*>(m_undistImg->data);
}
edit retag flag offensive close merge delete

Comments

push to top

Pellaeon gravatar imagePellaeon ( 2015-05-11 08:12:30 -0600 )edit