OpenCV Error: Bad argument <Unknown array type> in unknown function, file ..\..\..\modules\core\src\matrix.cpp, line 697

11,210

so, you've been bitten by the c-api ? why don't you just turn your back on it ?

use the c++ api whenever possible, don't start learning opencv with the old(1.0), deprecated api, please !

double init_li[9] = 
    {   477.984984743, 0, 316.17458671, 
    0, 476.861945645, 253.45073026, 
    0, 0 ,1  };
double init_lm[5] = {-0.117798518453, 0.147554949385, -0.0549082041898, 0, 0};
double init_ri[9] = 
    {   478.640315323, 0, 299.957994781, 
    0, 477.898896505, 251.665771947, 
    0, 0, 1};
double init_rm[5] = {-0.10884732532, 0.12118405303, -0.0322073237741, 0, 0};
double init_r[9] = 
    {   0.999973709051976, 0.00129700728791757, -0.00713435189275776,
    -0.00132096594266573, 0.999993501087837, -0.00335452397041856, 
    0.00712995468519435, 0.00336386001267643, 0.99996892361313};
double init_t[3] = {-0.0830973040641153, -0.00062704210860633, 1.4287643345188e-005};

cv::Mat li(3, 3, CV_64FC1, init_li);
cv::Mat lm(5, 1, CV_64FC1, init_lm);
cv::Mat ri(3, 3, CV_64FC1, init_ri);
cv::Mat rm(5, 1, CV_64FC1, init_rm);
cv::Mat r, t, Rl, Rr, Pl, Pr; // note: no initialization needed.

//frame is a cv::MAT holding the first frame of the video.
cv::Size imageSize = frame.size();
imageSize.width /= 2;

//IT won't break HERE
cv::stereoRectify(li, ri, lm, rm, imageSize, r, t, Rl, Rr, Pl, Pr);

// no need ever to release or care about anything
Share:
11,210
Steve Schwarcz
Author by

Steve Schwarcz

Updated on June 04, 2022

Comments

  • Steve Schwarcz
    Steve Schwarcz almost 2 years

    I'm currently trying to rectify stereo cameras to create a disparity map. Unfortunately, I'm having trouble getting past the stereo rectification step because I keep receiving the error

    "OpenCV Error: Bad argument in unknown function, file ..\..\..\modules\core\src\matrix.cpp, line 697."

    The process is complicated by the fact that I'm not the one one who calibrated the cameras, nor do I have access to the cameras used to record the videos. I was given all of the calibration parameters (intrinsics, distortion coefficients, rotation matrix, and translation vector). As you can see, I've tried to turn these directly into CvMats and use them that way, but I get an error when I try to actually use them.

    Thanks in advance.

    CvMat li, lm, ri, rm, r, t, Rl, Rr, Pl, Pr;    
    
    double init_li[3][3] = 
        {   {477.984984743, 0, 316.17458671}, 
        {0, 476.861945645, 253.45073026}, 
        {0, 0 ,1}   };
    double init_lm[5] = {-0.117798518453, 0.147554949385, -0.0549082041898, 0, 0};
    double init_ri[3][3] = 
        {{478.640315323, 0, 299.957994781}, 
        {0, 477.898896505, 251.665771947}, 
        {0, 0, 1}};
    double init_rm[5] = {-0.10884732532, 0.12118405303, -0.0322073237741, 0, 0};
    double init_r[3][3] = 
        {{0.999973709051976, 0.00129700728791757, -0.00713435189275776},
        {-0.00132096594266573, 0.999993501087837, -0.00335452397041856}, 
        {0.00712995468519435, 0.00336386001267643, 0.99996892361313}};
    double init_t[3] = {-0.0830973040641153, -0.00062704210860633, 1.4287643345188e-005};
    
    cvInitMatHeader(&li, 3, 3, CV_64FC1, init_li);
    cvInitMatHeader(&lm, 5, 1, CV_64FC1, init_lm);
    cvInitMatHeader(&ri, 3, 3, CV_64FC1, init_ri);
    cvInitMatHeader(&rm, 5, 1, CV_64FC1, init_rm);
    cvInitMatHeader(&r, 3, 3, CV_64FC1, init_r);
    cvInitMatHeader(&t, 3, 1, CV_64FC1, init_t);
    cvInitMatHeader(&Rl, 3,3, CV_64FC1);
    cvInitMatHeader(&Rr, 3,3, CV_64FC1);
    cvInitMatHeader(&Pl, 3,4, CV_64FC1);
    cvInitMatHeader(&Pr, 3,4, CV_64FC1);
    
    //frame is a cv::MAT holding the first frame of the video.
    CvSize imageSize = frame.size();
    imageSize.width /= 2;
    
    //IT BREAKS HERE
    cvStereoRectify(&li, &ri, &lm, &rm, imageSize, &r, &t, &Rl, &Rr, &Pl, &Pr);