OpenCV Image frames not stabilizing
<p>I am trying to perform a video stabilization technique using OpenCV and c++. This techniques involves the SURF detection and description, calculating homography and warping perspective based on the homography for each subsequent image frame. From the articles I have seen, I got the impression that this should produce a stabilized video but this is not the case. I can't seem to find out what I'm doing wrong. The following is my code</p>

<pre><code>Mat prev_frame, curr_frame;
int minHessian = 400;
Ptr&lt;SURF&gt; detector = SURF::create( minHessian );
std::vector&lt;KeyPoint&gt; prev_keypoints, curr_keypoints;
Mat prev_descriptors, curr_descriptors;


VideoCapture cap("patio.mp4");

if (!cap.isOpened())
    return -1;

cap &gt;&gt; curr_frame;

detector-&gt;detectAndCompute( curr_frame, Mat(), curr_keypoints, curr_descriptors );

namedWindow("Original Video");
namedWindow("Modified Video");
moveWindow("Modified Video", 600, 0);

FlannBasedMatcher matcher;
std::vector&lt; DMatch &gt; matches;

for(;;){

    prev_frame = curr_frame.clone();
    prev_keypoints = curr_keypoints;
    prev_descriptors = curr_descriptors.clone();

    curr_keypoints.clear();
    curr_descriptors = Mat();
    cap &gt;&gt; curr_frame;

    if( !prev_frame.data || !curr_frame.data )
    { std::cout&lt;&lt; " --(!) Error reading images " &lt;&lt; std::endl; return -1; }

    detector-&gt;detectAndCompute( curr_frame, Mat(), curr_keypoints, curr_descriptors );

    if (curr_keypoints.size() &lt; 20) {
        continue;
    }

    matcher.match( prev_descriptors, curr_descriptors, matches );

    double max_dist = 0; double min_dist = 100;
    for( int i = 0; i &lt; prev_descriptors.rows; i++ )
    {
        double dist = matches[i].distance;
        if( dist &lt; min_dist ) min_dist = dist;
        if( dist &gt; max_dist ) max_dist = dist;
    }

    std::vector&lt; DMatch &gt; good_matches;
    for( int i = 0; i &lt; prev_descriptors.rows; i++ )
    {
        if( matches[i].distance &lt; 3*min_dist )
        {
            good_matches.push_back( matches[i]);
        }
    }
    std::vector&lt;Point2f&gt; prev;
    std::vector&lt;Point2f&gt; curr;
    for( size_t i = 0; i &lt; good_matches.size(); i++ )
    {
        //-- Get the keypoints from the good matches
        prev.push_back( prev_keypoints[ good_matches[i].queryIdx ].pt );
        curr.push_back( curr_keypoints[ good_matches[i].trainIdx ].pt );
    }

    if (prev.size() &lt;=4 || curr.size() &lt;=4){
        continue;
    }
    Mat H = findHomography( prev, curr, RANSAC );

    Mat modified;
    warpPerspective(curr_frame,modified,H,curr_frame.size());

    imshow("Original Video", curr_frame);
    imshow("Modified Video", modified);

    waitKey(30);
}
waitKey(0);
</code></pre>

<p>The original and modified videos are in the following links respectively:</p>

<p><a href="https://www.dropbox.com/s/ilqwdocgankfe6n/input.mp4?dl=0" rel="nofollow">https://www.dropbox.com/s/ilqwdocgankfe6n/input.mp4?dl=0</a></p>

<p><a href="https://www.dropbox.com/s/1kd981j92drkfrn/output.mwv?dl=0" rel="nofollow">https://www.dropbox.com/s/1kd981j92drkfrn/output.mwv?dl=0</a></p>

<p>Please Help.</p>