video stabilization crashes with a blank video (Bug #3023)
Description
when there are no feature points, global_motion.cpp -? estimateGlobalMotionRobust crashes due to a division by 0.
Associated revisions
Fixed a bug related to video stabilization crashes with a blank video (Bug #3023)
Merge pull request #3023 from vbystricky:ocl_minMaxLoc
History
Updated by Andrei Zaharescu almost 12 years ago
if you add the following check in estimateGlobalMotionRobust after npoints is defined at the beginning
@
if (npoints==0)
{
Mat_<float> result = Mat_<float>::zeros(2,3);
result(0,0) = 1.0f;
result(1,1) = 1.0f;
return result;
}
@
the problem is solved (return the identity transformation).
Updated by Andrei Zaharescu almost 12 years ago
Here is my modified global_motion.cpp of 2.4.4.
Sorry that I did not have time to setup git and do a proper pull request.
- File global_motion.cpp added
Updated by Andrei Zaharescu almost 12 years ago
I still noticed some problems in other edge cases when there are not enough features. the previous solution seemed ok in VS2012, but had a problem in VS2005.
The correct solution is:
if (points0.size() < 5 || points1.size() < 5)
return Mat::eye(3, 3, CV_32F);
- File global_motion.cpp added
Updated by Andrei Zaharescu almost 12 years ago
Just to explain in more detail the use case: runn image stabilization on a camera that at some point can become temporarily obstructed (i.e. cover the webcam with you hand), resulting in no features to track.
Found some more issues:
Just to be on the safe side, we need at least 6 points, since the number of parameters is 6. so I've made it at least 10 points.
If 5 points are encountered (rarely, but it can happen), then it ends up in an infinite loop in the lines below, while trying to find potential indices.
if (points0.size() < 10 || points1.size() < 10)
return Mat::eye(3, 3, CV_32F);
Also..there needs to be a check before invoking the optical flow. If there are no points, that fails:
Hence I've introduced the check:
if (pointsPrev_.size() > 0)
optFlowEstimator_->run(frame0, frame1, pointsPrev_, points_, status_, noArray());
else
return Mat::eye(3, 3, CV_32F);
- File global_motion.cpp added
Updated by Alexander Shishkov almost 12 years ago
Thank you for reporting the issue. A pull request solving the issue in our GitHub repo would be highly appreciated!
Updated by Ivan Korolev over 11 years ago
- Assignee changed from Alexey Spizhevoy to Ivan Korolev
Updated by Vladislav Vinogradov over 11 years ago
- Pull request set to https://github.com/Itseez/opencv/pull/993
Updated by Vladislav Vinogradov over 11 years ago
- Status changed from Open to Done