使用 Amazon Rekognition 的代码示例 AWS SDKs - AWS SDK 代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon Rekognition 的代码示例 AWS SDKs

以下代码示例向您展示了如何将 Amazon Rekognition 与软件开发套件 () AWS 一起使用。SDK

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

跨服务示例 是指跨多个 AWS 服务工作的示例应用程序。

更多资源

开始使用

以下代码示例展示了如何开始使用 Amazon Rekognition。

C++
SDK对于 C++
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整实例,了解如何进行设置和运行。

CMakeLists.txt CMake 文件的代码。

# Set the minimum required version of CMake for this project. cmake_minimum_required(VERSION 3.13) # Set the AWS service components used by this project. set(SERVICE_COMPONENTS rekognition) # Set this project's name. project("hello_rekognition") # Set the C++ standard to use to build this target. # At least C++ 11 is required for the AWS SDK for C++. set(CMAKE_CXX_STANDARD 11) # Use the MSVC variable to determine if this is a Windows build. set(WINDOWS_BUILD ${MSVC}) if (WINDOWS_BUILD) # Set the location where CMake can find the installed libraries for the AWS SDK. string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all") list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH}) endif () # Find the AWS SDK for C++ package. find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) if (WINDOWS_BUILD AND AWSSDK_INSTALL_AS_SHARED_LIBS) # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging. # set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this # and set the proper subdirectory to the executables' location. AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR}${BIN_SUB_DIR}) endif () add_executable(${PROJECT_NAME} hello_rekognition.cpp) target_link_libraries(${PROJECT_NAME} ${AWSSDK_LINK_LIBRARIES})

hello_rekognition.cpp 源文件的代码。

#include <aws/core/Aws.h> #include <aws/rekognition/RekognitionClient.h> #include <aws/rekognition/model/ListCollectionsRequest.h> #include <iostream> /* * A "Hello Rekognition" starter application which initializes an Amazon Rekognition client and * lists the Amazon Rekognition collections in the current account and region. * * main function * * Usage: 'hello_rekognition' * */ int main(int argc, char **argv) { Aws::SDKOptions options; // Optional: change the log level for debugging. // options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug; Aws::InitAPI(options); // Should only be called once. { Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::Rekognition::RekognitionClient rekognitionClient(clientConfig); Aws::Rekognition::Model::ListCollectionsRequest request; Aws::Rekognition::Model::ListCollectionsOutcome outcome = rekognitionClient.ListCollections(request); if (outcome.IsSuccess()) { const Aws::Vector<Aws::String>& collectionsIds = outcome.GetResult().GetCollectionIds(); if (!collectionsIds.empty()) { std::cout << "collectionsIds: " << std::endl; for (auto &collectionId : collectionsIds) { std::cout << "- " << collectionId << std::endl; } } else { std::cout << "No collections found" << std::endl; } } else { std::cerr << "Error with ListCollections: " << outcome.GetError() << std::endl; } } Aws::ShutdownAPI(options); // Should only be called once. return 0; }
  • 有关API详细信息,请参阅 “AWS SDK for C++ API参考 ListCollections” 中的。