CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
calib3d: fix Rodrigues CV_32F and CV_64F type mismatch in projectPoints #25824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The solution is not complete:
The similar should be done for tvec. |
@asmorkalov could you show which data format you used as input? The translation vector should not be related to this issue. To me this looks more like the type assertion in projectPoints reacts to some invalid input opencv/modules/calib3d/src/calibration.cpp Lines 621 to 625 in b8ec949
|
I realized just now that the original issue python code uses invalid data input. projectPoints expects tvec to be a 3x1 or 1x3 vector, not a 3x3 matrix. |
@j3knk, thank you for the patch! Could you please add a test that reproduces error in the original code? |
@vpisarev I have used this example code from #25318 (comment) for testing. Did not have the time to create some randomized tests yet, but this triggers the original bug for sure. #include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/calib3d.hpp"
int main( int argc, char* argv[] )
{
using type = float;
cv::Mat objectPoints = (cv::Mat_<type>(3,3) << 181.24588 , 87.80361 , 11.421074,
87.17948 , 184.75563 , 37.223446,
22.558456, 45.495266, 246.05797);
cv::Mat rvec = (cv::Mat_<type>(3,3) << 0.9357548 , -0.28316498, 0.21019171,
0.30293274, 0.9505806 , -0.06803132,
-0.18054008, 0.12733458, 0.9752903);
cv::Mat tvec = (cv::Mat_<type>(3,1) << 69.32692 , 17.602057, 135.77672);
cv::Mat cameraMatrix = (cv::Mat_<type>(3,3) << 214.0047 , 26.98735 , 253.37799,
189.8172 , 10.038101, 18.862494,
114.07123 , 200.87277 , 194.56332);
cv::Mat distCoeffs = cv::Mat_<type>(4, 1, (type)0);
cv::Mat out;
cv::projectPoints(objectPoints, rvec, tvec, cameraMatrix, distCoeffs, out);
std::cout << out << std::endl;
return 0;
} |
Equivalent in Python: import cv2
import numpy as np
objectPoints = np.array([[181.24588 , 87.80361 , 11.421074],
[ 87.17948 , 184.75563 , 37.223446],
[ 22.558456, 45.495266, 246.05797 ]], dtype=np.float32)
rvec = np.array([[ 0.9357548 , -0.28316498, 0.21019171],
[ 0.30293274, 0.9505806 , -0.06803132],
[-0.18054008, 0.12733458, 0.9752903 ]], dtype=np.float32)
tvec = np.array([ 69.32692 , 17.602057, 135.77672 ], dtype=np.float32)
cameraMatrix = np.array([[214.0047 , 26.98735 , 253.37799 ],
[189.8172 , 10.038101, 18.862494],
[114.07123 , 200.87277 , 194.56332 ]], dtype=np.float32)
distCoeffs = distCoeffs = np.zeros((4, 1), dtype=np.float32)
imagePoints, _ = cv2.projectPoints(objectPoints, rvec, tvec, cameraMatrix, distCoeffs)
print(imagePoints) |
calib3d: fix Rodrigues CV_32F and CV_64F type mismatch in projectPoints opencv#25824 Fixes opencv#25318 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
Fixes #25318
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.