一、添加依赖
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>facebody20191230</artifactId>
<version>3.0.7</version>
</dependency>
二、JavaCode
import com.aliyun.facebody20191230.models.EnhanceFaceResponse;
import com.aliyun.tea.TeaModel;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
public class Sample {
public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// 必填,您的 AccessKey ID
.setAccessKeyId(accessKeyId)
// 必填,您的 AccessKey Secret
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new com.aliyun.facebody20191230.Client(config);
}
public static void main(String[] args) throws Exception {
com.aliyun.facebody20191230.Client client = Sample.createClient("{ak}", "{sk}");
// 场景一,使用本地文件
InputStream inputStream = new FileInputStream(new File("本地图片"));
// 场景二,使用任意可访问的url
//URL url = new URL("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/ocr/RecognizeBankCard/yhk1.jpg");
//InputStream inputStream = url.openConnection().getInputStream();
com.aliyun.facebody20191230.models.EnhanceFaceAdvanceRequest request = new com.aliyun.facebody20191230.models.EnhanceFaceAdvanceRequest().setImageURLObject(inputStream);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
EnhanceFaceResponse response = client.enhanceFaceAdvance(request,runtime);
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response)));
}
}
三、返回结果
{"headers":{"access-control-allow-origin":"*","date":"Wed, 15 Feb 2023 05:56:10 GMT","content-length":"351","x-acs-request-id":"F6120077-B411-5803-A2E9-8D2F083832D6","connection":"keep-alive","content-type":"application/json;charset=utf-8","x-acs-trace-id":"1321ab1649fcd435ace4f68728a0ddfe"},"body":{"RequestId":"F6120077-B411-5803-A2E9-8D2F083832D6","Data":{"ImageURL":"http://vibktprfx-prod-prod-damo-eas-cn-shanghai.oss-cn-shanghai.aliyuncs.com/eas-face-enhan/2023-02-15/f980076a-23f4-4744-b714-ca7a7b450cf5/20230215_135610745274_fl8wzn12gi.jpg?Expires=1676442370&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=CNc0e4WJ5uN65gu8fbAx7rIgf5Q%3D"}},"statusCode":200}
四、参考文档
文件URL处理