All Products
Search
Document Center

ImageSyncScanRequest

Last Updated: Jun 06, 2019

Interface description

SDK interface

  1. ImageSyncScanRequest

Function

Asynchronous image moderation: Identifies risky scenes in images, such as adult content.

region

  1. ap-southeast-1

Scene

Image moderation involves a variety of scenes, and each scene corresponds to a specific label. The relationship between scenes and labels is as follows:

Scene Label Remarks
porn normal Normal image without adult content
porn sexy Sexual image
porn porn Pornographic image

For example, if you want to identify pornographic images in your business, set the “scenes” parameter in the ImageAsyncScanRequest interface to porn. Similarly, you can set “scenes” to other values to suit different identification purposes.

Description of suggestion value in returned result

In porn scene, suggestion will be:[“pass”, “review”, “block”]; pass: normal image;review:need human review;block:illegale image, blocked or delete directly;

How to handle the returned result

  1. label == normal normal images, no risk
  2. label == porn contains porngraphic contenttake action according to suggetionsuggetion == review, human review neededsuggetion == block, delete or blocked

Image requirements

  1. The image link protocol can be either HTTP or HTTPS.
  2. The image format can be PNG, JPG, JPEG, BMP, or GIF.
  3. The maximum image size for synchronous calls is 5 MB and that for asynchronous calls is 20 MB. The download time-out period is 3 seconds.
  4. The recommended image pixel is not smaller than 256 x 256. If the pixel is excessively small, the identification performance may be adversely affected.
  5. The response period of the Image Moderation API is determined by the image download period. Make sure that the storage service of the images is stable. It is recommended to store the images in OSS or cache them in CDN.

Call methods

Synchronous image moderation – interface call example

  1. #coding=utf-8
  2. from aliyunsdkcore import client
  3. from aliyunsdkcore.profile import region_provider
  4. from aliyunsdkgreen.request.v20170112 import ImageSyncScanRequest
  5. import json
  6. import uuid
  7. import datetime
  8. # Please replace with your accessKeyId and accessKeySecret
  9. clt = client.AcsClient("your accessKeyId", "your accessKeySecret",'ap-southeast-1')
  10. region_provider.modify_point('Green', 'ap-southeast-1', 'green.ap-southeast-1.aliyuncs.com')
  11. request = ImageSyncScanRequest.ImageSyncScanRequest()
  12. request.set_accept_format('JSON')
  13. task1 = {"dataId": str(uuid.uuid1()),
  14. "url":"http://xxxx.jpg",
  15. "time":datetime.datetime.now().microsecond
  16. }
  17. # porn
  18. request.set_content(bytearray(json.dumps({"tasks": [task1], "scenes": ["porn"]}), "utf-8"))
  19. response = clt.do_action(request)
  20. print response
  21. result = json.loads(response)
  22. if 200 == result["code"]:
  23. taskResults = result["data"]
  24. for taskResult in taskResults:
  25. if (200 == taskResult["code"]):
  26. sceneResults = taskResult["results"]
  27. for sceneResult in sceneResults:
  28. scene = sceneResult["scene"]
  29. suggestion = sceneResult["suggestion"]
  30. print suggestion
  31. print scene
  32. #Actions taken according to scene and suggestion in returned results
  33. #do something