如何在OpenCV中使用单应性变换图片?
我有两张图片(A和B),一张图片与另一张图片有轻微的扭曲,它们之间存在平移、旋转和缩放差异(例如,这些图片:)如何在OpenCV中使用单应性变换图片?,opencv,transformation,distortion,homography,Opencv,Transformation,Distortion,Homography,我有两张图片(A和B),一张图片与另一张图片有轻微的扭曲,它们之间存在平移、旋转和缩放差异(例如,这些图片:) SSooooo我需要的是在图片B中应用一种变换,以补偿存在的失真/平移/旋转,从而使两张图片具有相同的大小、方向,并且没有平移 我已经提取了点并找到了单应性,如下所示。但是我不知道如何使用单应变换matimg\u B,所以它看起来像matimg\u A。有什么想法吗 //-- Localize the object from img_1 in img_2 std::vector&
SSooooo我需要的是在图片B中应用一种变换,以补偿存在的失真/平移/旋转,从而使两张图片具有相同的大小、方向,并且没有平移 我已经提取了点并找到了单应性,如下所示。但是我不知道如何使用单应变换
matimg\u B
,所以它看起来像matimg\u A
。有什么想法吗
//-- Localize the object from img_1 in img_2
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for (unsigned int i = 0; i < good_matches.size(); i++) {
//-- Get the keypoints from the good matches
obj.push_back(keypoints_object[good_matches[i].queryIdx].pt);
scene.push_back(keypoints_scene[good_matches[i].trainIdx].pt);
}
Mat H = findHomography(obj, scene, CV_RANSAC);
/--在img_2中从img_1定位对象
std::向量obj;
矢量场景;
for(无符号整数i=0;i
干杯,您想要这个功能。该过程类似于教程中介绍的过程(对于仿射变换和扭曲)此问题不需要单应性。可以改为计算仿射变换。但是,如果您确实想将单应用于其他目的,可以查看下面的代码。它是从一篇关于这个问题的非常详细的文章中抄来的 C++示例
// pts_src and pts_dst are vectors of points in source
// and destination images. They are of type vector<Point2f>.
// We need at least 4 corresponding points.
Mat h = findHomography(pts_src, pts_dst);
// The calculated homography can be used to warp
// the source image to destination. im_src and im_dst are
// of type Mat. Size is the size (width,height) of im_dst.
warpPerspective(im_src, im_dst, h, size);
'''
pts_src and pts_dst are numpy arrays of points
in source and destination images. We need at least
4 corresponding points.
'''
h, status = cv2.findHomography(pts_src, pts_dst)
'''
The calculated homography can be used to warp
the source image to destination. Size is the
size (width,height) of im_dst
'''
im_dst = cv2.warpPerspective(im_src, h, size)