Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to use undistort proper

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 seems not to change. Is there a fault in my code using undistort? 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, cv::Mat());

    m_pImgRender = reinterpret_cast<char*>(m_undistImg->data);
}

how to use undistort proper

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 seems not to change. Is there a fault in my code using undistort? is wronog. Looks like when der 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, cv::Mat());
dist);

    m_pImgRender = reinterpret_cast<char*>(m_undistImg->data);
}

how to use undistort proper

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 wronog. wrong. Looks like when der 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);
}