【发布时间】:2017-05-26 10:40:31
【问题描述】:
我对 OpenCV 完全陌生,我已经开始深入研究它。但我需要一点帮助。
所以我想合并这两张图片:
我希望这 2 张图像沿着它们的边缘匹配(暂时忽略图像的最右侧部分)
谁能指出我正确的方向?我试过使用findTransformECC 函数。这是我的实现:
cv::Mat im1 = [imageArray[1] CVMat3];
cv::Mat im2 = [imageArray[0] CVMat3];
// Convert images to gray scale;
cv::Mat im1_gray, im2_gray;
cvtColor(im1, im1_gray, CV_BGR2GRAY);
cvtColor(im2, im2_gray, CV_BGR2GRAY);
// Define the motion model
const int warp_mode = cv::MOTION_AFFINE;
// Set a 2x3 or 3x3 warp matrix depending on the motion model.
cv::Mat warp_matrix;
// Initialize the matrix to identity
if ( warp_mode == cv::MOTION_HOMOGRAPHY )
warp_matrix = cv::Mat::eye(3, 3, CV_32F);
else
warp_matrix = cv::Mat::eye(2, 3, CV_32F);
// Specify the number of iterations.
int number_of_iterations = 50;
// Specify the threshold of the increment
// in the correlation coefficient between two iterations
double termination_eps = 1e-10;
// Define termination criteria
cv::TermCriteria criteria (cv::TermCriteria::COUNT+cv::TermCriteria::EPS, number_of_iterations, termination_eps);
// Run the ECC algorithm. The results are stored in warp_matrix.
findTransformECC(
im1_gray,
im2_gray,
warp_matrix,
warp_mode,
criteria
);
// Storage for warped image.
cv::Mat im2_aligned;
if (warp_mode != cv::MOTION_HOMOGRAPHY)
// Use warpAffine for Translation, Euclidean and Affine
warpAffine(im2, im2_aligned, warp_matrix, im1.size(), cv::INTER_LINEAR + cv::WARP_INVERSE_MAP);
else
// Use warpPerspective for Homography
warpPerspective (im2, im2_aligned, warp_matrix, im1.size(),cv::INTER_LINEAR + cv::WARP_INVERSE_MAP);
UIImage* result = [UIImage imageWithCVMat:im2_aligned];
return result;
我尝试过使用termination_eps 和number_of_iterations 并增加/减少这些值,但它们并没有真正产生很大的不同。
结果如下:
我可以做些什么来改善我的结果?
编辑:我用红色圆圈标记了有问题的边缘。目标是扭曲底部图像并使其与上图中的线条匹配:
我做了一些研究,恐怕findTransformECC 函数不会给我想要的结果:-(
需要补充的重要内容:
实际上,我有一组图像“条纹”,在这种情况下为 8 个,它们看起来都与此处显示的图像相似,并且都需要进行处理以匹配线条。我试过用 OpenCV 的 stitch 函数做实验,但结果很糟糕。
编辑:
以下是 3 张源图片:
结果应该是这样的:
我按照应该匹配的线条转换了每张图片。距离太远的线可以忽略(图片右侧的阴影和路段)
【问题讨论】:
-
您能否向我们展示您希望结果看起来如何的示例?
-
@alhadhrami 当然。我在问题中添加了一些细节。
-
你误解了我的意思。我要求查看正确输出的示例,即您希望通过代码创建的输出。 @gasparuff
-
另外,能否提供两张图片,以便我自己进行测试?
-
嗨@alhadhrami。对不起,我的回复晚了,很多事情正在发生。我今晚会更新我的问题并添加您要求的信息。谢谢
标签: c++ opencv image-processing computer-vision image-stitching