2

I am currently trying to implement a basic image stitching C++ (OpenCV) code in Eclipse. The feature detection part shows great results for SURF Features. However, when I attempt to warp the 2 images together, I get only half the image as the output. I have tried to find a solution everywhere but to no avail. I even tried to offset the homography matrix , like in this answer OpenCV warpperspective . Nothing has helped so far.

I'll attach the output images in the comments since I don't have enough reputation points.

For feature detection and homography, I used the exact code from here http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html

And then I added the following piece of code after the given code,

Mat result;
warpPerspective(img_object,result,H, Size(2*img_object.cols,img_object.rows));
Mat half(result,Rect(0,0,img_scene.cols,img_scene.rows));
img_scene.copyTo(half);

imshow( "Warped Image", result);

I'm quite new at this and just trying to put the pieces together. So I apologize if there's some basic error.

Community
  • 1
  • 1
hriddle
  • 789
  • 1
  • 9
  • 11
  • Feature detection : http://i.stack.imgur.com/7UjVJ.jpg Output : http://i.stack.imgur.com/Fe392.jpg – hriddle Feb 04 '13 at 10:00

2 Answers2

1

If you're only trying to put the pieces together, you cold try the built in OpenCV image stitcher class: http://docs.opencv.org/modules/stitching/doc/high_level.html#stitcher

b_m
  • 1,473
  • 2
  • 18
  • 29
  • 2
    Thanks for the link. I actually meant that I want to put the pieces of the code together by learning the underlying steps. I just want to understand what's going wrong so I can fix it. – hriddle Feb 07 '13 at 06:41
0

I found a related question here Stitching 2 images in opencv and implemented the additional code given. It worked!

For reference, the edited code I wrote was

Mat result;
warpPerspective(img_scene, result, H, Size(img_scene.cols*2, img_scene.rows*2), INTER_CUBIC);
Mat final(Size(img_scene.cols + img_object.cols, img_scene.rows*2),CV_8UC3);
Mat roi1(final, Rect(0, 0,  img_object.cols, img_object.rows));
Mat roi2(final, Rect(0, 0, result.cols, result.rows));
result.copyTo(roi2);
img_object.copyTo(roi1);
Community
  • 1
  • 1
hriddle
  • 789
  • 1
  • 9
  • 11