cvCalibrateCamera2 broken in python-opencv

Bug #188539 reported by Karl Ostmo
4
Affects Status Importance Assigned to Milestone
OpenCV
Unknown
Unknown
opencv (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Binary package hint: python-opencv

Using version 1.0.0-3ubuntu3 of python-opencv.

The documentation produced via "pydoc opencv.cv.cvCalibrateCamera2" is:
cvCalibrateCamera2(CvMat object_points, CvMat image_points, CvMat point_counts, CvSize image_size, CvMat intrinsic_matrix, CvMat rotation_vectors=None, CvMat translation_vectors=None, int flags=0)

As you can see it lists 8 arguments. However, when providing all 8, it raises the exception:
TypeError: cvCalibrateCamera2() takes at most 7 arguments (8 given)

Even when providing the bare minimum of arguments (5, according to pydoc) with all the matrices set up properly (in other words, exactly the same as a working version in C), it raises this error:
RuntimeError: openCV Error:
Status=Bad argument
function name=cvCalibrateCamera2
error message=the output array of rotation vectors must be 3-channel 1xn or nx1 array or 1-channel nx3 or nx9 array, where n is the number of views
file_name=cvcalibration.cpp
line=1324

I have noticed that in C, the function prototype of cvCalibrateCamera2 includes an extra argument "distortion_coeffs":
void cvCalibrateCamera2( const CvMat* object_points, const CvMat* image_points, const CvMat* point_counts, CvSize image_size, CvMat* intrinsic_matrix, CvMat* distortion_coeffs, CvMat* rotation_vectors=NULL, CvMat* translation_vectors=NULL, int flags=0 );

Could it be that the mapping from Python arguments to C arguments is ill-defined?

Revision history for this message
Daniel T Chen (crimsun) wrote :

Is this symptom still reproducible in 8.10 or 9.04?

Changed in opencv:
status: New → Incomplete
Revision history for this message
Karl Ostmo (kostmo) wrote :

I have determined what was wrong with my usage. The third argument to the Python function cv.cvCalibrateCamera2 must be a one-dimensional matrix of integers (e.g. type cv.CV_32SC1). The cv.cvmSet function will interpret its value argument as a "double", regardless of whether it was an "int" to begin with. If this function is used to populate the values of a matrix of type cv.CV_32SC1, the values seem to be incorrectly reinterpreted as integers on the binary level, rather than simply truncating the fractional part. Thus, when populating the matrix of integers in Python, one must use the array notation, rather than cvmSet.

This works:
point_counts[3] = 15

while this does not:
cv.cvmSet(point_counts, 3, 0, 15)

A correct call to cv.cvCalibrateCamera2 would look like this:

 intrinsic, distortion = cv.cvCalibrateCamera2(
  object_points_matrix, # Object points: a 3xN matrix, listing all the points in all the images
  corners_matrix, # Image points: a 2xN matrix, listing all the 2D points in all the images
  point_counts, # A vector (i.e. 1xM matrix) of point counts per image
  frame_size # Image size, type CvSize
 )

Revision history for this message
seyacat (seyacat-seyanim) wrote :

Hi all
i can use with this format

intrinsic, distortion = cv.cvCalibrateCamera2(
  object_points_matrix, # Object points: a 3xN matrix, listing all the points in all the images
  corners_matrix, # Image points: a 2xN matrix, listing all the 2D points in all the images
  point_counts, # A vector (i.e. 1xM matrix) of point counts per image
  frame_size # Image size, type CvSize
 )

and it works ok, but i need to use CV_CALIB_USE_INTRINSIC_GUESS flag, and there is no way i can initialize intrinsic matrix, because i can input this in function

 (intrinsic_matrix, distortion_matrix) = cvCalibrateCamera2( mat, points, count, cvGetSize(videoimg) , MRot, MLoc, CV_CALIB_USE_INTRINSIC_GUESS);

" openCV Error: Status=One of arguments' values is out of range function name=cvCalibrateCamera2 error message=The intrinsic matrix must have [fx 0 cx; 0 fy cy; 0 0 1] shape file_name=cvcalibration.cpp line=1420"

without this flag it works correct but i cant calibrate camera appropiate

Revision history for this message
Karl Ostmo (kostmo) wrote :
Revision history for this message
Mattia Rizzolo (mapreri) wrote :

closing this old bug...

Changed in opencv (Ubuntu):
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.