tencent cloud

Feedback

Image Moderation

Last updated: 2024-02-29 16:06:23

    Overview

    This document describes how to use the content moderation feature provided by Cloud Infinite (CI). CI fully integrates the processing capabilities with the COS SDK.
    Note:
    To use the content moderation service, you need to have the permission to use CI:
    For root accounts, click here for role authorization.
    This document provides an overview of APIs and SDK code samples for image moderation.
    API
    Description
    Scans existing data stored in COS for pornographic, illegal, and advertising images.
    Moderates multiple images in batches.
    Queries the result of the specified image moderation job.

    SDK API References

    For parameters and method description of all APIs in the SDK, see SDK API Reference.

    Single Image Moderation

    Feature description

    This API (QCloudSyncImageRecognitionRequest) is used to submit an image moderation job. You can receive the moderation result by setting the callback address or querying by JobId.
    Note:
    The COS iOS SDK version must be at least v6.0.9.

    Sample request

    Objective-C
    QCloudSyncImageRecognitionRequest * request = [[QCloudSyncImageRecognitionRequest alloc]init];
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = @"bucket";
    
    // File region
    request.regionName = @"regionName";
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".
    request.object = @"***.jpg";
    
    // Moderation type, such as `porn` (pornography) and `ads` (advertising).
    // You can select multiple types; for example, `detect-type=porn,ads` indicates to moderate the image for pornographic and advertising information.
    // You can use multiple parameters together, such as `QCloudRecognitionPorn | QCloudRecognitionTerrorist`.
    request.detectType = QCloudRecognitionPorn | QCloudRecognitionTerrorist | QCloudRecognitionPolitics | QCloudRecognitionAds;
    [request setFinishBlock:^(QCloudImageRecognitionResult * _Nullable result, NSError * _Nullable error) {
    // `outputObject` is the moderation result. For detailed fields, see the API documentation or SDK source code.
    // `QCloudImageRecognitionResult` class
    }];
    [[QCloudCOSXMLService defaultCOSXML] SyncImageRecognition:request];
    
    Note:
    For more complete samples, visit GitHub.
    Swift
    let request : QCloudSyncImageRecognitionRequest = QCloudSyncImageRecognitionRequest();
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = "bucket";
    
    // File region
    request.regionName = "regionName";
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".
    request.object = "***.jpg";
    
    // Moderation type, such as `porn` (pornography) and `ads` (advertising).
    // You can select multiple types; for example, `detect-type=porn,ads` indicates to moderate the image for pornographic and advertising information.
    // You can use multiple parameters together, such as `QCloudRecognitionPorn | QCloudRecognitionTerrorist`.
    request.detectType = QCloudRecognitionEnum(rawValue: QCloudRecognitionEnum.porn.rawValue | QCloudRecognitionEnum.ads.rawValue)!
    
    request.finishBlock = { (result, error) in
    // `outputObject` is the moderation result. For detailed fields, see the API documentation or SDK source code.
    // `QCloudImageRecognitionResult` class
    }
    QCloudCOSXMLService.defaultCOSXML().syncImageRecognition(request);
    Note:
    For more complete samples, visit GitHub.

    Batch Image Moderation

    Feature description

    The batch image moderation API adopts a sync POST request method. You can use this API to perform content moderation on multiple image files.
    Note:
    The COS iOS SDK version must be at least v6.0.9.

    Sample request

    Objective-C
    
    QCloudBatchimageRecognitionRequest * request = [[QCloudBatchimageRecognitionRequest alloc]init];
    
    request.bucket = @"bucket";
    // File region
    request.regionName = @"regionName";
    
    NSMutableArray * input = [NSMutableArray new];
    
    // The image object to be moderated
    QCloudBatchRecognitionImageInfo * input1 = [QCloudBatchRecognitionImageInfo new];
    input1.Object = @"***.jpg";
    [input addObject:input1];
    
    QCloudBatchRecognitionImageInfo * input2 = [QCloudBatchRecognitionImageInfo new];
    input2.Object = @"***.jpg";
    [input addObject:input2];
    
    // The array of image objects to be moderated
    request.input = input;
    request.detectType = QCloudRecognitionPorn | QCloudRecognitionTerrorist | QCloudRecognitionPolitics | QCloudRecognitionAds;
    [request setFinishBlock:^(QCloudBatchImageRecognitionResult * _Nullable result, NSError * _Nullable error) {
    // `outputObject` is the moderation result. For detailed fields, see the API documentation or SDK source code.
    // `QCloudBatchImageRecognitionResult` class
    }];
    [[QCloudCOSXMLService defaultCOSXML] BatchImageRecognition:request];
    
    Note:
    For more complete samples, visit GitHub.
    Swift
    let request = QCloudBatchimageRecognitionRequest();
    request.bucket = "bucket";
    
    // File region
    request.regionName = "regionName";
    
    // The image object to be moderated
    let input1 = QCloudBatchRecognitionImageInfo();
    input1.object = "***.jpg";
    
    let input2 = QCloudBatchRecognitionImageInfo();
    input2.object = "***.jpg";
    
    // The array of image objects to be moderated
    request.input = [input1,input2];
    request.detectType = QCloudRecognitionEnum(rawValue: QCloudRecognitionEnum.porn.rawValue | QCloudRecognitionEnum.ads.rawValue)!
    request.setFinish { outputObject, error in
    // `outputObject` is the moderation result. For detailed fields, see the API documentation or SDK source code.
    // `QCloudBatchImageRecognitionResult` class
    }
    QCloudCOSXMLService.defaultCOSXML().batchImageRecognition(request);
    Note:
    For more complete samples, visit GitHub.

    Querying Image Moderation Job Result

    Feature description

    This API (QCloudGetImageRecognitionRequest) is used to query the result of the specified sync or batch image moderation job by JobId.
    Note:
    The COS iOS SDK version must be at least v6.0.9.

    Sample request

    Objective-C
    QCloudGetImageRecognitionRequest * request = [[QCloudGetImageRecognitionRequest alloc]init];
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = @"examplebucket-1250000000";
    
    // File region
    request.regionName = @"regionName";
    
    // The `jobid` of the sync or batch moderation job
    request.jobId = @"jobid";
    
    request.finishBlock = ^(QCloudImageRecognitionResult * outputObject, NSError *error) {
    // The moderation result `outputObject` contains the job ID used for query. For detailed fields, see the API documentation or SDK source code.
    // `QCloudImageRecognitionResult` class
    };
    [[QCloudCOSXMLService defaultCOSXML] GetImageRecognition:request];
    Note:
    For more complete samples, visit GitHub.
    Swift
    let request = QCloudGetImageRecognitionRequest();
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = "examplebucket-1250000000";
    
    request.regionName = "regionName";
    
    // The `jobid` of the sync or batch moderation job
    request.jobId = "jobid";
    
    request.setFinish { outputObject, error in
    // The moderation result `outputObject` contains the job ID used for query. For detailed fields, see the API documentation or SDK source code.
    // `QCloudWebRecognitionResult` class
    };
    QCloudCOSXMLService.defaultCOSXML().getImageRecognition(request);
    Note:
    For more complete samples, visit GitHub.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support