-
-
Notifications
You must be signed in to change notification settings - Fork 56.4k
Description
System information (version)
- OpenCV => 4.1.0
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017
Detailed description
In some rare cases, some src and dst keypoints generate an error in computeError (fundam.cpp), line 205, where a division by zero occurs.
This error can be observed when calling cv::findHomography with RANSAC method
Steps to reproduce
I've attached a zip file containing:
code snippet to reproduce the issue (observed on 4.1.0 version of the lib, but likely still there in 4.5.0).
a yml file containing src and dst keypoints (this set generates the divide by zero on my system). Some others sets can be provided if needed.
The attached code snippet will load the source and dst keypoints from the keypoints yml file, and perform homography search using RANSAC.... and will crash due to divide by zero when looking for inliners/outliners.
code_snippet_cvbug.zip
std::string keyPoints = "cvbug_keypoints.yml";
test_utils::BuildPathToInputImage(keyPoints);
//-- Localize the object
std::vector<cv::Point2f> obj;
std::vector<cv::Point2f> scene;
cv::FileStorage fs(keyPoints.c_str(), cv::FileStorage::READ);
cv::FileNode srcFileNode = fs["srcPoints"];
read(srcFileNode, obj);
cv::FileNode dstFileNode = fs["dstPoints"];
read(dstFileNode, scene);
fs.release();
cv::Mat h = cv::Mat();
try
{
h = cv::findHomography(scene, obj, cv::noArray(), cv::RANSAC);
}
catch(...)
{
// Here all the trouble started ....
// divide by zero triggered by fundam.cpp, line 205 (denominator in operation to compute ww evaluates to zero)
}
Related code:
https://github.com/opencv/opencv/blame/4.1.0/modules/calib3d/src/fundam.cpp#L205
Issue submission checklist
- [ X] I report the issue, it's not a question
- I updated to latest OpenCV version and the issue is still there
Could not update yet. OpenCV is used in our production code and I wasn't able to perform the switch yet. Will do it later on.. - [X ] There is reproducer code and related data files