IMM SDK for C++
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
-
An AccessKey pair is created. For more information, see Create an AccessKey pair.
-
OSS is activated, a bucket is created, and files are uploaded to the bucket. For more information, see Upload files using the console.
-
IMM is activated. For more information, see Activate a product.
-
A project is created in the IMM console. For more information, see Create a project.
Note-
You can also call an API operation to create a project. For more information, see CreateProject.
-
You can call the ListProjects operation to list information about all projects created in a specific region.
-
Install the SDK
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.
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;
}