Ask Your Question
1

Stitching 2 image with findHomography

asked 2015-11-17 13:27:59 -0600

Jalg gravatar image

Hi, i have troubles to stitching two image using findHomography and warpPerspective, my code is the next one:

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

Mat warpImage2;
warpPerspective(im2, warpImage2, H, Size(im2.cols, im2.rows), INTER_CUBIC, BORDER_TRANSPARENT);

Mat final(Size(im2.cols * 2 , im2.rows), CV_8UC3);

Mat roi1(final, Rect(0, 0, im.cols, im.rows));
Mat roi2(final, Rect(im.cols, 0, im2.cols, im2.rows));

warpImage2.copyTo(roi2);
im.copyTo(roi1);
imshow("final", final);

the problem is that the result is the next one:

http://imgur.com/hgAr1AB

I can move my roi manually and try and try untill stitching both but when i'll use that function for other image will not work.

There a form to stitching them without move de roi manually?

Thanks.

edit retag flag offensive close merge delete

Comments

Hello guy, You want to cut the two images by size.I have this function.

 Mat crop( Mat ent)

{ int maior_x, maior_y, menor_x, menor_y;

menor_x = maior_x = menor_y = maior_y = 900;

for(int rows = 900; rows < ent.rows; rows++) { for(int cols = 900; cols < ent.cols; cols++) { if(ent.at<vec3b>(rows, cols)[0] != 0 && ent.at<vec3b>(rows, cols)[1] != 0 && ent.at<vec3b>(rows, cols)[2] != 0 ) { if(rows < menor_y) { menor_y = rows; }

        if(rows > maior_y)
        {
            maior_y = rows;
        }

        if(cols < menor_x)
        {
            menor_x = rows;
        }

        if(cols > maior_x)
        {
            maior_x = cols;
        }
    }
}

}

diegomoreira gravatar imagediegomoreira ( 2015-11-17 16:51:06 -0600 )edit

Mmmm i think you don't understand me xD

I want a result similar to the class stitcher.

I don't need cut, the warpPerspective function with my homography cut my image correctly but i don't know how to stitch both without doing a roi like that:

Mat roi2(final, Rect(im.cols-77, 0, im2.cols, im2.rows));

Try and error say me that im.cols-77 is the position correct for my warpImage2 but i want put that without i have to create a function for all the images.

I hope undertand me or if i misundertand you excuse me.

Jalg gravatar imageJalg ( 2015-11-18 06:26:59 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-11 23:47:18 -0600

OpenCV_Learner gravatar image

I guess using opencv Stitcher class will help stitching multiple images:

vector<mat> images; images.push_back(imread("Set1/stretched1.jpg"));//Reading first image images.push_back(imread("Set1/stretched2.jpg"));//Reading second image Mat img;

Stitcher stitcher = Stitcher::createDefault(); Stitcher::Status stitcherStatus = stitcher.stitch(images, img);

imshow("First",img); images.clear(); images.push_back(img); images.push_back(imread("Set1/pic3 - Copy.jpg"));////Reading third image stitcherStatus = stitcher.stitch(images, img); imshow("Second",img)

In this way i tried to stitch 5 images, though it takes a lot of time. Is there any better way to do it for frames captured in video?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-11-17 13:27:59 -0600

Seen: 1,752 times

Last updated: Jan 11 '16