iOS和OpenCV:图像注册/对齐

我正在做一个在iOS中组合类似于HDR的多个图像的项目。 我已经设法通过相机获得3张不同曝光的图像,现在我想对齐它们,因为在拍摄过程中,一只手必须动摇并导致所有3张图像的对齐略有不同。

我已经导入了OpenCV框架,我一直在探索OpenCV中的函数来对齐/注册图像,但一无所获。 在OpenCV中实际上有一个function来实现这一目标吗? 如果没有,还有其他选择吗?

谢谢!

没有一个叫做对齐的函数,你需要自己做/实现它,或找到已经实现的函数。

这是一个解决方案。

您需要从所有3个图像中提取关键点并尝试匹配它们。 确保您的关键点提取技术对于光照变化是不变的,因为由于曝光不同,所有这些技术都具有不同的强度值。 您需要匹配您的关键点并找出一些差异。 然后,您可以使用差异来对齐图像。

请记住,这个答案是如此肤浅,首先,您需要对关键点/描述符提取和关键点/描述符匹配进行一些研究。

祝你好运!

在OpenCV 3.0中,您可以使用findTransformECC 。 我已经从LearnOpenCV.com复制了这个ECC图像对齐代码,其中解决了一个非常类似的问题,用于对齐颜色通道。 该post还包含Python中的代码。 希望这可以帮助。

// Read the images to be aligned Mat im1 = imread("images/image1.jpg"); Mat im2 = imread("images/image2.jpg"); // Convert images to gray scale; 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 = MOTION_EUCLIDEAN; // Set a 2x3 or 3x3 warp matrix depending on the motion model. Mat warp_matrix; // Initialize the matrix to identity if ( warp_mode == MOTION_HOMOGRAPHY ) warp_matrix = Mat::eye(3, 3, CV_32F); else warp_matrix = Mat::eye(2, 3, CV_32F); // Specify the number of iterations. int number_of_iterations = 5000; // Specify the threshold of the increment // in the correlation coefficient between two iterations double termination_eps = 1e-10; // Define termination criteria TermCriteria criteria (TermCriteria::COUNT+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. Mat im2_aligned; if (warp_mode != MOTION_HOMOGRAPHY) // Use warpAffine for Translation, Euclidean and Affine warpAffine(im2, im2_aligned, warp_matrix, im1.size(), INTER_LINEAR + WARP_INVERSE_MAP); else // Use warpPerspective for Homography warpPerspective (im2, im2_aligned, warp_matrix, im1.size(),INTER_LINEAR + WARP_INVERSE_MAP); // Show final result imshow("Image 1", im1); imshow("Image 2", im2); imshow("Image 2 Aligned", im2_aligned); waitKey(0);