全景缝线无法正常工作

发布于 2025-02-01 19:47:31 字数 2508 浏览 2 评论 0原文

我试图将两个图像缝合在一起,这两个图像都具有不同的角度。如下所示:

如您所见,有一些重叠。但是,当我缝合它们时,我会得到以下内容:

我使用以下算法:

  • SIFT
  • LOWE比率测试
  • 同构型
  • FlannBasedMatcher(RANSAC)
  • 包装透视透视

降低比率测试

        if len(item) < 2:
            continue
        (left, right) = item
        if left.distance < 0.78 * right.distance:
            good.append(left)

同型

# img_feature is an object containing the keypoints where 1 refer to image 1.

src_pts = np.float32([img_feature1.key_points[m.queryIdx].pt for m in good]).reshape(-1, 1, 2) 
    dst_pts = np.float32([img_feature2.key_points[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)

    # Defining the Homography parameters
    homog_method = cv2.RANSAC
    homog_reprojthres = 5
    homog_mask = None
    homog_max_iter = 2000
    homog_confidence = 0.995

    homog_matrix, mask = cv2.findHomography(
        dst_pts,
        src_pts,
        homog_method,
        homog_reprojthres,
        homog_mask,
        homog_max_iter,
        homog_confidence,
    )

    return homog_matrix, mask

flann Matcher

def compute_flann_matcher_sift(des1, des2):
    """Computing the flann matchers"""
    # Defining the FlannMatcher parameters
    flann_index_kdtree = 0
    index_params = dict(algorithm=flann_index_kdtree, trees=5)
    search_params = dict(checks=50)
    # Set up the flannMatcher
    flann = cv2.FlannBasedMatcher(index_params, search_params)

    # Get the matches
    matches = flann.knnMatch(des1, des2, k=2)
    return matches

包裹透视

def blend_image(img1, img2, homog_matrix):
    # Warp the image 2 (right) for image 1 (left)
    dst = cv2.warpPerspective(
        img2, homog_matrix, (img1.shape[1] + img2.shape[1], img1.shape[0])
    )

    # Concatenation
    dst[0 : img1.shape[0], 0 : img1.shape[1]] = img1
    return dst

I am trying to stitch two images together in which both images have different angles. Shown below:
enter image description here
enter image description here

As you can see, there are some overlaps. However, when I stitch them, I get the following:
enter image description here

I use the following algorithm:

  • SIFT
  • Lowe Ratio test
  • Homography
  • FlannBasedMatcher (RANSAC)
  • Wrap Perspective

Lower Ratio Test

        if len(item) < 2:
            continue
        (left, right) = item
        if left.distance < 0.78 * right.distance:
            good.append(left)

Homography

# img_feature is an object containing the keypoints where 1 refer to image 1.

src_pts = np.float32([img_feature1.key_points[m.queryIdx].pt for m in good]).reshape(-1, 1, 2) 
    dst_pts = np.float32([img_feature2.key_points[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)

    # Defining the Homography parameters
    homog_method = cv2.RANSAC
    homog_reprojthres = 5
    homog_mask = None
    homog_max_iter = 2000
    homog_confidence = 0.995

    homog_matrix, mask = cv2.findHomography(
        dst_pts,
        src_pts,
        homog_method,
        homog_reprojthres,
        homog_mask,
        homog_max_iter,
        homog_confidence,
    )

    return homog_matrix, mask

Flann Matcher

def compute_flann_matcher_sift(des1, des2):
    """Computing the flann matchers"""
    # Defining the FlannMatcher parameters
    flann_index_kdtree = 0
    index_params = dict(algorithm=flann_index_kdtree, trees=5)
    search_params = dict(checks=50)
    # Set up the flannMatcher
    flann = cv2.FlannBasedMatcher(index_params, search_params)

    # Get the matches
    matches = flann.knnMatch(des1, des2, k=2)
    return matches

Wrap perspective

def blend_image(img1, img2, homog_matrix):
    # Warp the image 2 (right) for image 1 (left)
    dst = cv2.warpPerspective(
        img2, homog_matrix, (img1.shape[1] + img2.shape[1], img1.shape[0])
    )

    # Concatenation
    dst[0 : img1.shape[0], 0 : img1.shape[1]] = img1
    return dst

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文