Search code examples
cvisual-studioopencvtriangulation

error : sizes of input arguments do not match. cvTriangulatePoints


I used the function cvTriangulatePoints (see doc :http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html ) on visual studio. When I have one corresponding point per images (N=1) the code works but if I add a second point (N=2) I got the following error : "error : sizes of input arguments do not match < Number of points must be the same> in cvTriangulatePoints." It's the first time I use cvTriangulatePoints with more than 1 corresponding points. Is it possible to add more points or do I have another error ?

CvMat* projMatr1;
CvMat* projMatr2;
CvMat* projPoints1;
CvMat* projPoints2;
CvMat* points4D;
int N = 2;

projMatr1 = cvCreateMat(3, 4, CV_64FC1);
projMatr2 = cvCreateMat(3, 4, CV_64FC1);
projPoints1 = cvCreateMat(2, N, CV_64FC1);
projPoints2 = cvCreateMat(2, N, CV_64FC1);
points4D = cvCreateMat(4, N, CV_64FC1);
// I fill the matrices with the opencv function cvSet2D()
cvTriangulatePoints(projMatr1, projMatr2, projPoints1, projPoints2, points4D);

Solution

  • When value of N (number of channels) is raised from 1 to 2, the last argument in cvCreateMat should also be changed from

    CV_64FC1 to CV_64FC2. 
           ^           ^
    
    projPoints1 = cvCreateMat(2, N, CV_64FC2);
    projPoints2 = cvCreateMat(2, N, CV_64FC2);
    points4D = cvCreateMat(4, N, CV_64FC2);
    

    The Cx portion of the arguement refers to the number of channels.

    More generally, type name of a Mat object consists of several parts. Here's example for CV_64FC1:

    • CV_ - library prefix
    • 64 - number of bits per base matrix element (e.g. pixel value in grayscale image or single color element in BGR image)
    • F - type of the base element. In this case it's F for float, but can also be S (signed) or U (unsigned)
    • Cx - number of channels included in image

    ...Cx for you should be ...C2
    ...from here

    Here is more information on CvType.