【问题标题】:warpPerspective overlapping one image over another on the backgroundwarpPerspective 在背景上将一个图像重叠在另一个图像上
【发布时间】:2021-12-01 05:30:56
【问题描述】:

所以我想以全景样式拼接两张图像。所以这是我的计划:

  1. 创建一个宽度是 image1 两倍的白色图像(即:color = 255, 255, 255)
  2. 将 img1 复制到此结果图像的左上角,这意味着像素坐标的恒等变换
  3. 将 img2 复制到结果图像,方法是使用估计的单应性(将 dst_pts 映射到 src_pts)的逆进行扭曲

但是,最终结果不仅将背景设置为黑色,而且将第二张图片重叠在第一张上面。我做错了什么?

代码如下

def panorama(img1, img2, H, size):
   I = np.linalg.inv(H)
   img = np.zeros(size,dtype=np.uint8)
   img.fill(255)
   img = cv2.warpPerspective(img1, np.identity(3), size, img, borderMode=cv2.BORDER_TRANSPARENT)
   img = cv2.warpPerspective(img2, I, size, img, flags=cv2.WARP_INVERSE_MAP+cv2.INTER_LINEAR, borderMode=cv2.BORDER_TRANSPARENT)
   return img

size = (2 * image1.shape[0],image1.shape[1])
cv2.imshow([panorama(image1, image2, H, size)],["Panorama"])

【问题讨论】:

  • 变形到第三张图像并将所有非黑色像素复制到目标图像。变形中不包含混合,因此您需要额外的步骤。
  • 最后一行的H 是什么?最好分享结果以查看问题所在

标签: python opencv image-processing


【解决方案1】:

我实际上是通过在 warpPerspective 中使用原始单应性 (H) 而不是逆 (I) 来解决它

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多