gas*_*uff 14 c++ opencv image-processing computer-vision image-stitching
我是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;
Run Code Online (Sandbox Code Playgroud)
我试图玩弄的termination_eps和number_of_iterations和增加/减少的值,但他们并没有真正有很大的不同.
所以这是结果:
我该怎么做才能改善我的结果?
编辑:我用红色圆圈标记了有问题的边缘.目标是扭曲底部图像并使其与上图中的线条匹配:
我做了一些研究,我担心这个findTransformECC功能不会给我我想要的结果:-(
一些重要的事情要添加:我实际上有一些图像"条纹",在这种情况下,它们看起来与这里显示的图像类似,它们都需要处理以匹配线条.我尝试过试验stitchOpenCV 的功能,但结果太可怕了.
编辑:
以下是3个源图像:
结果应该是这样的:
我沿着应该匹配的线条转换了每个图像.可以忽略彼此相距太远的线(阴影和图像右侧部分的道路)
小智 5
通过您的图像,它们似乎重叠.既然你说这个stitch功能没有得到你想要的结果,那就实现你自己的拼接.我也想尝试接近这一点.这是一个如何在c ++中实现它的教程:https://psmsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/