华为的moderation通过内容审核api,分析并识别用户上传的图像内容是否有敏感内容(如涉及政治人物、暴恐元素、涉黄内容等),并将识别结果返回给用户。
1、SDK下载:
PHP:https://static.huaweicloud.com/upload/files/sdk/Moderationphp.zip
JAVA:http://static.huaweicloud.com/upload/files/sdk/sdkmoderation.zip
Python:https://static.huaweicloud.com/upload/files/sdk/Moderationpython.zip
2、Api文档
https://support.huaweicloud.com/sdkreference-moderation/moderation_04_0007.html
3、图像反黄检测
URI:POST /v1.0/moderation/image/anti-porn
// 1. 配置好访问图像反黄检测服务的基本信息,生成对应的一个客户端连接对象
AisAccess service = ServiceAccessBuilder.builder()
.ak("######") // your ak
.sk("######") // your sk
.region("cn-north-1") // 图像识别服务华北-北京一(cn-north-1)的配置
.connectionTimeout(5000) // 连接目标url超时限制
.connectionRequestTimeout(1000) // 连接池获取可用连接超时限制
.socketTimeout(20000) // 获取服务器响应数据超时限制
.build();
//
// 2.构建访问图像反黄检测服务需要的参数,也可以用url
//
String uri = "/v1.1/moderation/image/anti-porn";
byte[] fileData = FileUtils.readFileToByteArray(new File("data/moderation-demo-1.jpg"));
String fileBase64Str = Base64.encodeBase64String(fileData);
完整的请求信息 :url
POST https://moderation.cn-north-1.myhuaweicloud.com/v1.0/moderation/image
Request Header:
Content-Type:application/json
X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"url" : "https://BucketName.obs.myhwclouds.com/ObjectName",
"image" : "",
"categories":[
"politics",
"terrorism"
],
"threshold" : ""
}
完整的请求信息 :base64
POST https://moderation.cn-north-1.myhuaweicloud.com/v1.0/moderation/image
Request Header:
Content-Type:application/json
X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"url" : "",
"image" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA...",
"categories":[
"politics",
"terrorism"
],
"threshold" : ""
}
响应:
{
"result":{
"detail":{
"politics":[
{
"confidence": 0.89155281782150264,
"face_detail":{
"h": 130,
"w": 103,
"x": 80,
"y": 125
},
"label": "xxx"
},
{
"confidence": 0.87563462432654422,
"face_detail":{
"h": 131,
"w": 203,
"x": 423,
"y": 109
},
"label": "yyy"
}
],
"terrorism":[
{
"confidence": 0.73155281782150264,
"label": "xxx"
},
{
"confidence": 0.26844718217849736,
"label": "yyy"
}
]
},
"suggestion": "block"
}
}