video stabilization crashes with a blank video (Bug #3023)


Added by Andrei Zaharescu almost 12 years ago. Updated over 11 years ago.


Status:Done Start date:2013-05-14
Priority:Normal Due date:
Assignee:Ivan Korolev % Done:

0%

Category:videostab
Target version:2.4.6 Estimated time:0.10 hour
Affected version:2.4.5 (latest release) Operating System:
Difficulty: HW Platform:
Pull request:https://github.com/Itseez/opencv/pull/993

Description

when there are no feature points, global_motion.cpp -? estimateGlobalMotionRobust crashes due to a division by 0.


global_motion.cpp (11.2 kB) Andrei Zaharescu, 2013-05-14 09:50 pm

global_motion.cpp (11.1 kB) Andrei Zaharescu, 2013-05-15 05:16 pm

global_motion.cpp (11.2 kB) Andrei Zaharescu, 2013-05-16 08:08 pm


Associated revisions

Revision de4c3f01
Added by Ivan Korolev over 11 years ago

Fixed a bug related to video stabilization crashes with a blank video (Bug #3023)

Revision b3e31fb8
Added by Alexander Alekhin over 10 years ago

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.

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);

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);

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

Also available in: Atom PDF