hriddle
hriddle

Reputation: 789

OpenCV WarpPerspective issue

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.

Upvotes: 2

Views: 3291

Answers (2)

hriddle
hriddle

Reputation: 789

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);

Upvotes: 0

b_m
b_m

Reputation: 1533

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

Upvotes: 1

Related Questions