Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding camera and distortion matrix usinc cvCalibrateCamera2( )
    primarykey
    data
    text
    <p>I was trying to find out the camera matrix and distortion coefficients using <code>cvCalibrateCamera2</code>. There were no compilation errors, but when I am trying to execute the program it gives:</p> <blockquote> <p>OpenCV error: Sizes of input arguments do not match( both matrices must have the same number of points) in cvConvertPointsHomogenous, file /build/buildd/opencv-2.3.1/modules/calib3d/src/fundam.cpp</p> </blockquote> <p>size of the matrix storing object points in 4 x 3 and that of the matrix storing image points in 4 X2, what could be wrong?</p> <p>Now I made certain changes to my code. This is the code that I am using:</p> <pre><code>#include "opencv2/highgui/highgui.hpp" #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/calib3d/calib3d.hpp" #include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; //function to call cvCalibrateCamera2() void calibrate(CvMat* object_points, CvMat* image_points, CvMat* intrinsic,CvMat* distortion) { const int point_count= object_points-&gt;rows; const int image_count=object_points-&gt;rows/point_count; CvMat* const full_object_points = cvCreateMat(image_count*point_count,3,CV_32FC1); CvMat* const point_counts= cvCreateMat(image_count,1,CV_32SC1); for(int i =0; i&lt;image_count;i++) { CV_MAT_ELEM(*point_counts,float , i,0)= point_count; for(int j=0;j&lt;point_count;j++) { for(int k=0; k&lt;3;k++){ CV_MAT_ELEM(*full_object_points,float,i*point_count+j,k)=CV_MAT_ELEM(*object_points,float,j,k); } } } cvCalibrateCamera2(full_object_points,image_points,point_counts,cvSize(1,1),intrinsic, distortion,NULL,NULL,0); } int main() { const float points[][2]={{1,2},{0,0},{3,5},{5,2}}; const int image_count=5; const int point_count=sizeof(points)/sizeof(points[1]); CvMat* const object_points=cvCreateMat(point_count,3,CV_32FC1); for(int i=0; i&lt;point_count;i++) { CV_MAT_ELEM(*object_points, float, i,0)=points[i][0]; CV_MAT_ELEM(*object_points, float, i,1)=points[i][1]; CV_MAT_ELEM(*object_points, float, i,2)=0; } CvMat* const image_points=cvCreateMat(image_count*point_count,2,CV_32FC1); CvMat* const intrinsic=cvCreateMat(3,3,CV_32FC1); CvMat* const distortion=cvCreateMat(5,1,CV_32FC1); calibrate(object_points,image_points,intrinsic,distortion); } </code></pre> <p>On execution I am getting the following error:</p> <blockquote> <p>OpenCV Error: Bad argument (The total number of matrix elements is not divisible by the new number of rows) in cvReshape, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 2755 terminate called after throwing an instance of 'cv::Exception' what(): /build/buildd/opencv-2.3.1/modules/core/src/array.cpp:2755: error: (-5) The total number of matrix elements is not divisible by the new number of rows in function cvReshape</p> <p>Aborted (core dumped)</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload