有人知道如何借助任何软件包从图像中删除背景吗?
我尝试使用remove.bg包,但它似乎是一项付费服务。
是的,https://www.remove-background.ai是唯一允许免费API查询的API。
然而,每月最多可免费删除 60 次,与其他竞争对手相比,它仍然是一个很棒的优惠,它的订阅价格也非常便宜,每月每 100 次删除只需 1 美元起。 您还可以获得无限制的访问权限。
npm i --save @remove-background-ai/rembg.js
然后创建index.mjs:
import { rembg } from '@remove-background-ai/rembg.js';
import dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();
// API_KEY will be loaded from the .env file
const API_KEY = process.env.API_KEY;
// log upload and download progress
const onDownloadProgress = console.log;
const onUploadProgress = console.log;
rembg({
apiKey: API_KEY,
inputImagePath: './input.png',
onDownloadProgress,
onUploadProgress
}).then(({ outputImagePath, cleanup }) => {
console.log('path', outputImagePath);
// if called, it will cleanup (delete from disk) your removed background image
// cleanup();
});
如果您想显示上传/下载进度条,您可以创建自己的 onDownloadProgress 和 onUploadProgress 回调。 两个回调都接受 AxiosProgressEvent 作为事件参数,在我的测试中,我能够删除背景,这是输出:
您可以查看rembg。虽然它可以在 python 中运行 https://github.com/danielgatis/rembg