Manual image review

Updated at:

This topic describes how to use the .NET software development kit (SDK) to manually review images.

Description

If you think the image detection result does not meet your expectations, you can perform a manual review. For more information about the parameters, see Manual image moderation API reference.

For the endpoint of this API, see Endpoint.

Note
  • This SDK only supports image URLs. Local files or binary data are not supported.

  • Supported URL types:

    • Public HTTP/HTTPS URLs with a maximum length of 2,048 characters.

    • Alibaba Cloud OSS URLs: oss://<bucket-name>.<endpoint>/<object-name>. You must authorize Content Moderation to access the target OSS bucket, and the bucket must be in the same region as the Content Moderation service. For more information, see Authorize Content Moderation to access OSS storage space.

Prerequisites

Before you begin, make sure you have:

  • Installed the .NET dependencies. See Install .NET dependencies and use the exact .NET version specified — otherwise operation calls will fail.

  • An AccessKey ID and AccessKey secret for a RAM user, stored as environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.

Submit an image for manual review

Sample code

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * Common methods to obtain environment variables:
             *     Obtain the AccessKey ID of a Resource Access Management (RAM) user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     Obtain the AccessKey secret of a RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "Obtain the AccessKey ID of the RAM user from an environment variable.",
                    "Obtain the AccessKey secret of the RAM user from an environment variable.");
            // Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
            DefaultAcsClient client = new DefaultAcsClient(profile);

            ImageAsyncManualScanRequest request = new ImageAsyncManualScanRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            Dictionary<string, object> task1 = new Dictionary<string, object>();
            task1.Add("dataId", "The data ID.");
            task1.Add("url", "The image URL.");

            // The callback and seed parameters are optional. They are used for callback notifications.
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("bizType", "The business scenario.");
            httpBody.Add("callback", "The webhook address.");
            httpBody.Add("seed", "A random string.");
            httpBody.Add("tasks", new List<Dictionary<string, object>> { task1 });

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
            try
            {
                ImageAsyncManualScanResponse response = client.GetAcsResponse(request);
                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}

Query the result of a manual image review

Sample code

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * Common methods to obtain environment variables:
             *     Obtain the AccessKey ID of a Resource Access Management (RAM) user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     Obtain the AccessKey secret of a RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "Obtain the AccessKey ID of the RAM user from an environment variable.",
                    "Obtain the AccessKey secret of the RAM user from an environment variable.");
            // Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
            DefaultAcsClient client = new DefaultAcsClient(profile);

            ImageAsyncManualScanResultsRequest request = new ImageAsyncManualScanResultsRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            List<string> tasks = new List<string>();
            tasks.Add("The ID of the manual image review task.");

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(tasks)), "utf-8", FormatType.JSON);
            try
            {
                ImageAsyncManualScanResultsResponse response = client.GetAcsResponse(request);
                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}