projectPoints function exception (Bug #1319)
Description
In this example:
http://programmingexamples.net/index.php?title=OpenCV/WishList/ProjectPoints
I have hardcoded a projection matrix, and corresponding 2D and 3D points. I am attempting to project the 3D points and show that they are close to their 2D correspondences. I have used float for all of the data types. However, I get this error:
OpenCV Error: Formats of input arguments do not match (All the matrices must have the same data type) in cvRodrigues2, file /home/ddoria/src/OpenCV- 2.3.0/modules/calib3d/src/calibration.cpp, line 507
terminate called after throwing an instance of 'cv::Exception'
what(): /home/ddoria/src/OpenCV-2.3.0/modules/calib3d/src/calibration.cpp:507: error: (-205) All the matrices must have the same data type in function cvRodrigues2
Can anyone explain this?
Thanks,
David
History
Updated by Alexander Shishkov over 13 years ago
Good day!
1) You should pass rvec and translation vector to projectPoints(...) function in double precision format.
If you really need float type you can change string 782 in calibrating.cpp (rev. 6832)
CvMat matR = cvMat( 3, 3, CV_64F, R ), _dRdr = cvMat( 3, 9, CV_64F, dRdr );
to
CvMat matR = cvMat( 3, 3, r_vec->type, R ), _dRdr = cvMat( 3, 9, r_vec->type, dRdr );
and string 841
_r = cvMat( 3, 1, CV_64FC1, r );
to
_r = cvMat( 3, 1, r_vec->type, r );
But these changes lead to significant loss of accuracy.
2) It is incorrect to use projectPoints(...) function with data that obtained by decomposeProjectionMatrix(...) function. Because decomposeProjectionMatrix(...) returns for intrinsics matrix upper triangular matrix instead of OpenCV model of intrinsics matrix:
[fx 0 cx
0 fy cy
0 0 1].
For example element (0,1) may be not equals to 0.
Also decomposeProjectionMatrix() returns translation vector in homogeneous coordinates (4x1), but projectPoints(...) requires 3x1 vector.
Best regards,
Alexander Shishkov.
- Status changed from Open to Done
- (deleted custom field) set to wontfix