1

I am using openCV to write a code that can find and replace one image with another image

Here is my 1st image enter image description here

Now i have 2nd image as this enter image description here

I need to replace the second image with this enter image description here

and final output should be like this enter image description here

So how to start about ? I am not sure how can i find it, I tried using Template Matching but the images are supposed to be exactly equal for template matching, and when my images are distorted or skewed in some manner then it doesn't work ?

How can i match the image get the bounds using openCV, and replace with another image ? Any help would be appreciated Thank you

4

2 回答 2

1

SURF 算法,这就是你想要的。OPENCV SURF 示例

于 2013-10-02T12:58:04.650 回答
0

您可以使用此SURF 算法来匹配图像,如下所示

编码

line( img_scene , scene_corners[0] + Point2f( img_object .cols, 0), scene_corners[1] + Point2f( img_object .cols, 0), Scalar(0, 255, 0), 4 );

不会在场景图像上而是在对象上绘制图像,所以使用它

line( img_scene , scene_corners[0], scene_corners[1] , Scalar(0, 255, 0), 4 );
line( img_scene , scene_corners[1] , scene_corners[2] , Scalar( 0, 255, 0), 4 );
line( img_scene , scene_corners[2] , scene_corners[3], Scalar( 0, 255, 0), 4 );
line( img_scene , scene_corners[3] , scene_corners[0], Scalar( 0, 255, 0), 4 );

现在替换图像使用这个

Mat temp;
cv::resize(mReplacementImage,temp,img_object .size());
warpPerspective(temp, mReplacementImage, H, img_scene .size());
Mat mask = cv::Mat::ones(img_object .size(), CV_8U);
Mat temp2;
warpPerspective(mask, temp2, H, img_scene .size());
mReplacementImage.copyTo(img_scene , temp2);
cv::imwrite("output.bmp",img_scene );
于 2013-10-04T12:13:01.757 回答