Magic Studio Eraser API使用教程

embedded/2024/10/11 11:18:40/
aidu_pl">

AI橡皮擦 - 使用网址

Magic Studio的AI橡皮擦功能非常好用,能去除图片中的杂物。但是网页版只支持低分辨率下载,想要原图就得开会员,价格不菲。

不过官网其实提供了API接入方式,并且有100次的免费试用机会

API接入网站

在这里可以查看AI橡皮擦的接入文档

1、先获取API Token

2、调用Magic Eraser API,传入待处理图片、待擦除部位图片(mask_file)、文件名

关于这个mask_file,官网并没有给出详细介绍,但是通过对网页版AI橡皮擦进行抓包可以发现,mask_file是一个二进制流文件

尝试对这个mask_file流文件进行拦截捕获,使用postman、charles、nginx均未实现,最终解决办法:安装chrome插件 Requestly

Requestly插件下载地址

安装完毕后,在Requestly管理页面,创建一条重定向规则

匹配规则为Equals,并将请求:https://ai-api.magicstudio.com/api/magic-erase

转发到:http://127.0.0.1:8000/saveBinary

http://127.0.0.1:8000/saveBinary 是我本地启动的java服务(下面有提供代码),将页面请求转发到本地,从而捕获mask_file流文件内容,并保存到本地

存到本地后,发现其实就是橡皮擦涂抹区域的图片

这样就拿到了mask_file,接下来就可以调用官方API进行原图无损擦除了。

附完整java代码:

package com.yechen.smm.controller;import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import java.io.File;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;@Slf4j
@CrossOrigin
@RestController
public class AController {/*** 图片地址*/static String pic_path = "C:\\Users\\Administrator\\Pictures\\百丈漈瀑布.jpg";/*** mask地址*/static String mask_path = "D:\\Temp\\mask.jpg";/*** 使用chrome浏览器Requestly插件,创建redirect规则,将:* https://ai-api.magicstudio.com/api/magic-erase* 转发到:* http://127.0.0.1:8000/saveBinary* 即可保存mask文件到本地** @param mask_file* @return* @throws IOException*/@PostMapping("/saveBinary")public String saveBinary(@RequestParam("mask_file") MultipartFile mask_file) throws IOException {FileUtil.writeBytes(mask_file.getBytes(), mask_path);return "ok";}@Testpublic void getToken() {JSONObject param = new JSONObject();param.set("client_id", "xxx");param.set("client_secret", "xxx");param.set("expiry_days", 4);String res = HttpUtil.post("https://api.magicstudio.com/auth/token", param.toString());JSONObject obj = JSONUtil.parseObj(res);String token = obj.getStr("token");res = HttpRequest.post("https://api.magicstudio.com/magiceraser/erase").header("accessToken", token).form("image_file", new File(pic_path)).form("mask_file", new File(mask_path)).form("filename", "filename.jpg").execute().body();System.out.println(res);}}

需要引入lombok、hutool依赖:

<dependency>    <groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version>
</dependency>
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.25</version>
</dependency>

只能说这个magic studio真的太坑爹了,用心做AI,用脚做API,要不是冲着100次的免费额度,真不想折腾这么大劲


http://www.ppmy.cn/embedded/34811.html

相关文章

OpenVoice——强大的语音克隆与生成技术

OpenVoice 是一款由 MyShell TTS 开发的令人惊叹的技术。它只需一小段参考发言者的音频片段&#xff0c;就能精确复制其声音&#xff0c;并能够生成多种语言的语音。 其主要功能包括准确的音色克隆&#xff0c;能够精确地克隆参考音色&#xff0c;并在多种语言和口音中生成语音…

【notes2】并发,IO,内存

文章目录 1.线程/协程/异步&#xff1a;并发对应硬件资源是cpu&#xff0c;线程是操作系统如何利用cpu资源的一种抽象2.并发&#xff1a;cpu&#xff0c;线程2.1 可见性&#xff1a;volatile2.2 原子性&#xff08;读写原子&#xff09;&#xff1a;AtomicInteger/synchronized…

doris be报错:sysctl -w vm.max_map_count=2000000

报错信息 [ERROR] 2024-05-06 16:42:18 TaskLogLogger-DORIS-DorisBE:[197] - [INFO] 2024-05-06 16:42:18 TaskLogLogger-DORIS-DorisBE:[175] - execute shell command : [bash, be/bin/start_be.sh, --daemon] [INFO] 2024-05-06 16:42:18 TaskLogLogger-DORIS-DorisBE:[1…

小土堆pytorch学习

土堆视频链接 1. 两大函数 1.1 dir函数 dir函数返回一个属性列表,其中列表的元素都是字符串格式。 对于模块对象:返回模块的所有属性(变量名和方法) 对于类对象:返回这个类的属性,以及其所有父类(包括父类的父类)的属性 对于其它对象(实例对象):返回这个实例…

2024年5月6日优雅草蜻蜓API大数据服务中心v2.0.3更新

v2.0.3更新 2024年5月6日优雅草蜻蜓API大数据服务中心v2.0.3更新-修复改版后搜索框漏掉的bug-增加搜索框 提示&#xff1a;优雅草大数据中心已经 上线137天 稳定运行 1181555 次 累积调用 目前大数据中心用户呈现增长趋势&#xff0c;目标2024年11月底突破1亿次调用&#xf…

Linux 操作系统线程

目录 一、线程 1.1线程的基本概念 1.2 线程相关的API函数 1.2.1 线程的创建 1.2.2 线程退出 1.2.3 线程等待函数 1.2.4 获取线程ID 1.2.5 线程取消 1.2.6 线程的清理函数 一、线程 1.1线程的基本概念 线程是属于进程&#xff1b;一个进程可以有多个线程&#xff…

前端面试题(二)

面试形式&#xff1a;线上面试&#xff08;不露脸&#xff09;&#xff1a;时长40分钟 面试评价&#xff1a;由易到难&#xff0c;由细到全&#xff0c;比较不错 面试官&#xff1a;项目经理 面试官提问&#xff08;面试题&#xff09;&#xff1a; 1、聊聊最近写的这个项目…

同创优配正规股票港股市场炒股加仓!中国资产,火了

查查配近日,受国内利好政策不断、全球资金对中国市场信心提升等多重因素影响,市场风险偏好明显上升,A股、港股市场均表现强劲,上证指数站上3100点,恒生指数也上演九连阳,创下2018年以来的最长连涨纪录。从资金动向来看,机构加仓明显,北向资金持续净买入,A股ETF也被大幅加仓,部分…