├── .github └── PULL_REQUEST_TEMPLATE.md ├── CONTRIBUTING.md ├── LICENSE ├── LICENSE-SAMPLECODE ├── LICENSE-SUMMARY ├── README.md ├── code_examples ├── dotnet_examples │ ├── README.md │ └── image │ │ ├── net-add-faces.cs │ │ ├── net-celebrities-in-image.cs │ │ ├── net-celebrity-info.cs │ │ ├── net-compare-faces.cs │ │ ├── net-create-collection.cs │ │ ├── net-delete-collection.cs │ │ ├── net-delete-faces.cs │ │ ├── net-detect-faces.cs │ │ ├── net-detect-labels-local-file.cs │ │ ├── net-detect-labels.cs │ │ ├── net-detect-moderation-labels.cs │ │ ├── net-detect-text.cs │ │ ├── net-image-orientation-bounding-box.cs │ │ ├── net-list-collections.cs │ │ ├── net-list-faces.cs │ │ ├── net-search-faces-matching-id.cs │ │ └── net-search-faces-matching-image.cs ├── java_examples │ ├── README.md │ ├── image │ │ ├── java-add-faces-to-collection.java │ │ ├── java-celebrity-info.java │ │ ├── java-compare-faces.java │ │ ├── java-create-collection.java │ │ ├── java-delete-collection.java │ │ ├── java-delete-faces-from-collection.java │ │ ├── java-describe-collection.java │ │ ├── java-detect-faces.java │ │ ├── java-detect-labels-local-file.java │ │ ├── java-detect-labels.java │ │ ├── java-detect-moderation-labels.java │ │ ├── java-detect-text.java │ │ ├── java-list-collections.java │ │ ├── java-list-faces-In-collection.java │ │ ├── java-list-faces-in-collection.java │ │ ├── java-recognize-celebrities.java │ │ ├── java-rotate-image.java │ │ ├── java-search-face-matching-id-collection.java │ │ └── java-search-face-matching-image-collection.java │ ├── stored_video │ │ ├── java-lambda-handler-sns.java │ │ └── java-rek-video.java │ └── streaming_video │ │ ├── java-stream-processor-manager.java │ │ └── java-stream-processor-starter.java ├── javascript_examples │ ├── README.md │ ├── js-estimate-age-snippet.html │ └── js-estimate-age.html ├── php_examples │ ├── README.md │ └── php-detect-labels-local-file.php └── python_examples │ ├── README.md │ ├── image │ ├── python-add-faces-to-collection.py │ ├── python-compare-faces.py │ ├── python-create-collection.py │ ├── python-delete-collection.py │ ├── python-delete-faces-from-collection.py │ ├── python-describe-collection.py │ ├── python-detect-faces.py │ ├── python-detect-labels-local-file.py │ ├── python-detect-labels.py │ ├── python-detect-moderation-labels.py │ ├── python-detect-text.py │ ├── python-get-celebrity-info.py │ ├── python-image-orientation-bounding-box.py │ ├── python-list-collections.py │ ├── python-list-faces-in-collection.py │ ├── python-recognize-celebrities.py │ ├── python-search-faces-by-image-collection.py │ ├── python-search-faces-collection.py │ └── python-show-faces-bounding-exif.py │ └── stored_video │ └── python-rek-video.py └── doc_source ├── API_Reference.md ├── a2i-rekognition.md ├── add-faces-to-collection-procedure.md ├── aggregated-metrics.md ├── api-streaming-video-roles.md ├── api-video-roles.md ├── api-video.md ├── best-practices.md ├── celebrities-procedure-image.md ├── celebrities-video-sqs.md ├── celebrities.md ├── celebrity-recognition-vs-face-search.md ├── cloudwatch-metricsdim.md ├── collections-streaming.md ├── collections.md ├── compare-faces-console.md ├── considerations-public-safety-use-cases.md ├── create-collection-procedure.md ├── cross-service-confused-deputy-prevention.md ├── data-protection.md ├── delete-collection-procedure.md ├── delete-faces-procedure.md ├── describe-collection-procedure.md ├── detect-faces-console.md ├── detect-labels-console.md ├── disaster-recovery-resiliency.md ├── displaying-rekognition-results-locally.md ├── document-history.md ├── error-handling.md ├── example_cross_DetectFaces_section.md ├── example_cross_DetectLabels_section.md ├── example_cross_RekognitionPhotoAnalyzerPPE_section.md ├── example_cross_RekognitionPhotoAnalyzer_section.md ├── example_cross_RekognitionVideoDetection_section.md ├── example_rekognition_CompareFaces_section.md ├── example_rekognition_CreateCollection_section.md ├── example_rekognition_DeleteCollection_section.md ├── example_rekognition_DeleteFaces_section.md ├── example_rekognition_DescribeCollection_section.md ├── example_rekognition_DetectFaces_section.md ├── example_rekognition_DetectLabels_section.md ├── example_rekognition_DetectModerationLabels_section.md ├── example_rekognition_DetectText_section.md ├── example_rekognition_GetCelebrityInfo_section.md ├── example_rekognition_IndexFaces_section.md ├── example_rekognition_ListCollections_section.md ├── example_rekognition_ListFaces_section.md ├── example_rekognition_RecognizeCelebrities_section.md ├── example_rekognition_SearchFacesByImage_section.md ├── example_rekognition_SearchFaces_section.md ├── example_rekognition_Usage_DetectAndDisplayImage_section.md ├── example_rekognition_Usage_FindFacesInCollection_section.md ├── example_rekognition_VideoDetection_section.md ├── face-detection-model.md ├── face-feature-differences.md ├── faces-comparefaces.md ├── faces-detect-images.md ├── faces-sqs-video.md ├── faces.md ├── fedramp.md ├── get-celebrity-info-procedure.md ├── get-started-exercise.md ├── getting-started-console.md ├── getting-started.md ├── glossary.md ├── guidance-face-attributes.md ├── how-it-works-operations-intro.md ├── how-it-works-storage-non-storage.md ├── how-it-works-types.md ├── how-it-works.md ├── identity-verification-tutorial.md ├── image-bytes-javascript.md ├── images-bytes.md ├── images-displaying-bounding-boxes.md ├── images-information.md ├── images-lambda-s3-tutorial.md ├── images-orientation.md ├── images-s3.md ├── images.md ├── index.md ├── infrastructure-security.md ├── labels-detect-labels-image.md ├── labels-detecting-custom-labels.md ├── labels-detecting-labels-video.md ├── labels.md ├── limits.md ├── list-collection-procedure.md ├── list-faces-in-collection-procedure.md ├── logging-using-cloudtrail.md ├── moderation.md ├── operation-latency.md ├── persons.md ├── ppe-detection.md ├── ppe-example-image-bounding-box.md ├── ppe-procedure-image.md ├── ppe-request-response.md ├── procedure-moderate-images.md ├── procedure-moderate-videos.md ├── procedure-person-search-videos.md ├── programming.md ├── recommendations-camera-image-video.md ├── recommendations-camera-stored-streaming-video.md ├── recommendations-camera-streaming-video.md ├── recommendations-facial-input-images.md ├── rekognition-compliance.md ├── rekognition-monitoring.md ├── rekognition-video-stream-processor-search-faces.md ├── sdk-general-information-section.md ├── search-face-with-id-procedure.md ├── search-face-with-image-procedure.md ├── security-data-encryption.md ├── security-iam-awsmanpol.md ├── security-iam.md ├── security-inter-network-privacy.md ├── security.md ├── security_iam_id-based-policy-examples.md ├── security_iam_resource-based-policy-examples.md ├── security_iam_service-with-iam.md ├── security_iam_troubleshoot.md ├── segment-api.md ├── segment-example.md ├── segments.md ├── service_code_examples.md ├── service_code_examples_actions.md ├── service_code_examples_cross-service_examples.md ├── service_code_examples_scenarios.md ├── setting-up-your-amazon-rekognition-streaming-video-resources.md ├── setting-up.md ├── setup-awscli-sdk.md ├── storage-tutorial.md ├── stored-video-lambda.md ├── stored-video-tutorial-v2.md ├── streaming-labels-detection.md ├── streaming-labels-setting-up.md ├── streaming-using-gstreamer-plugin.md ├── streaming-video-detect-labels.md ├── streaming-video-kinesis-output-reference-detectedface.md ├── streaming-video-kinesis-output-reference-facematch.md ├── streaming-video-kinesis-output-reference-facesearchresponse.md ├── streaming-video-kinesis-output-reference-inputinformation.md ├── streaming-video-kinesis-output-reference-kinesisvideostreams-kinesisvideo.md ├── streaming-video-kinesis-output-reference-streamprocessorinformation.md ├── streaming-video-kinesis-output-reference.md ├── streaming-video-kinesis-output.md ├── streaming-video-tagging-stream-processor.md ├── streaming-video-troubleshooting.md ├── streaming-video.md ├── tag-collections.md ├── text-detecting-text-procedure.md ├── text-detecting-video-procedure.md ├── text-detection.md ├── tutorials.md ├── video-analyzing-with-sqs.md ├── video-cli-commands.md ├── video-notification-payload.md ├── video-troubleshooting.md ├── video.md ├── vpc.md ├── vulnerability-analysis-and-management.md └── what-is.md /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 7 | -------------------------------------------------------------------------------- /LICENSE-SAMPLECODE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | software and associated documentation files (the "Software"), to deal in the Software 5 | without restriction, including without limitation the rights to use, copy, modify, 6 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 10 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 11 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 12 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 13 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 14 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /LICENSE-SUMMARY: -------------------------------------------------------------------------------- 1 | Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | The documentation is made available under the Creative Commons Attribution-ShareAlike 4.0 International License. See the LICENSE file. 4 | 5 | The sample code within this documentation is made available under a modified MIT license. See the LICENSE-SAMPLECODE file. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Amazon Rekognition Developer Guide 2 | 3 | The open source version of the Amazon Rekognition docs. You can submit feedback & requests for changes by submitting issues in this repo or by making proposed changes & submitting a pull request. 4 | 5 | ## License Summary 6 | 7 | The documentation is made available under the Creative Commons Attribution-ShareAlike 4.0 International License. See the LICENSE file. 8 | 9 | The sample code within this documentation is made available under a modified MIT license. See the LICENSE-SAMPLECODE file. 10 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/README.md: -------------------------------------------------------------------------------- 1 | .. Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 4 | International License (the "License"). You may not use this file except in compliance with the 5 | License. A copy of the License is located at http://creativecommons.org/licenses/by-nc-sa/4.0/. 6 | 7 | This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 | either express or implied. See the License for the specific language governing permissions and 9 | limitations under the License. 10 | 11 | 12 | 13 | Amazon Rekognition Documentation .NET Examples 14 | ============================================== 15 | 16 | These are the .NET examples used in the [Amazon Rekognition developer documentation](https://aws.amazon.com/documentation/rekognition/). 17 | 18 | Prerequisites 19 | ============= 20 | 21 | To build and run these examples, you'll need: 22 | 23 | 24 | * AWS credentials, either configured in a local AWS credentials file or by setting the 25 | ``AWS_ACCESS_KEY_ID`` and ``AWS_SECRET_ACCESS_KEY`` environment variables. 26 | * You should also set the *AWS region* within which the operations will be performed. If a region is 27 | not set, the default region used will be ``us-east-1``. 28 | 29 | For information about how to set AWS credentials and the region for use with the AWS SDK for .NET, 30 | see [Configuring Your AWS SDK for .NET Application](https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config.html). 31 | 32 | Running the examples 33 | ==================== 34 | Open the solution corresponding to the service for which you wish to run examples in Visual Studio. 35 | 36 | Compile and run the solution. 37 | 38 | An IAM user with the following IAM permissions can call every example: 39 | * AmazonRekognitionFullAccess 40 | * AmazonS3ReadOnlyAccess 41 | * AmazonSQSFullAccess 42 | 43 | Depending on the AWS operations that you are calling, you can further restrict access. For more 44 | information, see [Amazon Rekognition API Permissions: Actions, Permissions, and Resources Reference](https://docs.aws.amazon.com/rekognition/latest/dg/api-permissions-reference.html). 45 | 46 | **IMPORTANT** 47 | 48 | The examples perform AWS operations for the account and region for which you've specified 49 | credentials, and you may incur AWS service charges by running them. Please visit the 50 | [AWS Pricing](https://aws.amazon.com/pricing/) page for details about the charges you can expect for a given service and operation. 51 | 52 | Some of these examples perform *destructive* operations on AWS resources, such as deleting an 53 | Amazon Rekognition collection. **Be very careful** when running an operation that 54 | may delete or modify AWS resources in your account. It's best to create separate test-only 55 | resources when experimenting with these examples. 56 | 57 | Many of the examples require configuration before they can be run. For example, to call 58 | DetectLabels, you have to specify the source image. The source code comments and service 59 | documentation provide further information. 60 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-add-faces.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using Amazon.Rekognition; 7 | using Amazon.Rekognition.Model; 8 | 9 | public class AddFaces 10 | { 11 | public static void Example() 12 | { 13 | String collectionId = "MyCollection"; 14 | String bucket = "bucket"; 15 | String photo = "input.jpg"; 16 | 17 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 18 | 19 | Image image = new Image() 20 | { 21 | S3Object = new S3Object() 22 | { 23 | Bucket = bucket, 24 | Name = photo 25 | } 26 | }; 27 | 28 | IndexFacesRequest indexFacesRequest = new IndexFacesRequest() 29 | { 30 | Image = image, 31 | CollectionId = collectionId, 32 | ExternalImageId = photo, 33 | DetectionAttributes = new List(){ "ALL" } 34 | }; 35 | 36 | IndexFacesResponse indexFacesResponse = rekognitionClient.IndexFaces(indexFacesRequest); 37 | 38 | Console.WriteLine(photo + " added"); 39 | foreach (FaceRecord faceRecord in indexFacesResponse.FaceRecords) 40 | Console.WriteLine("Face detected: Faceid is " + 41 | faceRecord.Face.FaceId); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-celebrities-in-image.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using System.IO; 6 | using Amazon.Rekognition; 7 | using Amazon.Rekognition.Model; 8 | 9 | public class CelebritiesInImage 10 | { 11 | public static void Example() 12 | { 13 | String photo = "moviestars.jpg"; 14 | 15 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 16 | 17 | RecognizeCelebritiesRequest recognizeCelebritiesRequest = new RecognizeCelebritiesRequest(); 18 | 19 | Amazon.Rekognition.Model.Image img = new Amazon.Rekognition.Model.Image(); 20 | byte[] data = null; 21 | try 22 | { 23 | using (FileStream fs = new FileStream(photo, FileMode.Open, FileAccess.Read)) 24 | { 25 | data = new byte[fs.Length]; 26 | fs.Read(data, 0, (int)fs.Length); 27 | } 28 | } 29 | catch(Exception) 30 | { 31 | Console.WriteLine("Failed to load file " + photo); 32 | return; 33 | } 34 | 35 | img.Bytes = new MemoryStream(data); 36 | recognizeCelebritiesRequest.Image = img; 37 | 38 | Console.WriteLine("Looking for celebrities in image " + photo + "\n"); 39 | 40 | RecognizeCelebritiesResponse recognizeCelebritiesResponse = rekognitionClient.RecognizeCelebrities(recognizeCelebritiesRequest); 41 | 42 | Console.WriteLine(recognizeCelebritiesResponse.CelebrityFaces.Count + " celebrity(s) were recognized.\n"); 43 | foreach (Celebrity celebrity in recognizeCelebritiesResponse.CelebrityFaces) 44 | { 45 | Console.WriteLine("Celebrity recognized: " + celebrity.Name); 46 | Console.WriteLine("Celebrity ID: " + celebrity.Id); 47 | BoundingBox boundingBox = celebrity.Face.BoundingBox; 48 | Console.WriteLine("position: " + 49 | boundingBox.Left + " " + boundingBox.Top); 50 | Console.WriteLine("Further information (if available):"); 51 | foreach (String url in celebrity.Urls) 52 | Console.WriteLine(url); 53 | } 54 | Console.WriteLine(recognizeCelebritiesResponse.UnrecognizedFaces.Count + " face(s) were unrecognized."); 55 | } 56 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-celebrity-info.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | 9 | public class CelebrityInfo 10 | { 11 | public static void Example() 12 | { 13 | String id = "nnnnnnnn"; 14 | 15 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 16 | 17 | GetCelebrityInfoRequest celebrityInfoRequest = new GetCelebrityInfoRequest() 18 | { 19 | Id = id 20 | }; 21 | 22 | Console.WriteLine("Getting information for celebrity: " + id); 23 | 24 | GetCelebrityInfoResponse celebrityInfoResponse = rekognitionClient.GetCelebrityInfo(celebrityInfoRequest); 25 | 26 | //Display celebrity information 27 | Console.WriteLine("celebrity name: " + celebrityInfoResponse.Name); 28 | Console.WriteLine("Further information (if available):"); 29 | foreach (String url in celebrityInfoResponse.Urls) 30 | Console.WriteLine(url); 31 | } 32 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-compare-faces.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using System.IO; 6 | using Amazon.Rekognition; 7 | using Amazon.Rekognition.Model; 8 | 9 | public class CompareFaces 10 | { 11 | public static void Example() 12 | { 13 | float similarityThreshold = 70F; 14 | String sourceImage = "source.jpg"; 15 | String targetImage = "target.jpg"; 16 | 17 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 18 | 19 | Amazon.Rekognition.Model.Image imageSource = new Amazon.Rekognition.Model.Image(); 20 | try 21 | { 22 | using (FileStream fs = new FileStream(sourceImage, FileMode.Open, FileAccess.Read)) 23 | { 24 | byte[] data = new byte[fs.Length]; 25 | fs.Read(data, 0, (int)fs.Length); 26 | imageSource.Bytes = new MemoryStream(data); 27 | } 28 | } 29 | catch (Exception) 30 | { 31 | Console.WriteLine("Failed to load source image: " + sourceImage); 32 | return; 33 | } 34 | 35 | Amazon.Rekognition.Model.Image imageTarget = new Amazon.Rekognition.Model.Image(); 36 | try 37 | { 38 | using (FileStream fs = new FileStream(targetImage, FileMode.Open, FileAccess.Read)) 39 | { 40 | byte[] data = new byte[fs.Length]; 41 | data = new byte[fs.Length]; 42 | fs.Read(data, 0, (int)fs.Length); 43 | imageTarget.Bytes = new MemoryStream(data); 44 | } 45 | } 46 | catch (Exception) 47 | { 48 | Console.WriteLine("Failed to load target image: " + targetImage); 49 | return; 50 | } 51 | 52 | CompareFacesRequest compareFacesRequest = new CompareFacesRequest() 53 | { 54 | SourceImage = imageSource, 55 | TargetImage = imageTarget, 56 | SimilarityThreshold = similarityThreshold 57 | }; 58 | 59 | // Call operation 60 | CompareFacesResponse compareFacesResponse = rekognitionClient.CompareFaces(compareFacesRequest); 61 | 62 | // Display results 63 | foreach(CompareFacesMatch match in compareFacesResponse.FaceMatches) 64 | { 65 | ComparedFace face = match.Face; 66 | BoundingBox position = face.BoundingBox; 67 | Console.WriteLine("Face at " + position.Left 68 | + " " + position.Top 69 | + " matches with " + face.Confidence 70 | + "% confidence."); 71 | } 72 | 73 | Console.WriteLine("There was " + compareFacesResponse.UnmatchedFaces.Count + " face(s) that did not match"); 74 | Console.WriteLine("Source image rotation: " + compareFacesResponse.SourceImageOrientationCorrection); 75 | Console.WriteLine("Target image rotation: " + compareFacesResponse.TargetImageOrientationCorrection); 76 | } 77 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-create-collection.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class CreateCollection 9 | { 10 | public static void Example() 11 | { 12 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 13 | 14 | String collectionId = "MyCollection"; 15 | Console.WriteLine("Creating collection: " + collectionId); 16 | 17 | CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest() 18 | { 19 | CollectionId = collectionId 20 | }; 21 | 22 | CreateCollectionResponse createCollectionResponse = rekognitionClient.CreateCollection(createCollectionRequest); 23 | Console.WriteLine("CollectionArn : " + createCollectionResponse.CollectionArn); 24 | Console.WriteLine("Status code : " + createCollectionResponse.StatusCode); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-delete-collection.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class DeleteCollection 9 | { 10 | public static void Example() 11 | { 12 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 13 | 14 | String collectionId = "MyCollection"; 15 | Console.WriteLine("Deleting collection: " + collectionId); 16 | 17 | DeleteCollectionRequest deleteCollectionRequest = new DeleteCollectionRequest() 18 | { 19 | CollectionId = collectionId 20 | }; 21 | 22 | DeleteCollectionResponse deleteCollectionResponse = rekognitionClient.DeleteCollection(deleteCollectionRequest); 23 | Console.WriteLine(collectionId + ": " + deleteCollectionResponse.StatusCode); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-delete-faces.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using Amazon.Rekognition; 7 | using Amazon.Rekognition.Model; 8 | 9 | public class DeleteFaces 10 | { 11 | public static void Example() 12 | { 13 | String collectionId = "MyCollection"; 14 | List faces = new List() { "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }; 15 | 16 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 17 | 18 | DeleteFacesRequest deleteFacesRequest = new DeleteFacesRequest() 19 | { 20 | CollectionId = collectionId, 21 | FaceIds = faces 22 | }; 23 | 24 | DeleteFacesResponse deleteFacesResponse = rekognitionClient.DeleteFaces(deleteFacesRequest); 25 | foreach (String face in deleteFacesResponse.DeletedFaces) 26 | Console.WriteLine("FaceID: " + face); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-detect-faces.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using Amazon.Rekognition; 7 | using Amazon.Rekognition.Model; 8 | 9 | public class DetectFaces 10 | { 11 | public static void Example() 12 | { 13 | String photo = "input.jpg"; 14 | String bucket = "bucket"; 15 | 16 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 17 | 18 | DetectFacesRequest detectFacesRequest = new DetectFacesRequest() 19 | { 20 | Image = new Image() 21 | { 22 | S3Object = new S3Object() 23 | { 24 | Name = photo, 25 | Bucket = bucket 26 | }, 27 | }, 28 | // Attributes can be "ALL" or "DEFAULT". 29 | // "DEFAULT": BoundingBox, Confidence, Landmarks, Pose, and Quality. 30 | // "ALL": See https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Rekognition/TFaceDetail.html 31 | Attributes = new List() { "ALL" } 32 | }; 33 | 34 | try 35 | { 36 | DetectFacesResponse detectFacesResponse = rekognitionClient.DetectFaces(detectFacesRequest); 37 | bool hasAll = detectFacesRequest.Attributes.Contains("ALL"); 38 | foreach(FaceDetail face in detectFacesResponse.FaceDetails) 39 | { 40 | Console.WriteLine("BoundingBox: top={0} left={1} width={2} height={3}", face.BoundingBox.Left, 41 | face.BoundingBox.Top, face.BoundingBox.Width, face.BoundingBox.Height); 42 | Console.WriteLine("Confidence: {0}\nLandmarks: {1}\nPose: pitch={2} roll={3} yaw={4}\nQuality: {5}", 43 | face.Confidence, face.Landmarks.Count, face.Pose.Pitch, 44 | face.Pose.Roll, face.Pose.Yaw, face.Quality); 45 | if (hasAll) 46 | Console.WriteLine("The detected face is estimated to be between " + 47 | face.AgeRange.Low + " and " + face.AgeRange.High + " years old."); 48 | } 49 | } 50 | catch (Exception e) 51 | { 52 | Console.WriteLine(e.Message); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-detect-labels-local-file.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using System.IO; 6 | using Amazon.Rekognition; 7 | using Amazon.Rekognition.Model; 8 | 9 | public class DetectLabelsLocalfile 10 | { 11 | public static void Example() 12 | { 13 | String photo = "input.jpg"; 14 | 15 | Amazon.Rekognition.Model.Image image = new Amazon.Rekognition.Model.Image(); 16 | try 17 | { 18 | using (FileStream fs = new FileStream(photo, FileMode.Open, FileAccess.Read)) 19 | { 20 | byte[] data = null; 21 | data = new byte[fs.Length]; 22 | fs.Read(data, 0, (int)fs.Length); 23 | image.Bytes = new MemoryStream(data); 24 | } 25 | } 26 | catch (Exception) 27 | { 28 | Console.WriteLine("Failed to load file " + photo); 29 | return; 30 | } 31 | 32 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 33 | 34 | DetectLabelsRequest detectlabelsRequest = new DetectLabelsRequest() 35 | { 36 | Image = image, 37 | MaxLabels = 10, 38 | MinConfidence = 77F 39 | }; 40 | 41 | try 42 | { 43 | DetectLabelsResponse detectLabelsResponse = rekognitionClient.DetectLabels(detectlabelsRequest); 44 | Console.WriteLine("Detected labels for " + photo); 45 | foreach (Label label in detectLabelsResponse.Labels) 46 | Console.WriteLine("{0}: {1}", label.Name, label.Confidence); 47 | } 48 | catch (Exception e) 49 | { 50 | Console.WriteLine(e.Message); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-detect-labels.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class DetectLabels 9 | { 10 | public static void Example() 11 | { 12 | String photo = "input.jpg"; 13 | String bucket = "bucket"; 14 | 15 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 16 | 17 | DetectLabelsRequest detectlabelsRequest = new DetectLabelsRequest() 18 | { 19 | Image = new Image() 20 | { 21 | S3Object = new S3Object() 22 | { 23 | Name = photo, 24 | Bucket = bucket 25 | }, 26 | }, 27 | MaxLabels = 10, 28 | MinConfidence = 75F 29 | }; 30 | 31 | try 32 | { 33 | DetectLabelsResponse detectLabelsResponse = rekognitionClient.DetectLabels(detectlabelsRequest); 34 | Console.WriteLine("Detected labels for " + photo); 35 | foreach (Label label in detectLabelsResponse.Labels) 36 | Console.WriteLine("{0}: {1}", label.Name, label.Confidence); 37 | } 38 | catch (Exception e) 39 | { 40 | Console.WriteLine(e.Message); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-detect-moderation-labels.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class DetectModerationLabels 9 | { 10 | public static void Example() 11 | { 12 | String photo = "input.jpg"; 13 | String bucket = "bucket"; 14 | 15 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 16 | 17 | DetectModerationLabelsRequest detectModerationLabelsRequest = new DetectModerationLabelsRequest() 18 | { 19 | Image = new Image() 20 | { 21 | S3Object = new S3Object() 22 | { 23 | Name = photo, 24 | Bucket = bucket 25 | }, 26 | }, 27 | MinConfidence = 60F 28 | }; 29 | 30 | try 31 | { 32 | DetectModerationLabelsResponse detectModerationLabelsResponse = rekognitionClient.DetectModerationLabels(detectModerationLabelsRequest); 33 | Console.WriteLine("Detected labels for " + photo); 34 | foreach (ModerationLabel label in detectModerationLabelsResponse.ModerationLabels) 35 | Console.WriteLine("Label: {0}\n Confidence: {1}\n Parent: {2}", 36 | label.Name, label.Confidence, label.ParentName); 37 | } 38 | catch (Exception e) 39 | { 40 | Console.WriteLine(e.Message); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-detect-text.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class DetectText 9 | { 10 | public static void Example() 11 | { 12 | String photo = "input.jpg"; 13 | String bucket = "bucket"; 14 | 15 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 16 | 17 | DetectTextRequest detectTextRequest = new DetectTextRequest() 18 | { 19 | Image = new Image() 20 | { 21 | S3Object = new S3Object() 22 | { 23 | Name = photo, 24 | Bucket = bucket 25 | } 26 | } 27 | }; 28 | 29 | try 30 | { 31 | DetectTextResponse detectTextResponse = rekognitionClient.DetectText(detectTextRequest); 32 | Console.WriteLine("Detected lines and words for " + photo); 33 | foreach (TextDetection text in detectTextResponse.TextDetections) 34 | { 35 | Console.WriteLine("Detected: " + text.DetectedText); 36 | Console.WriteLine("Confidence: " + text.Confidence); 37 | Console.WriteLine("Id : " + text.Id); 38 | Console.WriteLine("Parent Id: " + text.ParentId); 39 | Console.WriteLine("Type: " + text.Type); 40 | } 41 | } 42 | catch (Exception e) 43 | { 44 | Console.WriteLine(e.Message); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-list-collections.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class ListCollections 9 | { 10 | public static void Example() 11 | { 12 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 13 | 14 | Console.WriteLine("Listing collections"); 15 | int limit = 10; 16 | 17 | ListCollectionsResponse listCollectionsResponse = null; 18 | String paginationToken = null; 19 | do 20 | { 21 | if (listCollectionsResponse != null) 22 | paginationToken = listCollectionsResponse.NextToken; 23 | 24 | ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest() 25 | { 26 | MaxResults = limit, 27 | NextToken = paginationToken 28 | }; 29 | 30 | listCollectionsResponse = rekognitionClient.ListCollections(listCollectionsRequest); 31 | 32 | foreach (String resultId in listCollectionsResponse.CollectionIds) 33 | Console.WriteLine(resultId); 34 | } while (listCollectionsResponse != null && listCollectionsResponse.NextToken != null); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-list-faces.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class ListFaces 9 | { 10 | public static void Example() 11 | { 12 | String collectionId = "MyCollection"; 13 | 14 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 15 | 16 | ListFacesResponse listFacesResponse = null; 17 | Console.WriteLine("Faces in collection " + collectionId); 18 | 19 | String paginationToken = null; 20 | do 21 | { 22 | if (listFacesResponse != null) 23 | paginationToken = listFacesResponse.NextToken; 24 | 25 | ListFacesRequest listFacesRequest = new ListFacesRequest() 26 | { 27 | CollectionId = collectionId, 28 | MaxResults = 1, 29 | NextToken = paginationToken 30 | }; 31 | 32 | listFacesResponse = rekognitionClient.ListFaces(listFacesRequest); 33 | foreach(Face face in listFacesResponse.Faces) 34 | Console.WriteLine(face.FaceId); 35 | } while (listFacesResponse != null && !String.IsNullOrEmpty(listFacesResponse.NextToken)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-search-faces-matching-id.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class SearchFacesMatchingId 9 | { 10 | public static void Example() 11 | { 12 | String collectionId = "MyCollection"; 13 | String faceId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; 14 | 15 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 16 | 17 | // Search collection for faces matching the face id. 18 | 19 | SearchFacesRequest searchFacesRequest = new SearchFacesRequest() 20 | { 21 | CollectionId = collectionId, 22 | FaceId = faceId, 23 | FaceMatchThreshold = 70F, 24 | MaxFaces = 2 25 | }; 26 | 27 | SearchFacesResponse searchFacesResponse = rekognitionClient.SearchFaces(searchFacesRequest); 28 | 29 | Console.WriteLine("Face matching faceId " + faceId); 30 | 31 | Console.WriteLine("Matche(s): "); 32 | foreach (FaceMatch face in searchFacesResponse.FaceMatches) 33 | Console.WriteLine("FaceId: " + face.Face.FaceId + ", Similarity: " + face.Similarity); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /code_examples/dotnet_examples/image/net-search-faces-matching-image.cs: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | using System; 5 | using Amazon.Rekognition; 6 | using Amazon.Rekognition.Model; 7 | 8 | public class SearchFacesMatchingImage 9 | { 10 | public static void Example() 11 | { 12 | String collectionId = "MyCollection"; 13 | String bucket = "bucket"; 14 | String photo = "input.jpg"; 15 | 16 | AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); 17 | 18 | // Get an image object from S3 bucket. 19 | Image image = new Image() 20 | { 21 | S3Object = new S3Object() 22 | { 23 | Bucket = bucket, 24 | Name = photo 25 | } 26 | }; 27 | 28 | SearchFacesByImageRequest searchFacesByImageRequest = new SearchFacesByImageRequest() 29 | { 30 | CollectionId = collectionId, 31 | Image = image, 32 | FaceMatchThreshold = 70F, 33 | MaxFaces = 2 34 | }; 35 | 36 | SearchFacesByImageResponse searchFacesByImageResponse = rekognitionClient.SearchFacesByImage(searchFacesByImageRequest); 37 | 38 | Console.WriteLine("Faces matching largest face in image from " + photo); 39 | foreach (FaceMatch face in searchFacesByImageResponse.FaceMatches) 40 | Console.WriteLine("FaceId: " + face.Face.FaceId + ", Similarity: " + face.Similarity); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /code_examples/java_examples/README.md: -------------------------------------------------------------------------------- 1 | .. Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 4 | International License (the "License"). You may not use this file except in compliance with the 5 | License. A copy of the License is located at http://creativecommons.org/licenses/by-nc-sa/4.0/. 6 | 7 | This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 | either express or implied. See the License for the specific language governing permissions and 9 | limitations under the License. 10 | 11 | 12 | 13 | Amazon Rekognition Documentation Java Examples 14 | ============================================== 15 | 16 | These are the Java examples used in the [Amazon Rekognition developer documentation](https://aws.amazon.com/documentation/rekognition/). 17 | 18 | Prerequisites 19 | ============= 20 | 21 | To build and run these examples, you'll need: 22 | 23 | * [AWS SDK for Java](https://aws.amazon.com/sdk-for-java/) (downloaded and extracted somewhere on 24 | your machine) 25 | * AWS credentials, either configured in a local AWS credentials file or by setting the 26 | ``AWS_ACCESS_KEY_ID`` and ``AWS_SECRET_ACCESS_KEY`` environment variables. 27 | * You should also set the *AWS region* within which the operations will be performed. If a region is 28 | not set, the default region used will be ``us-east-1``. 29 | 30 | For information about how to set AWS credentials and the region for use with the AWS SDK for Java, 31 | see [Set up AWS Credentials and Region for Development](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html). 32 | 33 | Running the examples 34 | ==================== 35 | 36 | To run the java examples you will need to create a Java project in your preferred Java 37 | development environment. For more information, see [Getting Started](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/getting-started.html). You can also 38 | use the [AWS Toolkit for Eclipse](https://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/welcome.html). 39 | 40 | An IAM user with the following IAM permissions can call every example: 41 | * AmazonRekognitionFullAccess 42 | * AmazonS3ReadOnlyAccess 43 | * AmazonSQSFullAccess 44 | 45 | Depending on the AWS operations that you are calling, you can further restrict access. For more 46 | information, see [Amazon Rekognition API Permissions: Actions, Permissions, and Resources Reference](https://docs.aws.amazon.com/rekognition/latest/dg/api-permissions-reference.html). 47 | 48 | **IMPORTANT** 49 | 50 | The examples perform AWS operations for the account and region for which you've specified 51 | credentials, and you may incur AWS service charges by running them. Please visit the 52 | [AWS Pricing](https://aws.amazon.com/pricing/) page for details about the charges you can expect for a given service and operation. 53 | 54 | Some of these examples perform *destructive* operations on AWS resources, such as deleting an 55 | Amazon Rekognition collection. **Be very careful** when running an operation that 56 | may delete or modify AWS resources in your account. It's best to create separate test-only 57 | resources when experimenting with these examples. 58 | 59 | Many of the examples require configuration before they can be run. For example, to run 60 | DetectLabels you have to specify the source image. The source code comments and service 61 | documentation provide further information. 62 | -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-add-faces-to-collection.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | 6 | import com.amazonaws.services.rekognition.AmazonRekognition; 7 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 8 | import com.amazonaws.services.rekognition.model.FaceRecord; 9 | import com.amazonaws.services.rekognition.model.Image; 10 | import com.amazonaws.services.rekognition.model.IndexFacesRequest; 11 | import com.amazonaws.services.rekognition.model.IndexFacesResult; 12 | import com.amazonaws.services.rekognition.model.S3Object; 13 | import com.amazonaws.services.rekognition.model.UnindexedFace; 14 | import java.util.List; 15 | 16 | public class AddFacesToCollection { 17 | public static final String collectionId = "MyCollection"; 18 | public static final String bucket = "bucket"; 19 | public static final String photo = "input.jpg"; 20 | 21 | public static void main(String[] args) throws Exception { 22 | 23 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 24 | 25 | Image image = new Image() 26 | .withS3Object(new S3Object() 27 | .withBucket(bucket) 28 | .withName(photo)); 29 | 30 | IndexFacesRequest indexFacesRequest = new IndexFacesRequest() 31 | .withImage(image) 32 | .withQualityFilter(QualityFilter.AUTO) 33 | .withMaxFaces(1) 34 | .withCollectionId(collectionId) 35 | .withExternalImageId(photo) 36 | .withDetectionAttributes("DEFAULT"); 37 | 38 | IndexFacesResult indexFacesResult = rekognitionClient.indexFaces(indexFacesRequest); 39 | 40 | System.out.println("Results for " + photo); 41 | System.out.println("Faces indexed:"); 42 | List faceRecords = indexFacesResult.getFaceRecords(); 43 | for (FaceRecord faceRecord : faceRecords) { 44 | System.out.println(" Face ID: " + faceRecord.getFace().getFaceId()); 45 | System.out.println(" Location:" + faceRecord.getFaceDetail().getBoundingBox().toString()); 46 | } 47 | 48 | List unindexedFaces = indexFacesResult.getUnindexedFaces(); 49 | System.out.println("Faces not indexed:"); 50 | for (UnindexedFace unindexedFace : unindexedFaces) { 51 | System.out.println(" Location:" + unindexedFace.getFaceDetail().getBoundingBox().toString()); 52 | System.out.println(" Reasons:"); 53 | for (String reason : unindexedFace.getReasons()) { 54 | System.out.println(" " + reason); 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-celebrity-info.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | import com.amazonaws.services.rekognition.AmazonRekognition; 6 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 7 | import com.amazonaws.services.rekognition.model.GetCelebrityInfoRequest; 8 | import com.amazonaws.services.rekognition.model.GetCelebrityInfoResult; 9 | 10 | 11 | public class CelebrityInfo { 12 | 13 | public static void main(String[] args) { 14 | String id = "nnnnnnnn"; 15 | 16 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 17 | 18 | GetCelebrityInfoRequest request = new GetCelebrityInfoRequest() 19 | .withId(id); 20 | 21 | System.out.println("Getting information for celebrity: " + id); 22 | 23 | GetCelebrityInfoResult result=rekognitionClient.getCelebrityInfo(request); 24 | 25 | //Display celebrity information 26 | System.out.println("celebrity name: " + result.getName()); 27 | System.out.println("Further information (if available):"); 28 | for (String url: result.getUrls()){ 29 | System.out.println(url); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-compare-faces.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | import com.amazonaws.services.rekognition.AmazonRekognition; 6 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 7 | import com.amazonaws.services.rekognition.model.Image; 8 | import com.amazonaws.services.rekognition.model.BoundingBox; 9 | import com.amazonaws.services.rekognition.model.CompareFacesMatch; 10 | import com.amazonaws.services.rekognition.model.CompareFacesRequest; 11 | import com.amazonaws.services.rekognition.model.CompareFacesResult; 12 | import com.amazonaws.services.rekognition.model.ComparedFace; 13 | import java.util.List; 14 | import java.io.File; 15 | import java.io.FileInputStream; 16 | import java.io.InputStream; 17 | import java.nio.ByteBuffer; 18 | import com.amazonaws.util.IOUtils; 19 | 20 | public class CompareFaces { 21 | 22 | public static void main(String[] args) throws Exception{ 23 | Float similarityThreshold = 70F; 24 | String sourceImage = "source.jpg"; 25 | String targetImage = "target.jpg"; 26 | ByteBuffer sourceImageBytes=null; 27 | ByteBuffer targetImageBytes=null; 28 | 29 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 30 | 31 | //Load source and target images and create input parameters 32 | try (InputStream inputStream = new FileInputStream(new File(sourceImage))) { 33 | sourceImageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream)); 34 | } 35 | catch(Exception e) 36 | { 37 | System.out.println("Failed to load source image " + sourceImage); 38 | System.exit(1); 39 | } 40 | try (InputStream inputStream = new FileInputStream(new File(targetImage))) { 41 | targetImageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream)); 42 | } 43 | catch(Exception e) 44 | { 45 | System.out.println("Failed to load target images: " + targetImage); 46 | System.exit(1); 47 | } 48 | 49 | Image source=new Image() 50 | .withBytes(sourceImageBytes); 51 | Image target=new Image() 52 | .withBytes(targetImageBytes); 53 | 54 | CompareFacesRequest request = new CompareFacesRequest() 55 | .withSourceImage(source) 56 | .withTargetImage(target) 57 | .withSimilarityThreshold(similarityThreshold); 58 | 59 | // Call operation 60 | CompareFacesResult compareFacesResult=rekognitionClient.compareFaces(request); 61 | 62 | 63 | // Display results 64 | List faceDetails = compareFacesResult.getFaceMatches(); 65 | for (CompareFacesMatch match: faceDetails){ 66 | ComparedFace face= match.getFace(); 67 | BoundingBox position = face.getBoundingBox(); 68 | System.out.println("Face at " + position.getLeft().toString() 69 | + " " + position.getTop() 70 | + " matches with " + face.getConfidence().toString() 71 | + "% confidence."); 72 | 73 | } 74 | List uncompared = compareFacesResult.getUnmatchedFaces(); 75 | 76 | System.out.println("There was " + uncompared.size() 77 | + " face(s) that did not match"); 78 | System.out.println("Source image rotation: " + compareFacesResult.getSourceImageOrientationCorrection()); 79 | System.out.println("target image rotation: " + compareFacesResult.getTargetImageOrientationCorrection()); 80 | } 81 | } -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-create-collection.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | 6 | import com.amazonaws.services.rekognition.AmazonRekognition; 7 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 8 | import com.amazonaws.services.rekognition.model.CreateCollectionRequest; 9 | import com.amazonaws.services.rekognition.model.CreateCollectionResult; 10 | 11 | 12 | public class CreateCollection { 13 | 14 | public static void main(String[] args) throws Exception { 15 | 16 | 17 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 18 | 19 | 20 | String collectionId = "MyCollection"; 21 | System.out.println("Creating collection: " + 22 | collectionId ); 23 | 24 | CreateCollectionRequest request = new CreateCollectionRequest() 25 | .withCollectionId(collectionId); 26 | 27 | CreateCollectionResult createCollectionResult = rekognitionClient.createCollection(request); 28 | System.out.println("CollectionArn : " + 29 | createCollectionResult.getCollectionArn()); 30 | System.out.println("Status code : " + 31 | createCollectionResult.getStatusCode().toString()); 32 | 33 | } 34 | 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-delete-collection.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | import com.amazonaws.services.rekognition.AmazonRekognition; 6 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 7 | import com.amazonaws.services.rekognition.model.DeleteCollectionRequest; 8 | import com.amazonaws.services.rekognition.model.DeleteCollectionResult; 9 | 10 | 11 | public class DeleteCollection { 12 | 13 | public static void main(String[] args) throws Exception { 14 | 15 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 16 | 17 | String collectionId = "MyCollection"; 18 | 19 | System.out.println("Deleting collections"); 20 | 21 | DeleteCollectionRequest request = new DeleteCollectionRequest() 22 | .withCollectionId(collectionId); 23 | DeleteCollectionResult deleteCollectionResult = rekognitionClient.deleteCollection(request); 24 | 25 | System.out.println(collectionId + ": " + deleteCollectionResult.getStatusCode() 26 | .toString()); 27 | 28 | } 29 | 30 | } 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-delete-faces-from-collection.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | import com.amazonaws.services.rekognition.AmazonRekognition; 6 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 7 | import com.amazonaws.services.rekognition.model.DeleteFacesRequest; 8 | import com.amazonaws.services.rekognition.model.DeleteFacesResult; 9 | 10 | import java.util.List; 11 | 12 | 13 | public class DeleteFacesFromCollection { 14 | public static final String collectionId = "MyCollection"; 15 | public static final String faces[] = {"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}; 16 | 17 | public static void main(String[] args) throws Exception { 18 | 19 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 20 | 21 | 22 | DeleteFacesRequest deleteFacesRequest = new DeleteFacesRequest() 23 | .withCollectionId(collectionId) 24 | .withFaceIds(faces); 25 | 26 | DeleteFacesResult deleteFacesResult=rekognitionClient.deleteFaces(deleteFacesRequest); 27 | 28 | 29 | List < String > faceRecords = deleteFacesResult.getDeletedFaces(); 30 | System.out.println(Integer.toString(faceRecords.size()) + " face(s) deleted:"); 31 | for (String face: faceRecords) { 32 | System.out.println("FaceID: " + face); 33 | } 34 | } 35 | } 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-describe-collection.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package com.amazonaws.samples; 5 | 6 | import com.amazonaws.services.rekognition.AmazonRekognition; 7 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 8 | import com.amazonaws.services.rekognition.model.DescribeCollectionRequest; 9 | import com.amazonaws.services.rekognition.model.DescribeCollectionResult; 10 | 11 | 12 | public class DescribeCollection { 13 | 14 | public static void main(String[] args) throws Exception { 15 | 16 | String collectionId = "CollectionID"; 17 | 18 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 19 | 20 | 21 | System.out.println("Describing collection: " + 22 | collectionId ); 23 | 24 | 25 | DescribeCollectionRequest request = new DescribeCollectionRequest() 26 | .withCollectionId(collectionId); 27 | 28 | DescribeCollectionResult describeCollectionResult = rekognitionClient.describeCollection(request); 29 | System.out.println("Collection Arn : " + 30 | describeCollectionResult.getCollectionARN()); 31 | System.out.println("Face count : " + 32 | describeCollectionResult.getFaceCount().toString()); 33 | System.out.println("Face model version : " + 34 | describeCollectionResult.getFaceModelVersion()); 35 | System.out.println("Created : " + 36 | describeCollectionResult.getCreationTimestamp().toString()); 37 | 38 | } 39 | 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-detect-faces.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | 6 | import com.amazonaws.services.rekognition.AmazonRekognition; 7 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 8 | import com.amazonaws.services.rekognition.model.AmazonRekognitionException; 9 | import com.amazonaws.services.rekognition.model.Image; 10 | import com.amazonaws.services.rekognition.model.S3Object; 11 | import com.amazonaws.services.rekognition.model.AgeRange; 12 | import com.amazonaws.services.rekognition.model.Attribute; 13 | import com.amazonaws.services.rekognition.model.DetectFacesRequest; 14 | import com.amazonaws.services.rekognition.model.DetectFacesResult; 15 | import com.amazonaws.services.rekognition.model.FaceDetail; 16 | import com.fasterxml.jackson.databind.ObjectMapper; 17 | import java.util.List; 18 | 19 | 20 | public class DetectFaces { 21 | 22 | 23 | public static void main(String[] args) throws Exception { 24 | 25 | String photo = "input.jpg"; 26 | String bucket = "bucket"; 27 | 28 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 29 | 30 | 31 | DetectFacesRequest request = new DetectFacesRequest() 32 | .withImage(new Image() 33 | .withS3Object(new S3Object() 34 | .withName(photo) 35 | .withBucket(bucket))) 36 | .withAttributes(Attribute.ALL); 37 | // Replace Attribute.ALL with Attribute.DEFAULT to get default values. 38 | 39 | try { 40 | DetectFacesResult result = rekognitionClient.detectFaces(request); 41 | List < FaceDetail > faceDetails = result.getFaceDetails(); 42 | 43 | for (FaceDetail face: faceDetails) { 44 | if (request.getAttributes().contains("ALL")) { 45 | AgeRange ageRange = face.getAgeRange(); 46 | System.out.println("The detected face is estimated to be between " 47 | + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() 48 | + " years old."); 49 | System.out.println("Here's the complete set of attributes:"); 50 | } else { // non-default attributes have null values. 51 | System.out.println("Here's the default set of attributes:"); 52 | } 53 | 54 | ObjectMapper objectMapper = new ObjectMapper(); 55 | System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face)); 56 | } 57 | 58 | } catch (AmazonRekognitionException e) { 59 | e.printStackTrace(); 60 | } 61 | 62 | } 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /code_examples/java_examples/image/java-detect-labels-local-file.java: -------------------------------------------------------------------------------- 1 | //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) 3 | 4 | package aws.example.rekognition.image; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.InputStream; 8 | import java.nio.ByteBuffer; 9 | import java.util.List; 10 | import com.amazonaws.services.rekognition.AmazonRekognition; 11 | import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; 12 | import com.amazonaws.AmazonClientException; 13 | import com.amazonaws.services.rekognition.model.AmazonRekognitionException; 14 | import com.amazonaws.services.rekognition.model.DetectLabelsRequest; 15 | import com.amazonaws.services.rekognition.model.DetectLabelsResult; 16 | import com.amazonaws.services.rekognition.model.Image; 17 | import com.amazonaws.services.rekognition.model.Label; 18 | import com.amazonaws.util.IOUtils; 19 | 20 | public class DetectLabelsLocalFile { 21 | public static void main(String[] args) throws Exception { 22 | String photo="input.jpg"; 23 | 24 | 25 | ByteBuffer imageBytes; 26 | try (InputStream inputStream = new FileInputStream(new File(photo))) { 27 | imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream)); 28 | } 29 | 30 | 31 | AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); 32 | 33 | DetectLabelsRequest request = new DetectLabelsRequest() 34 | .withImage(new Image() 35 | .withBytes(imageBytes)) 36 | .withMaxLabels(10) 37 | .withMinConfidence(77F); 38 | 39 | try { 40 | 41 | DetectLabelsResult result = rekognitionClient.detectLabels(request); 42 | List