IMM SDK for C++

Updated at:

This topic describes how to install and use Intelligent Media Management (IMM) SDK for C++. For API documentation, debugging, and SDK examples, see OpenAPI Explorer.

Prerequisites

  • You have created an AccessKey pair. For more information, see Create an AccessKey pair.

  • You have activated OSS, created a bucket, and uploaded files to the bucket. For more information, see Upload files.

  • You have activated IMM. For more information, see Activate IMM.

  • You have created a project in the IMM console. For more information, see Create a project.

    Note
    • You can also call the CreateProject operation to create a project. For more information, see Create a project.

    • You can call the ListProjects operation to list all projects in a specified region.

Install the SDK

Important

To call IMM API operations of V2020-09-30, use IMM SDK V2020-09-30.

For more information about how to use IMM SDK for C++, see the Quick Start.

Use the SDK

The following example detects faces and face information in an OSS image using IMM SDK for C++. The example targets the China (Hangzhou) region.

Note

Replace the IMM endpoint with one for the region where your IMM project resides. The IMM project and OSS object must be in the same region.

#include <cstdlib>
#include <iostream>
#include <string>
#include <alibabacloud/core/AlibabaCloud.h>
#include <imm/ImmClient.h>

using namespace std;
using namespace AlibabaCloud;
using namespace AlibabaCloud::Imm;
    
int main( int argc, char** argv )
{
    AlibabaCloud::InitializeSdk();

    // Specify the region where the IMM project resides.
    AlibabaCloud::ClientConfiguration configuration( "cn-hangzhou" );

    // Get credentials from environment variables to avoid hardcoding sensitive information.
    // For how to configure environment variables, see https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
    // Use a RAM user's AccessKey pair instead of an Alibaba Cloud account's AccessKey pair
    // to follow the principle of least privilege.
    const char *AccessKeyId = std::getenv("AccessKeyId");
    const char *AccessKeySecret = std::getenv("AccessKeySecret");
    AlibabaCloud::Credentials credential( AccessKeyId, AccessKeySecret );

    ImmClient client( credential, configuration );

    Model::DetectImageFacesRequest request;
    // Specify the name of the IMM project.
    request.setProjectName("immtest");
    // Specify the URI of the OSS image.
    request.setSourceURI("oss://test-bucket/test-object.jpg");

    auto outcome = client.detectImageFaces( request );
    if ( !outcome.isSuccess() )
    {
        std::cout << outcome.error().errorCode() << std::endl;
        AlibabaCloud::ShutdownSdk();
        return(-1);
    }
    
    std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
    
    AlibabaCloud::ShutdownSdk();
    return 0;
}