zoukankan      html  css  js  c++  java
  • opencv实现无缝融合--seamless clone

    先看效果图:

     

     

     

    要求: opencv

    再看python代码实现: 

    import cv2
    import numpy as np
    from math import sqrt
    
    folder = 'ball_merge/'
    # Read images : src image will be cloned into dst
    im = cv2.imread(folder + "backdrop.jpg")
    obj = cv2.imread(folder + "char.jpg")
    # Create an all white mask
    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)
    
    # Write results
    cv2.imwrite(folder + "normal_merge.jpg", normal_clone)
    cv2.imwrite(folder + "fluid_merge.jpg", mixed_clone)

    自己修改对应的路径。这个代码实现的主要函数是cv2.seamlessClone(),这个函数可以根据梯度来调节风格,使得拼接的图像部分不至于那么突兀。对于cv2.seamlessClone(obj, im, mask, center, cv2.NORMAL_CLONE)来讲:

    obj代表的是子图,由cv2读进来的数组文件;

    im代表的是母图,也是由cv2都进来的数组文件;

    mask代表掩模,因为你并不需要把子图所有的部分都贴进来,所以可以用mask划分出一个兴趣域。只需要用0和255区分就可以。如果你不想管这个mask,直接都设置成255就行了;

    center表示坐标,你打算在母图的哪个位置放子图。这里是放在中间。

    cv2.NORMAL_CLONE代表融合的模式,可以比较 cv2.NORMAL_CLONE和cv2.MIXED_CLONE的差别。、


    原文链接:https://blog.csdn.net/leviopku/article/details/83658767

  • 相关阅读:
    KVC KVO
    Objective-C的hook方案(一): Method Swizzling
    Method Swizzle黑魔法,修改 ios 系统类库方法 SEL IMP
    http 请求安全
    块对象block小结(2)
    块对象block小结
    springmvc项目目录总结
    软件开发实用标准流程——文档
    冷知识:反常识的margin-top与padding-top与%,你被坑过吗?
    菜鸟笔记:在公司内网下搭好Java项目环境(IDEA、maven、svn)
  • 原文地址:https://www.cnblogs.com/Ph-one/p/12090127.html
Copyright © 2011-2022 走看看