MacM2+MacOS13.3配置rembg
rembg是一個(gè)可以幫助摳圖的腳本,不一定要指定前景圖。
于是我突發(fā)奇想想配置在自己的Macmini M2上,來幫助我批量處理角色繪畫
Step1. 安裝anaconda
首先,需要配置anaconda的環(huán)境
訪問anaconda官網(wǎng)https://www.anaconda.com/

點(diǎn)擊右邊的按下拉按鈕(直接選Download for Mac(M1/M2)也可以 )。拉到最下方可以看見一排鏈接


我選擇安裝在這里

安裝成功,打開Anaconda Navigator,看到界面

命令行查看conda的版本(此時(shí)已經(jīng)activate了base環(huán)境,可以看到命令行左邊有個(gè)(base))

項(xiàng)目原地址為:
https://github.com/danielgatis/rembg
git clone https://ghproxy.com/https://github.com/danielgatis/rembg
我把下載的目錄拖到桌面,命名為rembg
cd rembg
然后用conda建立一個(gè)虛擬環(huán)境,命名為rembg
conda create -n rembg python=3.11 -y
然后輸入
conda activate rembg

pip install 'rembg[cli]'
這里要加上這個(gè)引號(hào),否則提示rembg[cli]不存在
等待安裝,提示所有的依賴安裝成功
Installing collected packages: pytz, pydub, mpmath, flatbuffers, filetype, ffmpy, websockets, watchdog, urllib3, uc-micro-py, tzdata, typing-extensions, tqdm, toolz, sympy, sniffio, six, semantic-version, rpds-py, pyyaml, python-multipart, pyparsing, protobuf, platformdirs, pillow, packaging, orjson, numpy, networkx, multidict, mdurl, markupsafe, llvmlite, lazy_loader, kiwisolver, idna, humanfriendly, h11, fsspec, frozenlist, fonttools, filelock, cycler, click, charset-normalizer, certifi, attrs, async-timeout, annotated-types, aiofiles, yarl, uvicorn, tifffile, scipy, requests, referencing, PyWavelets, python-dateutil, pydantic-core, opencv-python-headless, numba, markdown-it-py, linkify-it-py, jinja2, imageio, contourpy, coloredlogs, anyio, aiosignal, starlette, scikit-image, pymatting, pydantic, pooch, pandas, onnxruntime, mdit-py-plugins, matplotlib, jsonschema-specifications, huggingface-hub, httpcore, asyncer, aiohttp, rembg, jsonschema, httpx, fastapi, gradio-client, altair, gradio
Successfully installed PyWavelets-1.4.1 aiofiles-23.1.0 aiohttp-3.8.5 aiosignal-1.3.1 altair-5.0.1 annotated-types-0.5.0 anyio-3.7.1 async-timeout-4.0.2 asyncer-0.0.2 attrs-23.1.0 certifi-2023.7.22 charset-normalizer-3.2.0 click-8.1.6 coloredlogs-15.0.1 contourpy-1.1.0 cycler-0.11.0 fastapi-0.100.1 ffmpy-0.3.1 filelock-3.12.2 filetype-1.2.0 flatbuffers-23.5.26 fonttools-4.41.1 frozenlist-1.4.0 fsspec-2023.6.0 gradio-3.39.0 gradio-client-0.3.0 h11-0.14.0 httpcore-0.17.3 httpx-0.24.1 huggingface-hub-0.16.4 humanfriendly-10.0 idna-3.4 imageio-2.31.1 jinja2-3.1.2 jsonschema-4.18.4 jsonschema-specifications-2023.7.1 kiwisolver-1.4.4 lazy_loader-0.3 linkify-it-py-2.0.2 llvmlite-0.40.1 markdown-it-py-2.2.0 markupsafe-2.1.3 matplotlib-3.7.2 mdit-py-plugins-0.3.3 mdurl-0.1.2 mpmath-1.3.0 multidict-6.0.4 networkx-3.1 numba-0.57.1 numpy-1.24.4 onnxruntime-1.15.1 opencv-python-headless-4.8.0.74 orjson-3.9.2 packaging-23.1 pandas-2.0.3 pillow-10.0.0 platformdirs-3.9.1 pooch-1.7.0 protobuf-4.23.4 pydantic-2.1.1 pydantic-core-2.4.0 pydub-0.25.1 pymatting-1.1.8 pyparsing-3.0.9 python-dateutil-2.8.2 python-multipart-0.0.6 pytz-2023.3 pyyaml-6.0.1 referencing-0.30.0 rembg-2.0.50 requests-2.31.0 rpds-py-0.9.2 scikit-image-0.21.0 scipy-1.11.1 semantic-version-2.10.0 six-1.16.0 sniffio-1.3.0 starlette-0.27.0 sympy-1.12 tifffile-2023.7.18 toolz-0.12.0 tqdm-4.65.0 typing-extensions-4.7.1 tzdata-2023.3 uc-micro-py-1.0.2 urllib3-2.0.4 uvicorn-0.23.1 watchdog-3.0.0 websockets-11.0.3 yarl-1.9.2

ls -la


刪背景
rembg i 原圖路徑 輸出路徑rembg p 原圖文件夾路徑 輸出文件夾路徑
去除多圖片背景
去除背景單一圖片背景
刪除僅返回蒙版的背景
rembg i -om path/to/input.png path/to/output.png

原圖:


輸出:

