跳到主要内容

📸 图片背景移除器

1 IC每次请求
✅ 活跃🏙️ 智慧城市

图片背景移除器是一项 AI 服务,用于移除任何照片、自拍照的背景,尤其适用于证件照和头像更换。

免费试用!

Example Images (Click to try)

Example 1

入门指南

  1. 先决条件

    • 来自 iApp Technology 的 API 密钥
    • 任何类型的照片、自拍照,尤其适用于证件照
    • 支持的文件格式:JPEG、JPG、PNG
    • 最大文件大小:2MB
  2. 快速开始

    • 快速处理
    • 高精度
  3. 主要功能

    • 移除自拍照背景
    • 适用于证件照和头像更换
    • 旋转为横向模式
    • 便于移动应用程序实现。
  4. 安全与合规

    • 符合 GDPR 和 PDPA 标准
    • 处理后不保留数据
如何获取 API 密钥?

请访问 API 密钥管理 页面查看您现有的 API 密钥或申请新密钥。

API 端点

端点方法描述费用
/v3/store/smart-city/remove-background
旧版: /face-extractor
POST移除照片背景每请求 1 IC
旧版: /remove-bgPOST旧版背景移除端点每请求 1 IC

示例

请求

curl --location 'https://api.iapp.co.th/face-extractor/predict/file' \
--header 'apikey: {您的 API 密钥}' \
--form 'file=@"/Users/iapp/Downloads/2 (3).png"' \
--form 'rotateIfPortiat="True"'

API 参考

端点

POST https://api.iapp.co.th/face-extractor/predict/file

请求头

名称类型描述
apikeyStringiApp AI 的 API 密钥

请求体

名称类型描述
rotateIfPortiatBoolean如果此参数设置为“true”且图像为纵向,则输出将旋转为横向模式。便于移动应用程序实现。
filefile.PNG 或 .JPEG 或 .JPG 图像文件

代码示例

Python

import requests

url = "https://api.iapp.co.th/face-extractor/predict/file"

payload = {}
files=[
('file',('{您的上传文件名}',open('{您的上传文件路径}','rb'),'image/png'))
]
headers = {
'apikey': '{您的 API 密钥}'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

JavaScript

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
let data = new FormData();
data.append('file', fs.createReadStream('{您的上传文件路径}'));

let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.iapp.co.th/face-extractor/predict/file',
headers: {
'apikey': '{您的 API 密钥}',
...data.getHeaders()
},
data : data
};

axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.iapp.co.th/face-extractor/predict/file',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('file'=> new CURLFILE('{您的上传文件路径}')),
CURLOPT_HTTPHEADER => array(
'apikey: {您的 API 密钥}'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Swift

let parameters = [
[
"key": "file",
"src": "{您的上传文件路径}",
"type": "file"
]] as [[String: Any]]

let boundary = "Boundary-\(UUID().uuidString)"
var body = Data()
var error: Error? = nil
for param in parameters {
if param["disabled"] != nil { continue }
let paramName = param["key"]!
body += Data("--\(boundary)\r\n".utf8)
body += Data("Content-Disposition:form-data; name=\"\(paramName)\"".utf8)
if param["contentType"] != nil {
body += Data("\r\nContent-Type: \(param["contentType"] as! String)".utf8)
}
let paramType = param["type"] as! String
if paramType == "text" {
let paramValue = param["value"] as! String
body += Data("\r\n\r\n\(paramValue)\r\n".utf8)
} else {
let paramSrc = param["src"] as! String
let fileURL = URL(fileURLWithPath: paramSrc)
if let fileContent = try? Data(contentsOf: fileURL) {
body += Data("; filename=\"\(paramSrc)\"\r\n".utf8)
body += Data("Content-Type: \"content-type header\"\r\n".utf8)
body += Data("\r\n".utf8)
body += fileContent
body += Data("\r\n".utf8)
}
}
}
body += Data("--\(boundary)--\r\n".utf8);
let postData = body

var request = URLRequest(url: URL(string: "https://api.iapp.co.th/face-extractor/predict/file")!,timeoutInterval: Double.infinity)
request.addValue("{您的 API 密钥}", forHTTPHeaderField: "apikey")
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

request.httpMethod = "POST"
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}

task.resume()

Kotlin

val client = OkHttpClient()
val mediaType = "text/plain".toMediaType()
val body = MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file","{您的上传文件名}",
File("{您的上传文件路径}").asRequestBody("application/octet-stream".toMediaType()))
.build()
val request = Request.Builder()
.url("https://api.iapp.co.th/face-extractor/predict/file")
.post(body)
.addHeader("apikey", "{您的 API 密钥}")
.build()
val response = client.newCall(request).execute()

Java

OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file","{您的上传文件名}",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("{您的上传文件路径}")))
.build();
Request request = new Request.Builder()
.url("https://api.iapp.co.th/face-extractor/predict/file")
.method("POST", body)
.addHeader("apikey", "{您的 API 密钥}")
.build();
Response response = client.newCall(request).execute();

Dart

var headers = {
'apikey': '{您的 API 密钥}'
};
var request = http.MultipartRequest('POST', Uri.parse('https://api.iapp.co.th/face-extractor/predict/file'));
request.files.add(await http.MultipartFile.fromPath('file', '{您的上传文件路径}'));
request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}

代码示例

Curl

curl -X POST https://api.iapp.co.th/v3/store/smart-city/remove-background \
-H "apikey: 您的 API 密钥" \
-F "file=@/path/to/image.jpg"

Python

import requests

url = "https://api.iapp.co.th/v3/store/smart-city/remove-background"
files = {"file": ("("/path/to/image.jpg", "rb"))}
headers = {"apikey": "您的 API 密钥"}

response = requests.post(url, headers=headers, files=files)
print(response.json())

JavaScript

const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");

let data = new FormData();
data.append("file", fs.createReadStream("/path/to/image.jpg"));

let config = {
method: "post",
url: "https://api.iapp.co.th/v3/store/smart-city/remove-background",
headers: {
apikey: "您的 API 密钥",
...data.getHeaders(),
},
data: data,
};

axios(config)
.then((response) => console.log(response.data))
.catch((error) => console.log(error));

PHP

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.iapp.co.th/v3/store/smart-city/remove-background',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array(
'file'=> new CURLFILE('/path/to/image.jpg')
),
CURLOPT_HTTPHEADER => array(
'apikey: 您的 API 密钥'
),
));

$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>

Swift

import Foundation

let url = URL(string: "https://api.iapp.co.th/v3/store/smart-city/remove-background")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("您的 API 密钥", forHTTPHeaderField: "apikey")

let boundary = "Boundary-\(UUID().uuidString)"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var body = Data()
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"file\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: image/jpeg\r\n\r\n".data(using: .utf8)!)

if let fileData = try? Data(contentsOf: URL(fileURLWithPath: "/path/to/image.jpg")) {
body.append(fileData)
}
body.append("\r\n--\(boundary)--\r\n".data(using: .utf8)!)

request.httpBody = body

let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
print(String(data: data, encoding: .utf8)!)
}
}
task.resume()

Kotlin

import okhttp3.*
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File

val client = OkHttpClient()

val file = File("/path/to/image.jpg")
val requestBody = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", file.name, file.asRequestBody("image/jpeg".toMediaTypeOrNull()))
.build()

val request = Request.Builder()
.url("https://api.iapp.co.th/v3/store/smart-city/remove-background")
.addHeader("apikey", "您的 API 密钥")
.post(requestBody)
.build()

client.newCall(request).execute().use { response ->
println(response.body?.string())
}

Java

import okhttp3.*;
import java.io.File;

OkHttpClient client = new OkHttpClient();

File file = new File("/path/to/image.jpg");

RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", file.getName(),
RequestBody.create(MediaType.parse("image/jpeg"), file))
.build();

Request request = new Request.Builder()
.url("https://api.iapp.co.th/v3/store/smart-city/remove-background")
.addHeader("apikey", "您的 API 密钥")
.post(requestBody)
.build();

try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}

Dart

import 'package:http/http.dart' as http;

var request = http.MultipartRequest(
'POST',
Uri.parse('https://api.iapp.co.th/v3/store/smart-city/remove-background')
);

request.files.add(await http.MultipartFile.fromPath(
'file',
'/path/to/image.jpg'
));

request.headers.addAll({
'apikey': '您的 API 密钥'
});

var response = await request.send();
var responseBody = await response.stream.bytesToString();
print(responseBody);

定价

AI API 服务名称端点每分钟 IC本地部署
TRemove Background AI on Selfie Photo for Photo IDremove_background_v11 IC/请求联系我们