Home > Net >  OpenCv Troubleshooting (-4:Insufficient memory) Failed to allocate
OpenCv Troubleshooting (-4:Insufficient memory) Failed to allocate

Time:12-24

QCoreApplication a(argc, argv);

cv::Mat src=imread("/home/cdukunlu/Downloads/EuFFJ.jpg");

float data[9]= {161.837869,0.059269,319.778713,0.000000,165.648492,230.424626,0.000000,0.000000,1.000000};
float rectification[9]={1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000};
cv::Vec<float,4> k(0.148201,-0.031856,0.012784,-0.003392);

cv::Mat F = cv::Mat(3, 3, CV_32FC1, data);
cv::Mat R = cv::Mat(3, 3, CV_32FC1, rectification);

std::cout<<"Calibrationg..."<<std::endl;


    cv::Size size = {src.cols, src.rows};

    cv::Mat K(3, 3, cv::DataType<double>::type);
    K.at<double>(0, 0) = 1307.2807020496643;
    K.at<double>(0, 1) = 0.0;
    K.at<double>(0, 2) = 530.3754311563506;

    K.at<double>(1, 0) = 0.0;
    K.at<double>(1, 1) = 1318.342691460933;
    K.at<double>(1, 2) = 354.98352268131123;

    K.at<double>(2, 0) = 0.0;
    K.at<double>(2, 1) = 0.0;
    K.at<double>(2, 2) = 1.0;

    cv::Mat D(4, 1, cv::DataType<double>::type);
    D.at<double>(0, 0) = -0.2994762856767568;
    D.at<double>(1, 0) = 0.5036082961388784;
    D.at<double>(2, 0) = -4.231072729639434;
    D.at<double>(3, 0) = 3.8646397788794578;
    cv::Mat E = cv::Mat::eye(3, 3, cv::DataType<double>::type);

    cv::Mat map1;
    cv::Mat map2;

    std::cout << K << std::endl;
    std::cout << D << std::endl;
    std::cout << E << std::endl;
    std::cout << size << std::endl;

    cv::initUndistortRectifyMap(K, D, E, K, size, CV_16SC2, map1, map2);
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.5-pre) /home/cdukunlu/opencv_build/opencv/modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 61343654331232 bytes in function 'OutOfMemoryError'

What could be causing such situation?

CodePudding user response:

I had solved the problem with checking the opencv libraries.

Since ı had two different libraries installed to my ubuntu; the precompiled version of OpenCV version is 3.x but my code is tested on different version of opencv which it is OpenCV 4.5.2

As soon as ı had changed the version from 3.x to 4.5.2 the problem has gone.

After all it would be good to use only one version of libraries to avoid bugs.

  • Related