使用Opencv提取图像的公共部分 [英] Extract common part of images with Opencv

查看:123
本文介绍了使用Opencv提取图像的公共部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,用于查找图像之间的差异.现在,我正在使用AKAZE查找功能,因此,我已经知道了这2张图像的共同点.问题在于这两个图像只有一部分相同.如何从两个图像中提取公共部分?为了更好的解释:我需要从第一张图像中提取公共部分,然后从第二张图像中提取,因此我可以执行absdiff来发现差异. 我正在用C ++编程

谢谢大家!

解决方案

您应该将第一个图像扭曲到第二个图像上.您可以使用关键点对应关系给出的findHomographyperspectiveTransform函数.您可以在此处找到所需的大多数代码... >

更新


顺便说一句,今天我不得不做基本相同的事情.它已在灰色图像(Mat1b)上进行了测试,但仅需进行较小的更改即可应用于rgb图像(Mat3b). 这里是代码的相关部分:

Mat1b A = imread("...");
Mat1b B = imread("...");

vector<Point2f> ptsA; 
vector<Point2f> ptsB;

// Fill ptsA, ptsB with the points given by the match of your descriptors.

Mat H = findHomography(ptsA, ptsB, CV_RANSAC); // With ransac is more robust to outliers

Mat1b warpedA;
warpPerspective(A, warpedA, H, B.size());

// Now compute diff
Mat1b res;
absdiff(warpedA, B, res);

// res is what you are looking for!

I'm writing a program that find differences between images. For now, I'm finding features with AKAZE, so I've the common point of the 2 images. The problem is that these 2 images have only a part in common. How can I extract the common part from both images? For better explanation: I need to extract the common part from the first image and then from the second, so I can do absdiff for finding difference. I'm programming in c++

Thanks to all!

解决方案

You should warp the first image onto the second. You can use findHomography and perspectiveTransform functions given by the correspondence of your keypoints. You can find most of the code you need here.

Update


Incidentally, I had to do basically the same stuff today. It's tested on gray images (Mat1b), but should require only minor changes to apply to rgb images (Mat3b). Here the relevant parts of the code:

Mat1b A = imread("...");
Mat1b B = imread("...");

vector<Point2f> ptsA; 
vector<Point2f> ptsB;

// Fill ptsA, ptsB with the points given by the match of your descriptors.

Mat H = findHomography(ptsA, ptsB, CV_RANSAC); // With ransac is more robust to outliers

Mat1b warpedA;
warpPerspective(A, warpedA, H, B.size());

// Now compute diff
Mat1b res;
absdiff(warpedA, B, res);

// res is what you are looking for!

这篇关于使用Opencv提取图像的公共部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆