API | Operation | Description |
Moderating an image synchronously | Moderates an image synchronously. | |
Batch moderating images | Batch moderates images. | |
Querying the image moderation job result | Queries the result of the specified image moderation job. |
// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.String bucket = "examplebucket-1250000000";String key = "exampleobject"; // Object keySensitiveContentRecognitionRequest sensitiveContentRecognitionRequest = new SensitiveContentRecognitionRequest(bucket, key);sensitiveContentRecognitionRequest.addType("ads");// `CIService` is a subclass of `CosXmlService` and has the same initialization method as it.ciService.sensitiveContentRecognitionAsync(sensitiveContentRecognitionRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {SensitiveContentRecognitionResult sensitiveContentRecognitionResult = (SensitiveContentRecognitionResult) result;}@Overridepublic void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPIDString bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".String cosPath1 = "dir1/exampleobject1.jpg";String cosPath2 = "dir1/exampleobject2.jpg";// URL of the image. Either `Object` or `Url` can be selected at a time.String imageUrl = "https://myqcloud.com/%205image.jpg";PostImagesAuditRequest request = new PostImagesAuditRequest(bucket);PostImagesAudit.ImagesAuditInput image1 = new PostImagesAudit.ImagesAuditInput();image1.object = cosPath1;// Set the original content, which can contain up to 512 bytes. This field will be returned in the response as-is.image1.dataId = "DataId1";// Frame capturing frequency, which takes effect for GIF images only. The default value is `5`, indicating to capture a frame every five frames starting from the first frame (included).image1.interval = 2;// The maximum number of frames to be captured, which takes effect for GIF images only. The default value is `5`, indicating to capture only five frames of the GIF image for moderation. The parameter value must be greater than 0.image1.maxFrames = 5;PostImagesAudit.ImagesAuditInput image2 = new PostImagesAudit.ImagesAuditInput();image2.object = cosPath2;image2.dataId = "DataId2";image2.interval = 2;image2.maxFrames = 5;PostImagesAudit.ImagesAuditInput image3 = new PostImagesAudit.ImagesAuditInput();image3.url = imageUrl;image3.dataId = "DataId3";image3.interval = 2;image3.maxFrames = 5;request.addImage(image1);request.addImage(image2);request.addImage(image3);// The scene to be moderated, such as `Porn` (pornography) and `Ads` (advertising). You can pass in multiple types and separate them by comma, such as `Porn,Ads`.request.setDetectType("Porn,Ads");ciService.postImagesAuditAsync(request, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult cosResult) {// `result` is the result of the batch image moderation job.// For detailed fields, see the API documentation or SDK source code.PostImagesAuditResult result = (PostImagesAuditResult) cosResult;}@Overridepublic void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPIDString bucket = "examplebucket-1250000000";// Moderation job IDString jobId = "iab1ca9fc8a3ed11ea834c525400863904";GetImageAuditRequest request = new GetImageAuditRequest(bucket, jobId);ciService.getImageAuditAsync(request, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult cosResult) {// `result` is the result of the image moderation job.// For detailed fields, see the API documentation or SDK source code.GetImageAuditResult result = (GetImageAuditResult) cosResult;}@Overridepublic void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Was this page helpful?