This topic describes how to use the background removal feature to create ID photos. This topic uses the China (Shanghai) region as an example.
Background
ID photos are often required for school, work, and daily life. These photos usually have a white or other solid-color background. Going to a photo studio each time can be inconvenient. This topic describes how to quickly create an ID photo from a personal or travel photo using a mobile app.
Use the console (API debugging)
This section uses portrait background removal as an example.
Prerequisites: Activate IVPD and OSS
Upload an image to OSS
Go to the OSS console. Select a bucket in the China (Shanghai) region and upload the photo that you want to process. If you do not have a bucket in the China (Shanghai) region, create one and set it to public-read.
Example:
Debugging APIs in the console
Open the IVPD console.
Input:
{
"url": "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/IMG_20190515_202100.jpg"
}
Click OK to generate the result.
Java SDK development
As in the console example, the following example uses portrait matting.
Prerequisites: Activate IVPD and OSS
Upload the image
Select a bucket in the China (Shanghai) region and upload the photo that you want to process.
Import the SDK
Import the Maven dependency:
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-ivpd -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-ivpd</artifactId>
<version>0.1.0</version>
</dependency>
Write the code
Java
DefaultProfile profile = DefaultProfile.getProfile(
"cn-shanghai", // Default
"{accessKeyId}", // Your Access Key ID
"{accessKeySecret}"); // Your Access Key Secret
SegmentImageRequest req = new SegmentImageRequest();
req.setBizUrl("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/IMG_20190515_202100.jpg");
SegmentImageResponse resp = getAcsResponse(req);
if ("0".equals(resp.getCode()) {
String url = resp.getData().getUrl();// The URL of the image with the background removed.
//TODO
}