我有两幅图片(A和B),其中一幅略有扭曲,另一幅有平移、旋转和缩放差异(例如,这些图片:)


我需要的是在pic B中应用一种变换,这样它就可以补偿存在的失真/平移/旋转,使两幅图片都具有相同的大小、方向和没有平移。
我已经提取了点,找到了单字,如下所示。但是我不知道如何用“单字”来转换Mat img_B,所以它看起来像Mat img_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);干杯,
发布于 2012-11-26 17:55:49
您需要warpPerspective函数。该过程类似于这教程中提供的过程(用于仿射变换和翘曲)。
发布于 2016-01-13 18:59:48
对于这个问题,您不需要进行同形处理。你可以用仿射变换代替。但是,如果您确实希望将“同形”用于其他目的,则可以查看下面的代码。它是从这复制而来的,在同调上有很多详细的文章。
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);Python示例
'''
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)https://stackoverflow.com/questions/13570140
复制相似问题