Fix ransac issue "SolvePnPRansac Fails because calls to solvePnP with less than 6 points"#19492
Fix ransac issue "SolvePnPRansac Fails because calls to solvePnP with less than 6 points"#19492Dylancer1998 wants to merge 2 commits intoopencv:3.4from Dylancer1998:fix-ransac-issue
Conversation
|
@catree Could you help me review this PR? Thanks! |
|
|
Is there any problem? Could you guide me what should I do? |
catree
left a comment
There was a problem hiding this comment.
Quick review.
Probably we could try to fuse the two PRs.
modules/calib3d/src/solvepnp.cpp
Outdated
| distCoeffs, rvec, tvec, useExtrinsicGuess, | ||
| (flags == SOLVEPNP_P3P || flags == SOLVEPNP_AP3P) ? SOLVEPNP_EPNP : flags) ? 1 : -1; | ||
| } | ||
| catch(...){ |
There was a problem hiding this comment.
I think it is better to have catch (const cv::Exception& e).
And log also e.what(). This way, if another type of exception is thrown from solvePnP it will be logged.
There was a problem hiding this comment.
Ok. I agree with you. I have already commited the modification.
| camera_mat.at<float>(1, 2) = 353.712; | ||
| camera_mat.at<float>(2, 2) = 1.f; | ||
|
|
||
| pts3ds = { |
There was a problem hiding this comment.
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2247:5: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2238:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2238:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2238:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2258:5: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2249:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2249:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/build/precommit_linux64/3.4/opencv/modules/calib3d/test/test_solvepnp_ransac.cpp:2249:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
See the buildbot (you can click on the build numbers): https://pullrequest.opencv.org/#/summary/opencv
This requires C++11 and 3.4 OpenCV cannot require C++11 features.
There was a problem hiding this comment.
Please help me what should I do to fix the build failures?
There was a problem hiding this comment.
Initializer list for vector is a C++11 feature which should not be used here. You can either push_back the points to the vector, or use cv::Mat instead. See my PR here.
| catch(const cv::Exception& e) | ||
| { | ||
| CV_LOG_DEBUG(e.what()); | ||
| CV_LOG_DEBUG(NULL, "Broken implementation for DLT algorithm needs at least 6 points for pose estimation. Fallback to EPnP."); |
There was a problem hiding this comment.
Log message here is inaccurate. You cannot just presume that the Exception can only be caused by DLT algorithm.
| if(_inliers.needed()) | ||
| { | ||
| Mat _local_inliers; | ||
| for (int i = 0; i < npoints; ++i) | ||
| { | ||
| if((int)_mask_local_inliers.at<uchar>(i) != 0) // inliers mask | ||
| _local_inliers.push_back(i); // output inliers vector | ||
| } | ||
| _local_inliers.copyTo(_inliers); | ||
| } | ||
|
|
||
| return true; |
There was a problem hiding this comment.
Unnecessary codes (L329-L340)
|
@Johnzdh |
Great job~ Thanks! |
Firstly, I proposed this issue in there. issue #17799
I did some amendment based on this PR.
My solutions:
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.