Sato抠图API
Intelligently detects foreground subjects in images and identifies contours to achieve refined background segmentation and cutout, and cut out portraits, products, animals, stamps, etc. with one click. Call Zuotang API to integrate the AI cutout function into your website, applications, and software, and easily have pixel-level cutout services!
1. First look at the comparison of the two pictures.
2. Zuotang’s website contains not only the image cutout API but also other
https://picwish.cn/background-removal-api-doc
3. Without further ado, let’s go directly to the cutout code.
Just replace MattingKEY with your own
public class Faseapi : MonoBehaviour
{
public string MattingURL = "https://techsz.aoscdn.com/api/tasks/visual/segmentation";
public string MattingKEY = "wx1kcjxudkn4918**";
public string videoFilePath;
// Start is called before the first frame update
void Start()
{
videoFilePath = Application.streamingAssetsPath + "/savedImage.png";
StartCoroutine(StartGetMatting());
}
// Update is called once per frame
void Update()
{
} /// <summary>
/// 加载抠图api
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
IEnumerator StartGetMatting()
{
WWWForm _form = new WWWForm();
//_form.AddField("X-API-KEY", MattingKEY);
byte[] videoData = File.ReadAllBytes(videoFilePath);
_form.AddBinaryData("image_file", videoData);
_form.AddField("type", "person");
_form.AddField("return_type", 2);
_form.AddField("output_type", 2);
_form.AddField("crop", 0);
_form.AddField("sync", 1);
UnityWebRequest webRequest = UnityWebRequest.Post(MattingURL, _form);
webRequest.SetRequestHeader("X-API-KEY", MattingKEY);
//string _time = ShowTime();
yield return webRequest.SendWebRequest();
if (!string.IsNullOrEmpty(webRequest.error))
{
print("服务器获取出错" + webRequest.error.ToString());
//yield return new WaitForSeconds(4f); 4秒后重新连接
}
else
{
string data = webRequest.downloadHandler.text;
Debug.Log(data);
JsonData Mapper = JsonMapper.ToObject(data);
if (Mapper["status"].ToString() == "200")
{
//JsonData data_ = JsonMapper.ToObject(Mapper["data"].ToString());
//Debug.Log(int.Parse(Mapper["data"]["state"].ToString()));
if (int.Parse(Mapper["data"]["state"].ToString()) == 1)
{
Debug.Log(Mapper["data"]["image"].ToString());
byte[] buffers = Convert.FromBase64String(Mapper["data"]["image"].ToString());
//imagee = Base64ToTexture2D(Mapper["data"]["image"].ToString());
File.WriteAllBytes(Application.streamingAssetsPath + "/1.png", buffers);
}
}
}
}
Thank you all for watching, your likes and attention are my biggest motivation
Knowledge points and useful information will be updated from time to time~