图像画质修复V2
描述
本接口用于云端处理画质修复请求。
图片要求
- 支持 JPG、PNG 格式。
- 图片像素尺寸最小为 48×48,最大为 4096×4096。
- 图片文件大小不超过 2 MB。
- 系统能够检测到的人脸框为正方形,边长最小值为图像短边长度的 1/48,且不低于 48 像素。例如,图片为 4096×3200 像素时,最小人脸像素尺寸为 66×66 像素。
调用 URL
正式环境:https://openapi.meitu.com
任务提交接口:https://openapi.meitu.com/api/v1/sdk/sync/push
任务名称(task):/v1/High_Definition_V2/466662
任务类型(task_type):formula调用方法
POST
Content-Type: application/json
权限
请求参数
请求体恰好包含以下五个顶层字段:
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | params | string | 推理参数;值为序列化后的 JSON 字符串,而不是 JSON 对象 |
| 必选 | init_images | object[] | 图片文件列表;本接口传入一张待修复原图 |
| 必选 | task | string | 固定 /v1/High_Definition_V2/466662 |
| 必选 | task_type | string | 固定 formula |
| 可选 | sync_timeout | int | 默认 30;-1 表示不等待。同步等待超时后返回状态 9,需使用查询接口获取结果 |
init_images 图片参数,结构说明如下
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | url | string | 图片 URL 或 base64 |
| 可选 | profile | object | 多媒体参数 |
profile 多媒体参数,结构说明如下
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 可选 | media_extra | object | 多媒体附加参数;源文未进一步定义其内部字段 |
| 可选 | media_profiles | object | 多媒体描述 |
| 可选 | version | string | 源文请求示例中传 v1 |
media_profiles 多媒体描述,结构说明如下
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 可选 | media_data_type | string | url 表示多媒体文件以 URL 形式传输;jpg 表示多媒体文件以 JPG base64 编码传输 |
params 推理参数是 JSON 字符串,其反序列化后的结构说明如下
| 是否必选 | 字段 | 类型 | 说明 |
|---|---|---|---|
| 可选 | rsp_media_type | string | 公共返回媒体类型,位于 parameter 同级;默认 url。jpg 表示结果图像以 base64 编码返回,url 表示结果图像以 URL 返回 |
| 必选 | parameter | object | 算法参数对象;源文未定义本接口的其他算法参数,传空对象 {} |
输入值示例
{
"task": "/v1/High_Definition_V2/466662",
"task_type": "formula",
"init_images": [
{
"url": "https://example.com/input.jpg",
"profile": {
"media_profiles": {"media_data_type": "url"},
"version": "v1"
}
}
],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{}}",
"sync_timeout": 30
}返回值说明
统一网关返回结构如下:
| 字段 | 类型 | 说明 |
|---|---|---|
| request_id | string | 请求标识 |
| trace_id | string | 链路追踪标识 |
| code | int | 业务状态码,0 表示请求受理成功 |
| error_code | int | 错误码,成功时为 0 |
| message | string | 业务信息或错误信息 |
| tips | any | 补充提示,可为 null |
| data | object | 任务状态和算法结果 |
data 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| status | int | -1 未找到任务;0 创建成功;1 执行中;2 失败;9 需使用查询接口查询;10 成功 |
| result | object | 算法结果 |
| progress | number | 任务进度,例如 0.1、0.85、1 |
| predict_elapsed | int | 预计耗时,毫秒 |
| create_time | int64 | 创建时间戳,毫秒 |
| task_id | string | 任务 ID |
| custom_task_id | string | 客户自定义任务 ID |
| trace_id | string | 链路追踪标识 |
| client_info | string | 客户端信息 |
| init_images | object[]/null | 输入媒体回显 |
result 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 任务 ID |
| urls | string[] | 结果图片列表;rsp_media_type=url 时为图片 URL,rsp_media_type=jpg 时为 base64 编码的图片数据 |
源文同时定义了算法媒体结果字段:
| 字段 | 类型 | 说明 |
|---|---|---|
| parameter | object | 返回媒体类型标识 |
| media_info_list | object[] | 多媒体结果列表,每项包含图片数据及对应信息 |
parameter 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| rsp_media_type | string | jpg 表示 media_data 是经过 base64 编码的图片 |
media_info_list 中单个元素的字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| media_data | string | 多媒体文件数据;源文成功示例为 base64 编码的图片 |
| media_profiles | object | 多媒体文件属性信息 |
media_profiles 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| media_data_type | string | jpg 表示 media_data 是经过 base64 编码的图片 |
源文定义的算法失败字段如下;统一网关失败响应还会通过顶层 code、error_code、message 和 data.result 表达错误。
| 字段 | 类型 | 说明 |
|---|---|---|
| ErrorCode | int | 错误代码 |
| ErrorMsg | string | 错误信息 |
| Data | string/null | 具体信息 |
返回值示例
请求成功返回示例
Response Status:200
content-type 为 application/json; charset=utf-8
{
"request_id": "req_1234567890",
"trace_id": "trace_1234567890",
"code": 0,
"error_code": 0,
"message": "success",
"tips": null,
"data": {
"status": 10,
"result": {
"id": "task_1234567890",
"urls": ["https://example.com/result.jpg"]
},
"progress": 1,
"predict_elapsed": 0,
"create_time": 1718172000000,
"task_id": "task_1234567890",
"custom_task_id": "",
"trace_id": "trace_1234567890",
"client_info": "",
"init_images": null
}
}需要查询返回示例
当 data.status 为 9 时,使用查询接口和返回的任务 ID 查询结果。
Response Status:200
content-type 为 application/json; charset=utf-8
{
"request_id": "req_1234567890",
"trace_id": "trace_1234567890",
"code": 0,
"error_code": 0,
"message": "success",
"tips": null,
"data": {
"status": 9,
"result": {"id": "task_1234567890"},
"progress": 0,
"predict_elapsed": 10000,
"create_time": 1718172000000,
"task_id": "task_1234567890",
"custom_task_id": "",
"trace_id": "trace_1234567890",
"client_info": "",
"init_images": null
}
}请求失败返回示例
Response Status:400
content-type 为 application/json; charset=utf-8
{
"request_id": "req_1234567890",
"trace_id": "trace_1234567890",
"code": 20003,
"error_code": 20003,
"message": "DETECT_NOT_FACE",
"tips": null,
"data": {
"status": 2,
"result": {
"id": "task_1234567890",
"ErrorCode": 20003,
"ErrorMsg": "detect no face",
"Data": null
},
"progress": 1,
"predict_elapsed": 0,
"create_time": 1718172000000,
"task_id": "task_1234567890",
"custom_task_id": "",
"trace_id": "trace_1234567890",
"client_info": "",
"init_images": null
}
}当前 API 特有的错误代码与信息
| ErrorCode 状态代码 | 错误信息 | 说明 |
|---|---|---|
| 20001 | PROCESS_ERROR | 处理错误 |
| 20003 | DETECT_NOT_FACE | 人脸缺失 |
| 20004 | MORE_THAN_ONE_FACE | 人脸数大于 1 |
| 20007 | MISSING_LANDMARK_ARGUMENTS | 未传入人脸点 |
| 20008 | UNSUITABLE_IMAGE | 照片不符合规范 |
| 20009 | UNSUPPORT_TYPE | 不支持的 type |
| 20010 | DETECT_NOT_FACE | 检测不到第二张图片的人脸 |
| 20011 | UNSUITABLE_VERTICAL_IMAGE | 垂直高度不满足 |
| 20012 | UNSUITABLE_HORIZONTAL_IMAGE | 水平宽度不满足 |
| 20013 | RESOLUTION_TOO_LARGE_ERROR | 分辨率过大 |
| 20014 | NOT_FOUND | 查找不到图片 |
| 20015 | PICTURE_OVERRUN_ERROR | 图片超限 |
| 20020 | DETECT_FACE_OUTOFIMAGE | 五官缺失 |
| 20021 | DETECT_FACE_PITCHANGLE_BIG | 非正脸,点头或俯仰角过大 |
| 20022 | DETECT_FACE_YAWANGLE_BIG | 非正脸,摇头或旋转角过大 |
| 20023 | DETECT_FACE_LOWAREA | 脸部占比小、像素低 |
| 21001 | LOAD_MODEL_ERROR | 加载模型失败 |
| 21002 | HAIR_MASK_LOSS | 头发 mask 缺失 |
| 21003 | FACE_NUM_ERROR | 人脸个数错误 |
| 21004 | AR_PARSE_FAULT | AR 中 plist 解析错误 |
| 21005 | AR_EEEOR_COUNT | AR 人脸错误 |
| 21006 | AR_FACE_OUT | AR 超过人脸范围 |
| 21007 | JSON_ERROR | JSON 内容错误 |
| 21008 | BACKGROUND_IMAGE_LOSS | 背景图片缺失 |
| 21009 | BODY_MASK_LOSS | body mask 缺失 |
| 21010 | FACE_ANGLE_ERROR | 人脸角度错误 |
| 21011 | SKIN_MASK_LOSS | skin mask 缺失 |
| 21012 | BODY_INFO_LOSS | 骨骼点或者外轮廓点缺失 |
| 21013 | RECT_OUT_IMAGE | 超过图片范围 |
| 30001 | GEN_ERROR | 生成错误 |
通用的错误代码与信息
详见 API 错误码
SDK 调用示例
以下示例均对最终发送的完整 JSON body 进行签名。
Python
import json
import requests
from sign_sdk import sign
key = "your_api_key"
secret = "your_api_secret"
url = "https://openapi.meitu.com/api/v1/sdk/sync/push"
headers = {"Content-Type": "application/json", sign.HeaderHost: "openapi.meitu.com"}
inner_params = {"rsp_media_type": "url", "parameter": {}}
payload = {
"task": "/v1/High_Definition_V2/466662",
"task_type": "formula",
"init_images": [{
"url": "https://example.com/input.jpg",
"profile": {"media_profiles": {"media_data_type": "url"}, "version": "v1"},
}],
"params": json.dumps(inner_params, ensure_ascii=False),
"sync_timeout": 30,
}
body = json.dumps(payload, ensure_ascii=False)
signed_request = sign.Signer(key, secret).sign(url, "POST", headers, body)
response = requests.Session().send(signed_request)
print(response.status_code, response.text)Go
package main
import (
"fmt"
"io"
"net/http"
"github.com/mtlab/api/signer"
)
func main() {
signObj := signer.NewSigner("your_api_key", "your_api_secret")
url := "https://openapi.meitu.com/api/v1/sdk/sync/push"
headers := make(http.Header)
headers.Set(signer.HeaderHost, "openapi.meitu.com")
headers.Set("Content-Type", "application/json")
body := `{
"task":"/v1/High_Definition_V2/466662",
"task_type":"formula",
"init_images":[{"url":"https://example.com/input.jpg","profile":{"media_profiles":{"media_data_type":"url"},"version":"v1"}}],
"params":"{\"rsp_media_type\":\"url\",\"parameter\":{}}",
"sync_timeout":30
}`
req, err := signObj.Sign(url, http.MethodPost, headers, body)
if err != nil { panic(err) }
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil { panic(err) }
fmt.Println(resp.StatusCode, string(responseBody))
}PHP
<?php
require 'signer.php';
$signer = new Signer('your_api_key', 'your_api_secret');
$url = 'https://openapi.meitu.com/api/v1/sdk/sync/push';
$headers = ['Content-Type' => 'application/json'];
$innerParams = json_encode([
'rsp_media_type' => 'url',
'parameter' => (object) [],
]);
$body = json_encode([
'task' => '/v1/High_Definition_V2/466662',
'task_type' => 'formula',
'init_images' => [[
'url' => 'https://example.com/input.jpg',
'profile' => [
'media_profiles' => ['media_data_type' => 'url'],
'version' => 'v1',
],
]],
'params' => $innerParams,
'sync_timeout' => 30,
]);
$curl = $signer->sign($url, 'POST', $headers, $body);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo "Status: {$status}\nResponse: {$response}\n";
curl_close($curl);
?>Java
package com.meitu.openai.common;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws Exception {
Signer signer = new Signer("your_api_key", "your_api_secret");
String url = "https://openapi.meitu.com/api/v1/sdk/sync/push";
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put(Signer.HeaderHost, "openapi.meitu.com");
String body = "{\n" +
" \"task\":\"/v1/High_Definition_V2/466662\",\n" +
" \"task_type\":\"formula\",\n" +
" \"init_images\":[{\"url\":\"https://example.com/input.jpg\",\"profile\":{\"media_profiles\":{\"media_data_type\":\"url\"},\"version\":\"v1\"}}],\n" +
" \"params\":\"{\\\"rsp_media_type\\\":\\\"url\\\",\\\"parameter\\\":{}}\",\n" +
" \"sync_timeout\":30\n" +
"}";
Map<String, String> signedHeaders = signer.sign(url, "POST", headers, body);
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("POST");
for (Map.Entry<String, String> entry : signedHeaders.entrySet()) {
connection.setRequestProperty(entry.getKey(), entry.getValue());
}
connection.setDoOutput(true);
connection.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
int status = connection.getResponseCode();
InputStream stream = status >= 400 ? connection.getErrorStream() : connection.getInputStream();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) response.append(line);
System.out.println("Response: " + status + " " + response);
}
}
}