Synchronous detection

Updated at:

This topic describes the API operations and parameters for submitting synchronous image detection tasks to perform liveness detection. You can use this information to build HTTP requests in your program.

Important Liveness and spoofing detection requires that an image contains a face. We recommend that you use this API operation with the sensitive face recognition feature. First, call the sensitive face recognition API operation to detect faces in an image. After a face is detected, call the liveness and spoofing detection API operation to determine whether the face is a spoof. For more information, see Sensitive face recognition.

Usage notes

API operation: /green/image/scan

Call this operation to submit a synchronous image detection task. The task performs liveness detection to determine whether a live object, such as a face, in an image is from a direct shot or a screen replay. To learn how to construct an HTTP request, see Request structure. You can also use a pre-constructed HTTP request. For more information, see SDK overview.

This is a paid API operation. For more information about billing, see Content Moderation Pricing.

Detection time limit

The maximum detection time for a synchronous call is 6 seconds. If the detection does not complete within this time, the system returns a timeout error. If real-time results are not critical, use asynchronous detection. Otherwise, use synchronous detection, which is simpler to call. For synchronous calls, set the timeout period to 6 seconds.

Image limits
  • The image URL must use the HTTP or HTTPS protocol.

  • Supported image formats: PNG, JPG, JPEG, BMP, GIF, and WEBP.

  • The image size cannot exceed 20 MB for both synchronous and asynchronous calls. The height or width cannot exceed 30,000 pixels (px), and the total number of pixels cannot exceed 250 million (px).

    Note

    For GIF images, the total number of pixels cannot exceed 4,194,304 (px), and the height or width cannot exceed 30,000 pixels (px).

  • The image must be downloaded within 3 seconds. If the download time exceeds 3 seconds, a download timeout error is returned.

  • For optimal performance, we recommend that the image resolution be at least 256x256 pixels. A lower resolution may affect the detection accuracy.

  • The response time of the image detection API depends on the image download time. Ensure that the storage service where the image is stored is stable and reliable. For best performance, use Alibaba Cloud Object Storage Service (OSS) or a Content Delivery Network (CDN).

QPS limit

The queries per second (QPS) limit for this API is 50 per user. Exceeding this limit triggers throttling, which can impact your business. Plan your calls accordingly.

Request parameters

For more information about the common request parameters that must be included in a request, see Common parameters.

The request body is a JSON object that contains the fields described in the following table.
NameTypeRequiredExampleDescription
bizTypeStringNodefault

This field identifies your business scenario. You can create a business scenario in the Content Moderation console. For more information, see Customize moderation rules.

scenesStringArrayYes["liveness"]The application scenario for image detection. The only valid value is liveness.
tasksJSONArrayYesThe detection objects. Each element in this JSON array is a detection task struct. You can specify up to 100 elements. To submit 100 elements at a time, you must set the number of concurrent tasks to more than 100. For more information about the structure of each element, see task.
Table 1. task
NameTypeRequiredExampleDescription
dataIdStringNotest2NInmO$tAON6qYUrtCRgLo-1mwxdiThe data ID. Ensure that all IDs in a single request are unique.
urlStringYeshttps://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.pngThe URL of the image to detect.

Returned data

For more information about the response, see Response parameters.

The `data` field in the response body is a JSON array. Each element in the array is an object that contains the following fields.
NameTypeExampleDescription
codeInteger200

The error code. It is the same as the HTTP status code.

For more information, see Common error codes.

msgStringOKThe response message for the request.
dataIdStringtest2NInmO$tAON6qYUrtCRgLo-1mwxdiCorresponds to the dataId in the request.
taskIdStringimg2hsbmQeA4CU7l78$s8q5mW-1pnn7ZThe ID of the detection task.
urlStringhttps://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.pngCorresponds to the URL in the request.
extrasMapxxxAdditional information. This value is subject to change. Do not create a business dependency on it.
resultsJSONArrayThe detection results. When the call is successful (code=200), the results contain one or more elements. Each element is a struct. For a description of the structure, see result.
Table 2. result
NameTypeExampleDescription
sceneStringlivenessThe risk scenario. The only valid value is liveness.
labelStringlivenessThe classification of the detection result. Valid values:
  • normal: A live photo.
  • liveness: A replayed photo.
suggestionStringreviewThe recommended action. Valid values:
  • pass: The object in the image is from a direct shot. No further action is needed.
  • review: The object in the image may be from a screen replay. Confirm before you proceed.
  • block: The object in the image is highly likely from a screen replay. Take further action.
rateFloat97.0The probability that the result belongs to this classification. The value ranges from 0.00 to 100.00. A higher value indicates a higher probability.
livenessDataJSONObjectThe liveness detection information returned when the result is a replay (label=liveness). For a description of the structure, see livenessData.
Table 3. livenessData
NameTypeExampleDescription
rateFloat97.0The probability that the liveness photo is a recaptured photo. A higher score indicates a higher probability.

Examples

Request example
http(s)://[Endpoint]/green/image/scan
&<Common request parameters>

{
  "scenes": ["liveness"],
  "tasks": [
    {
      "dataId": "test2NInmO$tAON6qYUrtCRgLo-1mwxdi",
      "url": "https://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.png"
    }
  ]
}
Response example
{
 "code": 200,
 "msg": "OK",
 "requestId": "9EEF894F-A933-4830-97B1-EC1A9630A9D6",
 "data": [{
  "code": 200,
  "dataId": "test2NInmO$tAON6qYUrtCRgLo-1mwxdi",
  "taskId": "img2hsbmQeA4CU7l78$s8q5mW-1pnn7Z",
  "url": "https://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.png",
  "msg": "OK",
  "results": {
   "label": "liveness",
   "rate": 97.0,
   "scene": "liveness",
   "suggestion": "review",
   "livenessData": {
   "rate": 97.0
   }
  }
 }]
}