有人知道如何借助任何软件包从图像中删除背景吗?
我尝试使用remove.bg包,但它似乎是一项付费服务。
最佳答案
Disclaimer, I'm the author of rembg.js.
是的,https://www.remove-background.ai是唯一允许免费API查询的API。
不过,每月最多可以免费删除 60 次,与其他竞争对手相比,它仍然是一个不错的选择,因为他们甚至不允许通过 API 免费删除背景。 如果你看一下定价,它实际上是非常便宜的订阅,每 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 作为事件参数,在我的测试中,我能够删除背景,这是输出:
关于node.js - 有没有用于从图像中删除背景的 npm 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75628409/