图像叠加cv2.seamlessClone

opencv python用一个函数将两个图像进行叠加:cv2.seamlessClone

im = cv2.imread('E:/bglearn/pic/90.jpg')
    obj = cv2.imread('E:/bglearn/pic/90.jpg')

    mask = 255 * np.ones(obj.shape, obj.dtype)

    # The location of the center of the src in the dst
    width, height, channels = im.shape
    center = (height // 2, width // 2)

    # Seamlessly clone src into dst and put the results in output
    normal_clone = cv2.seamlessClone(obj, im, mask, center, cv2.NORMAL_CLONE)
    mixed_clone = cv2.seamlessClone(obj, im, mask, center, cv2.MIXED_CLONE)


    # Clone seamlessly.


    # 保存结果
    cv_show('normal_clone',normal_clone)
    #cv_show('mixed_clone',mixed_clone)
    new_bottle = cv2.absdiff(im, normal_clone)
    # cv_show('new_bottle', new_bottle)
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (15, 15))
    new_bottle_gray = cv2.cvtColor(new_bottle, cv2.COLOR_BGR2GRAY)
    new_bottle_thresh = cv2.threshold(new_bottle_gray, 10, 255, cv2.THRESH_BINARY)[1]
    # 得到新瓶子的mask图
    new_bottle_mask = cv2.morphologyEx(new_bottle_thresh, cv2.MORPH_CLOSE, kernel)
    # cv_show('new_bottle_mask', new_bottle_mask)
    _, new_bottle_mask_contours, _ = cv2.findContours(new_bottle_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cv2.drawContours(normal_clone, new_bottle_mask_contours, -1,
                         (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)), 2)

    cv_show('normal_clone',normal_clone)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值