0

Opencv でビデオからモザイクを作成しています。ビデオのフレームをステッチするためにこの例を使用しています: http://docs.opencv.org/doc/tutorials/features2d/feature_detection/feature_detection.html。最後に、新しいフレームを渡された反復で作成されたステッチとマージするためにこれを行っています。

Mat H = findHomography(obj, scene, CV_RANSAC);

static Mat rImg;
warpPerspective(vImg[0], rImg, H, Size(vImg[0].cols, vImg[0].rows), INTER_NEAREST);//(vImg[0], rImg, H, Size(vImg[0].cols * 2, vImg[0].rows * 2), CV_INTER_LINEAR);

static Mat final_img(Size(rImg.cols*2, rImg.rows*2), CV_8UC3);
static Mat roi1(final_img, Rect(0, 0, vImg[1].cols, vImg[1].rows));
Mat roi2(final_img, Rect(0, 0, rImg.cols, rImg.rows));

rImg.copyTo(roi2);
vImg[1].copyTo(roi1);

imwrite("stitch.jpg", final_img);
vImg[0] = final_img;

final_imgだからここに私の問題があります.明らかにステッチは反復ごとに大きくなります.画像に収まるようにサイズを変更するにはどうすればよいですか?

編集 申し訳ありませんが、画像を削除する必要がありました

4

1 に答える 1

0

For the second question, what you observe is an error in the homography that was estimated. This may come either from:

  1. drift (if you chain homographies along the sequence), ie, small errors that accumulate and become large after dozens of frames
  2. or (more likely) because your reference image is too old with respect to your new image, and they exhibit too few matching points to give an accurate homography, but yet enough to find one that passes the quality test inside cv::findHomography().

For your first question, you need to add some code that keeps track of the current bounds of the stitched image in a fixed coordinate frame. I would suggest to choose the coordinates linked with the first image.

Then, when you stitch a new image, what you do really is to project this image onto this coordinate frame. You can compute first for example the projected coordinates of the 4 corners of the incoming frame, test if they fit into the current stitching result, copy it to a new (bigger) image if necessary, then proceed with stitching the new image.

于 2015-03-25T08:26:02.123 に答える