本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
取得名人的相關資訊
在這些程序中,您會使用 getCelebrityInfo API 操作來取得名人資訊。使用之前呼叫 RecognizeCelebrities 所傳回的名人 ID,即可識別名人。
呼叫 GetCelebrityInfo
這些程序也需要 Amazon Rekognition 已知名人的名人 ID。使用您在「辨識映像中的名人」中記下的名人 ID。
取得名人資訊 (開發套件)
如果您尚未執行:
建立或更新具有
AmazonRekognitionFullAccess
和AmazonS3ReadOnlyAccess
許可的使用者。如需詳細資訊,請參閱步驟 1:設定AWS帳戶並建立使用者。安裝和設定 AWS CLI 和 AWS SDKs。如需詳細資訊,請參閱步驟 2:設定 AWS CLI 以及 AWS SDKs。
使用下列範例來呼叫
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 文件開發套件範例 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 命令會顯示 CLI
get-celebrity-info
操作的 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" ] }