Python图片拼接(121张拼接成1张)

来源:互联网 发布:三星指纹锁软件 编辑:程序博客网 时间:2024/05/03 20:56

原始代码:https://github.com/dby/photo_joint

需要:

  1. Python基本语法
  2. PIL第三方库
  3. Numexpr库
  4. 图像处理相关知识
原图与需要的拼接图。


需要的背景素材图213张(任意张)

第一点:Windows下的Python  32位,读取11X11图片(121张图片),再增大图片数会报MemoryError

第二点:原始代码有漏洞,拼接结果会有黑缝隙。原因是 重置照片的大小出了问题,需要修改代码。




# name: transfer
# todo: 将照片转为一样的大小
def transfer(img_path, dst_width,dst_height):
    STA = time.time()
    im = Image.open(img_path)   
    print im.size, 
    
    if im.mode != "RGBA":
        im = im.convert("RGBA")     
    s_w,s_h = im.size
    if s_w < s_h:
        im = im.rotate(90)  修改为  im=im.transpose(Image.ROTATE_90) 

修改代码后:没有了黑缝隙





第三,使用Linux下 python 64位可以读取20x20图片数量(合成图片9.18 MB ),或更多的图片(没有进一步测试)




执行过程






0 0