Ask Your Question
0

videostab::estimateGlobalMotionLeastSquares() doesn't work properly

asked 2017-10-17 23:17:07 -0600

Dan Do gravatar image

updated 2017-10-19 20:42:32 -0600

Hi there,

Could any one give me an example of using videostab APIs in OpenCV-3.3.0 to estimate global motion between two adjacent frames? I couldn't find any of them, so I have figured out my way (as explained step by step bellowed). I am trying with estimateGlobalMotionLeastSquares(), but things seem doesn't work well.

Here are 2 original gray frames (left: previous, right: current) between those I want to find the global motion matrix.

image description

After the extraction of keypoints (using cv::goodFeatureTotrack).

image description

Getting transformation matrix with estimateGlobalMotionLeastSquares(), then have it transform the previous frame into coordinate space of the current one (left) and compute difference image (right).

image description

You can see that the result are terrible. In bellow I attach my piece of code, I would highly appreciate a help to figure out possible mistakes in it, or favorably a well working sample of code.

 //------------- READ 2 CONSECUTIVE FRAMES
 videoSrc.read(prev_frame);
 videoSrc.read(cur_frame);

 //------------- CONVERT TO GRAY SCALE & EXTRACT KEY POINTS
 cvtColor(prev_frame, prev_gray, COLOR_RGB2GRAY);
 cvtColor(cur_frame, cur_gray, COLOR_RGB2GRAY);

 goodFeaturesToTrack(prev_gray, prev_keypoints, 500, 0.04f, 10, cv::Mat(), 5, 0, 0.04f);
 goodFeaturesToTrack(cur_gray, cur_keypoints, 500, 0.04f, 10, cv::Mat(), 5, 0, 0.04f);


 //------------- ESTIMATE GLOBAL MOTION BASED ON THE ABOVE SETS OF KEY POINTS
 Mat m_transform = videostab::estimateGlobalMotionLeastSquares(prev_keypoints, cur_keypoints, videostab::MM_AFFINE, NULL);


 //------------- COMPUTE DIFFERENCE IMAGES
 Mat prev_gray_trans, diffImg, normImg;

 warpPerspective(prev_gray, prev_gray_trans, m_transform, Size(prev_gray.cols, prev_gray.rows));
 diffImg = cur_gray - prev_gray_trans;
 normalize (diffImg, normImg, 0, 255, NORM_MINMAX, CV_8UC1, Mat());
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-03-14 21:09:53 -0600

Your 2 points sets are independent of one another. I think you need to use one of the feature matching functions:

BFMatcher() FlannBasedMatcher()

to find corresponding sets of points to pass in.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-10-17 23:15:42 -0600

Seen: 371 times

Last updated: Oct 19 '17