Ask Your Question

Revision history [back]

C++ openCV video to panorama

I'm trying to create panorama out of a video by stitching frame n-1 with frame n. My problem is that after (around 20 frames) the right side of the picture gets very blurry and I don't know what to do with it.

main:

 frames = getVideoFrames();
 stichPair(frames[1], frames[0], panorama[0]);
for (int i = 2; i < SIZE; i++)
{
    stichPair(frames[i], panorama[i - 2], panorama[i - 1]);
    printf("%d\n", i);
}

cvNamedWindow(windowsName1, 1);
on_trackbar(index, 0);
createTrackbar("MyTrackbar:", windowsName1, &index, SIZE - 2, on_trackbar);

stichPair:

  Ptr<FeatureDetector> brisk = BRISK::create(20, 3, 1.0f);
    Ptr<DescriptorMatcher> matcher = BFMatcher::create("BruteForce-Hamming");
   // find features
brisk->detect(leftImage, keypoints_1);
brisk->detect(rightImage, keypoints_2);
brisk->compute(leftImage, keypoints_1, descriptors_1);
brisk->compute(rightImage, keypoints_2, descriptors_2);

// Find two nearest matches
matcher->knnMatch(descriptors_1, descriptors_2, matches, 2);

//filter bad matches
const float ratio = 0.6;
for (int i = 0; i < matches.size(); ++i)
{
    if (matches[i][0].distance / matches[i][1].distance < ratio)
    {
        good_matches.push_back(matches[i][0]);
    }
}

for (size_t i = 0; i < good_matches.size(); i++)
{
    leftImage_matchedKPs.push_back(keypoints_1[good_matches[i].queryIdx].pt);
    rightImage_matchedKPs.push_back(keypoints_2[good_matches[i].trainIdx].pt);
}

H = findHomography(Mat(rightImage_matchedKPs), Mat(leftImage_matchedKPs), RANSAC, 5);
warpPerspective(rightImage, rightImageWarped, H, Size(4000, 1280)); // fixed size

panorama = rightImageWarped.clone();
roi = Mat(panorama, Rect(0, 0, leftImage.cols, leftImage.rows));
leftImage.copyTo(roi);

after 20 frames:

i.stack.imgur.com/FiHd9.jpg

after 40 frames:

i.stack.imgur.com/U7ucU.jpg