Different output from Python and C++ in CalibrateHandEye()
Hi,
We have tried to translate a C++ project into Python. The problem is that we get different outputs from the calibrateHandEye() function in the two versions. Even though the input is the same of course.
The code of interest is this part (C++ version)
Mat rotationCamera2Gripper, translationCamera2Gripper;
calibrateHandEye(rotationGripper2Base, translationGripper2Base, rvecsRod, tvecs,
rotationCamera2Gripper, translationCamera2Gripper, CALIB_HAND_EYE_TSAI);
Mat rotVecCam2Gripper;
Rodrigues(rotationCamera2Gripper, rotVecCam2Gripper);
std::cout << "Rot: " << std::endl << rotVecCam2Gripper << std::endl;
std::cout << "Trans: " << std::endl << translationCamera2Gripper << std::endl;
and in Python:
rotationCamera2Gripper, translationCamera2Gripper = cv.calibrateHandEye(
rotationGripper2Base,
translationGripper2Base,
rvecsRod,
tvecs,
method=cv.CALIB_HAND_EYE_TSAI)
rotVecCam2Gripper, _ = cv.Rodrigues(rotationCamera2Gripper)
print("Rot:")
print(rotVecCam2Gripper)
print("Trans: ")
print(translationCamera2Gripper)
The main difference is between the translation vectors. Output from C++:
Output from Python:
We end up in a situation where everything before calibrateHandEye seem to be the same, but the output is different. Any hint to what could be the problem is appreciated :)
How did you install Python OpenCV? If you are using
pip install
, you are not using the same config (e.g. Math libraries, version, etc.) between C++ OpenCV that you may have built from source andhttps://github.com/skvark/opencv-python
.the rotation vectors look identical but the translation vectors differ significantly. speculation: your the code in both language versions is not equivalent (check intermediate results!); you are actually not giving it the same input even though you think you do; you are feeding it too little data, and ill conditioned data for the algorithm; the algorithm contains some randomization (pose estimation) and that causes random behavior in either version when run repeatedly; the source in OpenCV has bugs that cause diverging behavior for minor disturbances (always a possibility in functions that aren't commonly used)
We used pip install for Python, and standard binaries for C++ (Visual Studio). We checked that we used same version of OpenCV (4.4.0) for both languages.
We import exactly the same data for both programs imported with FileStorage, and all other steps produce the same results. We use 16 poses for the calibration, and the results are consistent when run repeatedly (and on different computers/software versions). But there may be some problem with the data being ill conditioned...
The only thing we can't check is the OpenCV code that is called from the Python version of calibrateHandEye, as we haven't found a way to debug from Python into the original C++ functions.
What I would do:
pip