You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
solvePnPGeneric Python Binding crash when reprojectionError is not passed as argument #16049
Operating System / Platform => Linux / Ubuntu 18.04
Compiler => ❔
Detailed description
When running the code below that call solvePnPGeneric from Python the program crashes because the C++ code expect a different type for reprojectionError from the one passed by solvePnPGeneric by default. The argument is however documented as optional. Passing the argument with the correct type avoid the error.
I suspect that the binding of the solvePnPGeneric function do not pass the correct argument type for reprojectionError by default.
The error:
Traceback (most recent call last):
File "error.py", line 15, in<module>
obj_points, img_points, cameraMatrix, distCoeffs #, reprojectionError=r
cv2.error: OpenCV(4.1.2) /io/opencv/modules/calib3d/src/solvepnp.cpp:1017: error: (-2:Unspecified error) infunction'int cv::solvePnPGeneric(cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::OutputArrayOfArrays, cv::OutputArrayOfArrays, bool, cv::SolvePnPMethod, cv::InputArray, cv::InputArray, cv::OutputArray)'> Type of reprojectionError must be CV_32FC1 or CV_64FC1!:> 'type == CV_32FC1 ||type == CV_64FC1'> where> 'reprojectionError.type()' is 0 (CV_8UC1)
This might be closely linked to #16040 which is about Java binding of solvePnPGeneric
changed the title [-]solvePnPGeneric Python Binding crash when no reprojectionError is passed[/-][+]solvePnPGeneric Python Binding crash when reprojectionError is not passed as argument[/+]on Dec 3, 2019
CV_CheckType(reprojectionError.type(), type == CV_32FC1 || type == CV_64FC1,
"Type of reprojectionError must be CV_32FC1 or CV_64FC1!");
the default noArray() won't trigger needed(), but once we pass (a ref to) an empty Mat, we get past that check and it creates the wrong type (still CV_8U).
OutputArray param = noArray() is used in meaning of optional output parameter, which should be calculated only if requested. Calculation (which can be heavy) is guarded by .needed() check.
Python bindings is not able to work with OutputArray directly. They using Mat and the problem is in that (bindings generator and wrappers should be fixed).
However removal of type check can unlock calling of this function with empty Mat as OutputArray parameter:
with 64F type by default?
or max(_ipoint.depth(), _opoint.depth()) == CV_64F ? CV_64F : CV_32F
You can try to unlock function for empty "Mat".
Start from adding corresponding simple test (modules/calib3d/misc/python/test/test_solvepnp.py) - no need to check accuracy, just check that bindings work (non empty result of "expected" type).
But please avoid part of issue about:
OutputArray param = noArray()
Mentor with strong Python bindings experience is required for this task.
Activity
[-]solvePnPGeneric Python Binding crash when no reprojectionError is passed[/-][+]solvePnPGeneric Python Binding crash when reprojectionError is not passed as argument[/+]alalek commentedon Dec 4, 2019
Python bindings is not able to pass default value for "OutputArray reprojectionError = noArray()" parameter.
Need to fix bindings generator. Corresponding test check is here (commented out).
berak commentedon Dec 4, 2019
i don't quite agree. i could reproduce it from c++:
leading to:
it's the very same thing done in the python wrappers
so let's look here:
opencv/modules/calib3d/src/solvepnp.cpp
Lines 1012 to 1017 in 4c71dbf
the default
noArray()won't triggerneeded(), but once we pass (a ref to) an empty Mat, we get past that check and it creates the wrong type (still CV_8U).why not create a Mat of correct type / size like:
and remove the type check / assertion ?
alalek commentedon Dec 4, 2019
OutputArray param = noArray()is used in meaning of optional output parameter, which should be calculated only if requested. Calculation (which can be heavy) is guarded by.needed()check.Python bindings is not able to work with
OutputArraydirectly. They usingMatand the problem is in that (bindings generator and wrappers should be fixed).However removal of type check can unlock calling of this function with empty
MatasOutputArrayparameter:64Ftype by default?max(_ipoint.depth(), _opoint.depth()) == CV_64F ? CV_64F : CV_32Fganesh-k13 commentedon Jan 20, 2020
Hi @alalek , can I look into this issue?
alalek commentedon Jan 20, 2020
You can try to unlock function for empty "Mat".
Start from adding corresponding simple test (
modules/calib3d/misc/python/test/test_solvepnp.py) - no need to check accuracy, just check that bindings work (non empty result of "expected" type).But please avoid part of issue about:
Mentor with strong Python bindings experience is required for this task.
ganesh-k13 commentedon Jan 21, 2020
Sure @alalek, I'll do the following:
modules/calib3d/misc/python/test/test_solvepnp.pyopencv/modules/calib3d/src/solvepnp.cpp
Line 1015 in 4c71dbf
by adding max(_ipoint.depth(), _opoint.depth()) == CV_64F ? CV_64F : CV_32F for default
typeMerge pull request opencv#16405 from ganesh-k13:bugfix/solvepnp-crash