获取有关名人的信息 - Amazon Rekognition

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

获取有关名人的信息

在这些步骤中,您通过使用 getCelebrityInfo API 操作获取名人信息。名人是通过使用之前对 RecognizeCelebrities 的调用返回的名人 ID 标识的。

正在呼叫 GetCelebrityInfo

这些过程需要 Amazon Rekognition 已知名人的名人 ID。使用您在识别图像中的名人中记住的名人 ID。

获取名人信息 (SDK)
  1. 如果您尚未执行以下操作,请:

    1. 使用 AmazonRekognitionFullAccessAmazonS3ReadOnlyAccess 权限创建或更新用户。有关更多信息,请参见 步骤 1:设置 AWS 账户并创建用户

    2. 安装和配置 AWS CLI 和 AWS 开发工具包。有关更多信息,请参见 第 2 步:设置 AWS CLI 和 AWS 软件开发工具包

  2. 使用以下示例调用 GetCelebrityInfo 操作。

    Java

    此示例显示有关名人的姓名和信息。

    id 替换为识别图像中的名人中显示的名人 ID 之一。

    //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) package aws.example.rekognition.image; import com.amazonaws.services.rekognition.AmazonRekognition; import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; import com.amazonaws.services.rekognition.model.GetCelebrityInfoRequest; import com.amazonaws.services.rekognition.model.GetCelebrityInfoResult; public class CelebrityInfo { public static void main(String[] args) { String id = "nnnnnnnn"; AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); GetCelebrityInfoRequest request = new GetCelebrityInfoRequest() .withId(id); System.out.println("Getting information for celebrity: " + id); GetCelebrityInfoResult result=rekognitionClient.getCelebrityInfo(request); //Display celebrity information System.out.println("celebrity name: " + result.getName()); System.out.println("Further information (if available):"); for (String url: result.getUrls()){ System.out.println(url); } } }
    Java V2

    此代码取自AWS文档 SDK 示例 GitHub 存储库。请在此处查看完整示例。

    import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.GetCelebrityInfoRequest; import software.amazon.awssdk.services.rekognition.model.GetCelebrityInfoResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class CelebrityInfo { public static void main(String[] args) { final String usage = """ Usage: <id> Where: id - The id value of the celebrity. You can use the RecognizeCelebrities example to get the ID value.\s """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String id = args[0]; Region region = Region.US_EAST_1; RekognitionClient rekClient = RekognitionClient.builder() .region(region) .build(); getCelebrityInfo(rekClient, id); rekClient.close(); } public static void getCelebrityInfo(RekognitionClient rekClient, String id) { try { GetCelebrityInfoRequest info = GetCelebrityInfoRequest.builder() .id(id) .build(); GetCelebrityInfoResponse response = rekClient.getCelebrityInfo(info); System.out.println("celebrity name: " + response.name()); System.out.println("Further information (if available):"); for (String url : response.urls()) { System.out.println(url); } } catch (RekognitionException e) { System.out.println(e.getMessage()); System.exit(1); } } }
    AWS CLI

    此 AWS CLI 命令显示 get-celebrity-info CLI 操作的 JSON 输出。将 ID 替换为识别图像中的名人中显示的名人 ID 之一。将profile-name的值替换为您的开发人员资料的名称。

    aws rekognition get-celebrity-info --id celebrity-id --profile profile-name
    Python

    此示例显示有关名人的姓名和信息。

    id 替换为识别图像中的名人中显示的名人 ID 之一。将创建 Rekognition 会话的行中的profile_name值替换为您的开发人员资料的名称。

    # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. # PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) import boto3 def get_celebrity_info(id): session = boto3.Session(profile_name='profile-name') client = session.client('rekognition') # Display celebrity info print('Getting celebrity info for celebrity: ' + id) response = client.get_celebrity_info(Id=id) print(response['Name']) print('Further information (if available):') for url in response['Urls']: print(url) def main(): id = "celebrity-id" celebrity_info = get_celebrity_info(id) if __name__ == "__main__": main()
    .NET

    此示例显示有关名人的姓名和信息。

    id 替换为识别图像中的名人中显示的名人 ID 之一。

    //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) using System; using Amazon.Rekognition; using Amazon.Rekognition.Model; public class CelebrityInfo { public static void Example() { String id = "nnnnnnnn"; AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); GetCelebrityInfoRequest celebrityInfoRequest = new GetCelebrityInfoRequest() { Id = id }; Console.WriteLine("Getting information for celebrity: " + id); GetCelebrityInfoResponse celebrityInfoResponse = rekognitionClient.GetCelebrityInfo(celebrityInfoRequest); //Display celebrity information Console.WriteLine("celebrity name: " + celebrityInfoResponse.Name); Console.WriteLine("Further information (if available):"); foreach (String url in celebrityInfoResponse.Urls) Console.WriteLine(url); } }

GetCelebrityInfo 操作请求

下面是 GetCelebrityInfo 的示例 JSON 输入和输出。

GetCelebrityInfo 的输入是所需名人的 ID。

{ "Id": "nnnnnnn" }

GetCelebrityInfo 操作响应

GetCelebrityInfo 返回一个链接数组 (Urls),这些链接指向有关所请求的名人的信息。

{ "Name": "Celebrity Name", "Urls": [ "www.imdb.com/name/nmnnnnnnn" ] }