【发布时间】:2017-06-13 21:33:53
【问题描述】:
我正在尝试创建拼接算法。我已经成功地创建了它,需要进行一些调整。下面的照片是迄今为止我的拼接程序的示例。我能够为它提供一个无序列表的图像(只要图像在飞行路径中或并排,无论它们彼此的方向如何,它都可以工作。
问题是如果图像被颠倒,一些图像不会进入最终产品。这是实际拼接的代码。假设找到关键点、匹配和单应性是正确的。
通过更改此代码,有一种方法可以将第一张图像居中到目标空白图像并仍然缝合到它。另外,我在堆栈溢出时得到了这段代码 (Opencv Image Stitching or Panorama),我不完全确定它是如何工作的,如果有人能解释一下,我会很高兴。
提前感谢您的帮助!
Mat stitchMatches(Mat image1,Mat image2, Mat homography){
Mat result;
vector<Point2f> fourPoint;
//-Get the four corners of the first image (master)
fourPoint.push_back(Point2f (0,0));
fourPoint.push_back(Point2f (image1.size().width,0));
fourPoint.push_back(Point2f (0, image1.size().height));
fourPoint.push_back(Point2f (image1.size().width, image1.size().height));
Mat destination;
perspectiveTransform(Mat(fourPoint), destination, homography);
double min_x, min_y, tam_x, tam_y;
float min_x1, min_x2, min_y1, min_y2, max_x1, max_x2, max_y1, max_y2;
min_x1 = min(fourPoint.at(0).x, fourPoint.at(1).x);
min_x2 = min(fourPoint.at(2).x, fourPoint.at(3).x);
min_y1 = min(fourPoint.at(0).y, fourPoint.at(1).y);
min_y2 = min(fourPoint.at(2).y, fourPoint.at(3).y);
max_x1 = max(fourPoint.at(0).x, fourPoint.at(1).x);
max_x2 = max(fourPoint.at(2).x, fourPoint.at(3).x);
max_y1 = max(fourPoint.at(0).y, fourPoint.at(1).y);
max_y2 = max(fourPoint.at(2).y, fourPoint.at(3).y);
min_x = min(min_x1, min_x2);
min_y = min(min_y1, min_y2);
tam_x = max(max_x1, max_x2);
tam_y = max(max_y1, max_y2);
Mat Htr = Mat::eye(3,3,CV_64F);
if (min_x < 0){
tam_x = image2.size().width - min_x;
Htr.at<double>(0,2)= -min_x;
}
if (min_y < 0){
tam_y = image2.size().height - min_y;
Htr.at<double>(1,2)= -min_y;
}
result = Mat(Size(tam_x*2,tam_y*2), CV_32F);
warpPerspective(image2, result, Htr, result.size(), INTER_LINEAR, BORDER_CONSTANT, 0);
warpPerspective(image1, result, (Htr*homography), result.size(), INTER_LINEAR, BORDER_TRANSPARENT,0);
return result;`
【问题讨论】:
-
离题:看起来你玩得很开心。前段时间研究了这一点,以使用无人机检测石油管道泄漏,然后再进行另一项工作。不知道是否有人建造过它。
-
你所说的“反转”是什么意思?
-
我将此标记为重复。这根本不是一个坏问题,但我just answered a very similar question the other day。希望对您有所帮助!
-
KjMag - 颠倒是指图像通过管道传输到程序中的顺序。我希望它能够将图像拼接在一起,而不管顺序如何(如果最左边的图像是第一个或最右边的图像是第一个)。
标签: c++ opencv image-stitching