• python:用backgroundRemover+imageMagick给人像照片更换背景色


    一,安装工具:

    1,安装backgroundremover:
    参考:
    https://www.cnblogs.com/architectforest/p/16790772.html
    2,安装imageMagick:
    参考:
    https://www.cnblogs.com/architectforest/p/12807514.html

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/
             或: https://gitee.com/liuhongdi

    说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,更换背景色:

    1,第一步:抠图,生成透明背景的png图片
    [lhdop@blog img2]$ backgroundremover -i "/home/lhdop/img2/a.jpeg" -o "/home/lhdop/img2/b.png"
    /home/lhdop/img2/b.png
    2,第二步:更换背景
    [lhdop@blog img2]$ convert b.png -background "#ff0000" -flatten red.png
    3,查看效果:
    原图:
    抠图为透明背景后:
    改为红色背景后:

    三,查看backgroundremover和imagemagick的版本:

    查看backgroundremover的版本:
    [lhdop@blog ~]$ pip3 show backgroundremover
    Name: backgroundremover
    Version: 0.1.9
    Summary: Background remover from image and video
    Home-page: https://github.com/nadermx/backgroundremover
    Author: Johnathan Nader
    Author-email: john@nader.mx
    License: UNKNOWN
    Location: /home/lhdop/.local/lib/python3.6/site-packages
    Requires: certifi, charset-normalizer, ffmpeg-python, filelock, filetype, gdown, hsh, idna, more-itertools, moviepy,
    numpy, Pillow, pymatting, PySocks, requests, scikit-image, scipy, six, torch, torchvision, tqdm, urllib3, waitress
    Required-by:
    查看ImageMagick的版本
    [lhdop@blog img]$ convert -version
    Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13 https://imagemagick.org
    Copyright: © 1999-2020 ImageMagick Studio LLC
    License: https://imagemagick.org/script/license.php
    Features: Cipher DPC Modules OpenMP(4.5)
    Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib gvc jbig jng jp2
    jpeg lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib 
  • 相关阅读:
    计蒜客练习题:互质数个数
    求欧拉函数
    欧拉函数和积性函数
    计蒜客练习题:素数距离
    计蒜客练习题:蒜头君的猜想(哥德巴赫猜想)
    素数打表——找出1~100以内的素数
    质数筛选——素数筛选法
    计蒜客练习题:取石子游戏
    计蒜客练习题:两仪剑法
    整除和取余
  • 原文地址:https://www.cnblogs.com/architectforest/p/16791891.html
Copyright © 2020-2023  润新知