如何在 python 中使用 OpenCV 拼接多张随机顺序的图像?

How to stitch multiple images that are in a random order using OpenCV in python?

在 python 中使用 OpenCV,我试图拼接多张乱序的图像。我有一个功能性的拼接方法,可以拼接两张图片,给定哪一张在左边和右边。

    def stitch(self, images, ratio=0.75, reprojThresh=4.0, 
    showMatches=False):

    """
    This function performs image stitching with help of other member functions of Stitcher class.
    Args:
        images          (list)  :   List of two images ordered left to right 
        ratio           (float) :   Ratio for Lowe's Test
        reprojThresh    (float) :   reprojThresh parameter for RANSAC for homography computation
        showMatches     (bool)  :   Flag for marking showing matches on input images
    """

    (imageL, imageR) = images

    #Find key points and features for input images
    (kpsR, featuresR) = self.find_kp_features(imageR)
    (kpsL, featuresL) = self.find_kp_features(imageL)

    # Match features between two input images
    M = self.matchKeypoints(kpsR, kpsL, featuresR, featuresL, ratio, reprojThresh)

    if M is None:
        return None


    (matches, H, status) = M
    #Perform perspective correction on second image (imageR)
    result = cv2.warpPerspective(imageR, H, (imageR.shape[1] + imageL.shape[1], imageR.shape[0]))

    #Insert Left image (imageL) in result to obtai stitched image
    result[0:imageL.shape[0], 0:imageL.shape[1]] = imageL

    if showMatches:
        vis = self.drawMatches(imageR, imageL, kpsR, kpsL, matches,
            status)

        return (result, vis)

    return result

来源:https://github.com/TejasBob/Panorama/blob/master/image-stitching-report.pdf

我已经通读了以下 paper,但我仍然对以 随机顺序 拼接多张图像的方法感到困惑。我考虑过使用束调整算法,但不知道可能的实现方式。

我的问题是,将多张无序图像拼接在一起的最佳方法是什么?一些合适的 material 或我能做的伪代码也会有所帮助。

对于可以随机顺序拼接的多张图片,您可以尝试以下操作:

1)在一张图片中找到特征

2) 尝试匹配所有图像中的那些特征

3) 与初始图像最大匹配的图像 select 并执行拼接

4) 现在你有一个新的拼接图像,你可以在其中添加特征并在其他帧中再次匹配它们等等。

这会很费时间,但可以考虑这方面的东西。