【问题标题】:iOS & OpenCV: Image Registration / AlignmentiOS & OpenCV:图像配准/对齐
【发布时间】:2014-01-02 06:51:36
【问题描述】:

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

我已经导入了 OpenCV 框架,并且一直在探索 OpenCV 中用于对齐/注册图像的功能,但一无所获。 OpenCV中实际上有一个功能可以实现这一点吗?如果没有,还有其他选择吗?

谢谢!

【问题讨论】:

    标签: ios image opencv alignment registration


    【解决方案1】:

    没有像 align 这样的单一函数,您需要自己做/实现它,或者找到一个已经实现的。

    这是一个单一的解决方案。

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

    记住这个答案很肤浅,首先你需要对关键点/描述符提取和关键点/描述符匹配做一些研究。

    祝你好运!

    【讨论】:

    • 嗨@yonasstephen!你有没有找到任何解决方案?
    【解决方案2】:

    在 OpenCV 3.0 中,您可以使用 findTransformECC。我从LearnOpenCV.com 复制了这个ECC Image Alignment 代码,其中解决了对齐颜色通道的非常相似的问题。这篇文章还包含 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);
    

    【讨论】:

      猜你喜欢
      • 2012-12-03
      • 2013-12-06
      • 2020-04-30
      • 2019-11-09
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多