OpenCv Troubleshooting (-4:Insufficient memory) 分配失败

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

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'

可能是什么原因导致这种情况?

我已经通过检查 opencv 库解决了问题。

因为我在 ubuntu 上安装了两个不同的库; OpenCV 版本的预编译版本是 3.x 但我的代码是在不同版本的 opencv 上测试的,它是 OpenCV 4.5.2

我将版本从 3.x 更改为 4.5.2 后问题就消失了。

毕竟只使用一个版本的库可以避免错误。