SDK を使用した Amazon Rekognition のコード例 AWS SDKs - AWS SDK コードの例

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

SDK を使用した Amazon Rekognition のコード例 AWS SDKs

次のコード例は、 AWS Software Development Kit (SDK) で Amazon Rekognition を使用する方法を示しています。

アクションはより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、関連するシナリオやサービス間の例ではアクションのコンテキストが確認できます。

「シナリオ」は、同じサービス内で複数の関数を呼び出して、特定のタスクを実行する方法を示すコード例です。

クロスサービスの例は、複数の AWS のサービスで動作するサンプルアプリケーションです。

その他のリソース

開始方法

次のコード例は、Amazon Rekognition の使用を開始する方法を示しています。

C++
SDK for C++
注記

については、「」を参照してください GitHub。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

C MakeLists.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 の詳細については、「 API リファレンスListCollections」の「」を参照してください。 AWS SDK for C++