Alibaba Cloud OpenAPI Explorer provides API documentation, API debugging, and SDK examples to help you get started by using the API. This topic describes how to install and use Intelligent Media Management (IMM) SDK for C++.
Prerequisites
An AccessKey pair is created and obtained. For more information, see Create an AccessKey pair.
OSS is activated, a bucket is created, and objects are uploaded to the bucket. For more information, see Upload objects.
IMM is activated. For more information, see Activate IMM.
A project is created in the IMM console. For more information about how to create a project by using the IMM console, see Create a project.
NoteYou can also call the CreateProject operation to create a project. For more information, see CreateProject.
You can call the ListProjects operation to query existing projects in a specific region. For more information, see ListProjects.
Install the SDK
To call IMM API operations of V2020-09-30, you must use IMM SDK V2020-09-30.
For more information about how to use IMM SDK for C++, see Quick Start.
Use the SDK
The following sample code provides an example how to detect faces and face information in an image in the China (Hangzhou) region by using IMM SDK for C++:
When you use the following sample code, replace the IMM endpoint with one for the region where your IMM project resides. Make sure that the IMM project and OSS object reside 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 ID of the region in which the project resides.
AlibabaCloud::ClientConfiguration configuration( "cn-hangzhou" );
// The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M.
// We recommend that you do not hardcode your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, the AccessKey pair is obtained from the environment variables. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables.
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");
// Initiate the request.
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;
}