Error with cvFindFundamentalMat

Hello! I just started a project on which I use cvFindStereoCorrespondence to create a disparity map.

My procedure goes like this, I grab the video and create IplImage src1 and src2 from two grayscale images!
To be more precise I use the type is ofxCvGrayscaleImage which I convert easily to IplImage (as CvImage and IplImage just need a typecast)

I then make matrices from these IplImages with:

  
mat1 = cvCreateMat( src->height, src->width, CV_32FC1 );  
cvConvert( src, mat1 );  
mat2 = cvCreateMat( src->height, src->width, CV_32FC1 );  
cvConvert( src2, mat2 );  

I then create space for the fundamental matrix :

  
fundamental_matrix = cvCreateMat(3, 3, CV_32FC1);  

and pass all the matrices in cvFindFundamentalMat :

  
cvFindFundamentalMat(mat1, mat2, fundamental_matrix,CV_FM_RANSAC, 3, 0.99); //not sure about 3  

when I run this I get :

OpenCV ERROR: One of arguments’ values is out of range (Both input and output point dimensionality must be 2,3 or 4) in function cvConvertPointsHomogeneous, cvfundam.cpp(1270)

I think that what it obviously says is that the way I created my matrices is wrong

Any ideas why my matrices are wrong? (I think it might be something with the grayscale part of my problem)

Thank you in advance!

PS. ? also contacted the opencv mailing list, but I needed to post here just in case :slight_smile:

By the way,

If someone knows and could present me (even with a resource he/she has) a procedure to calibrate my stereo rig (I use 2 web cams) I would really appreciate it :slight_smile:

Thanks again!

Hello again!

I did some searching and thanks to a guy from the OpenCV mailing-list I managed to write some code that should be working :slight_smile:

So, I was told that the whole procedure to use cvFindFundamentalMat is the same as using cvFindHomography! [1]
Unfortunately my code still gives me the same output!

OpenCV ERROR: One of arguments’ values is out of range (Both input and output point dimensionality must be 2,3 or 4) in function cvConvertPointsHomogeneous, cvfundam.cpp(1270)

The code that deals with cvFindFundamentalMat uses the function “flannfindpairs” from link [1] !!!

  
      
image1 = (IplImage*) cvGray1.getCvImage();  
image2 = (IplImage*) cvGray2.getCvImage();  
  
CvMemStorage* storage = cvCreateMemStorage(0);  
  
CvSeq* image2_Keypoints = 0, *image1_Descriptors = 0;  
CvSeq* image1_Keypoints = 0, *image2_Descriptors = 0;  
  
CvSURFParams params = cvSURFParams(500, 1);  
  
cvExtractSURF( image2, 0, &image2_Keypoints, &image2_Descriptors, storage, params );  
cvExtractSURF( image1, 0, &image1_Keypoints, &image2_Descriptors, storage, params );  
  
        double fund[9];  
        CvMat _fund = cvMat(3, 3, CV_64F, fund);  
        vector<int> ptpairs;  
        vector<CvPoint2D32f> pt1, pt2;  
        CvMat _pt1, _pt2;  
        int i, n;  
  
        flannFindPairs( image2_Keypoints, image2_Descriptors, image1_Keypoints, image1_Descriptors, ptpairs );  
  
        n = (int)(ptpairs.size()/2);  
        if( n < 7 ){  
            printf("problem!!!!!");  
            return;  
        }  
  
        pt1.resize(n);  
        pt2.resize(n);  
        for( i = 0; i < n; i++ )  
        {  
            pt1[i] = ((CvSURFPoint*)cvGetSeqElem(image2_Keypoints,ptpairs[i*2]))->pt;  
            pt2[i] = ((CvSURFPoint*)cvGetSeqElem(image1_Keypoints,ptpairs[i*2+1]))->pt;  
        }  
  
        _pt1 = cvMat(1, n, CV_32FC2, &pt1[0] );  
        _pt2 = cvMat(1, n, CV_32FC2, &pt2[0] );  
  
    cvFindFundamentalMat(&_pt1, &_pt2, &_fund,CV_FM_RANSAC, 1.0, 0.99);  

I can’t find anything wrong! In fact, I also checked the “cvfundam.cpp” file here [2]
In fact, if you check out what’s going on with cvConvertPointsHomogeneous, it says that multichannel nx1 or 1xn arrays are accepted!

[1] https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/c/find-obj.cpp
[2] https://code.ros.org/trac/opencv/browser/trunk/opencv/src/cv/cvfundam.cpp?rev=2960
[3] http://opencv.willowgarage.com/documentation/camera-calibration-and-3d-reconstruction.html?highlight=homogeneous#cvConvertPointsHomogeneous