Amazon Rekognition을 사용한 예제 AWS SDK for .NET - AWS SDK for .NET

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Rekognition을 사용한 예제 AWS SDK for .NET

다음 코드 예제는 Amazon Rekognition과 AWS SDK for .NET 함께 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

시나리오는 동일한 서비스 내에서 또는 다른 AWS 서비스와 결합된 상태에서 여러 함수를 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예제입니다.

각 예제에는 전체 소스 코드에 대한 링크가 포함되어 있으며, 여기에서 상황에 맞게 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있습니다.

작업

다음 코드 예시에서는 CompareFaces을 사용하는 방법을 보여 줍니다.

자세한 내용은 이미지 내 얼굴 비교를 참조하세요.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.IO; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to compare faces in two images. /// </summary> public class CompareFaces { public static async Task Main() { float similarityThreshold = 70F; string sourceImage = "source.jpg"; string targetImage = "target.jpg"; var rekognitionClient = new AmazonRekognitionClient(); Amazon.Rekognition.Model.Image imageSource = new Amazon.Rekognition.Model.Image(); try { using FileStream fs = new FileStream(sourceImage, FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); imageSource.Bytes = new MemoryStream(data); } catch (Exception) { Console.WriteLine($"Failed to load source image: {sourceImage}"); return; } Amazon.Rekognition.Model.Image imageTarget = new Amazon.Rekognition.Model.Image(); try { using FileStream fs = new FileStream(targetImage, FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); imageTarget.Bytes = new MemoryStream(data); } catch (Exception ex) { Console.WriteLine($"Failed to load target image: {targetImage}"); Console.WriteLine(ex.Message); return; } var compareFacesRequest = new CompareFacesRequest { SourceImage = imageSource, TargetImage = imageTarget, SimilarityThreshold = similarityThreshold, }; // Call operation var compareFacesResponse = await rekognitionClient.CompareFacesAsync(compareFacesRequest); // Display results compareFacesResponse.FaceMatches.ForEach(match => { ComparedFace face = match.Face; BoundingBox position = face.BoundingBox; Console.WriteLine($"Face at {position.Left} {position.Top} matches with {match.Similarity}% confidence."); }); Console.WriteLine($"Found {compareFacesResponse.UnmatchedFaces.Count} face(s) that did not match."); } }

다음 코드 예시에서는 CreateCollection을 사용하는 방법을 보여 줍니다.

자세한 내용은 컬렉션 생성을 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses Amazon Rekognition to create a collection to which you can add /// faces using the IndexFaces operation. /// </summary> public class CreateCollection { public static async Task Main() { var rekognitionClient = new AmazonRekognitionClient(); string collectionId = "MyCollection"; Console.WriteLine("Creating collection: " + collectionId); var createCollectionRequest = new CreateCollectionRequest { CollectionId = collectionId, }; CreateCollectionResponse createCollectionResponse = await rekognitionClient.CreateCollectionAsync(createCollectionRequest); Console.WriteLine($"CollectionArn : {createCollectionResponse.CollectionArn}"); Console.WriteLine($"Status code : {createCollectionResponse.StatusCode}"); } }

다음 코드 예시에서는 DeleteCollection을 사용하는 방법을 보여 줍니다.

자세한 내용은 컬렉션을 삭제를 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to delete an existing collection. /// </summary> public class DeleteCollection { public static async Task Main() { var rekognitionClient = new AmazonRekognitionClient(); string collectionId = "MyCollection"; Console.WriteLine("Deleting collection: " + collectionId); var deleteCollectionRequest = new DeleteCollectionRequest() { CollectionId = collectionId, }; var deleteCollectionResponse = await rekognitionClient.DeleteCollectionAsync(deleteCollectionRequest); Console.WriteLine($"{collectionId}: {deleteCollectionResponse.StatusCode}"); } }

다음 코드 예시에서는 DeleteFaces을 사용하는 방법을 보여 줍니다.

자세한 내용은 컬렉션에서 얼굴 삭제를 참조하십시오.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Collections.Generic; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to delete one or more faces from /// a Rekognition collection. /// </summary> public class DeleteFaces { public static async Task Main() { string collectionId = "MyCollection"; var faces = new List<string> { "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }; var rekognitionClient = new AmazonRekognitionClient(); var deleteFacesRequest = new DeleteFacesRequest() { CollectionId = collectionId, FaceIds = faces, }; DeleteFacesResponse deleteFacesResponse = await rekognitionClient.DeleteFacesAsync(deleteFacesRequest); deleteFacesResponse.DeletedFaces.ForEach(face => { Console.WriteLine($"FaceID: {face}"); }); } }

다음 코드 예시에서는 DescribeCollection을 사용하는 방법을 보여 줍니다.

자세한 내용은 컬렉션 설명을 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to describe the contents of a /// collection. /// </summary> public class DescribeCollection { public static async Task Main() { var rekognitionClient = new AmazonRekognitionClient(); string collectionId = "MyCollection"; Console.WriteLine($"Describing collection: {collectionId}"); var describeCollectionRequest = new DescribeCollectionRequest() { CollectionId = collectionId, }; var describeCollectionResponse = await rekognitionClient.DescribeCollectionAsync(describeCollectionRequest); Console.WriteLine($"Collection ARN: {describeCollectionResponse.CollectionARN}"); Console.WriteLine($"Face count: {describeCollectionResponse.FaceCount}"); Console.WriteLine($"Face model version: {describeCollectionResponse.FaceModelVersion}"); Console.WriteLine($"Created: {describeCollectionResponse.CreationTimestamp}"); } }

다음 코드 예시에서는 DetectFaces을 사용하는 방법을 보여 줍니다.

자세한 내용은 이미지에서 얼굴 감지를 참조하십시오.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Collections.Generic; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to detect faces within an image /// stored in an Amazon Simple Storage Service (Amazon S3) bucket. /// </summary> public class DetectFaces { public static async Task Main() { string photo = "input.jpg"; string bucket = "bucket"; var rekognitionClient = new AmazonRekognitionClient(); var detectFacesRequest = new DetectFacesRequest() { Image = new Image() { S3Object = new S3Object() { Name = photo, Bucket = bucket, }, }, // Attributes can be "ALL" or "DEFAULT". // "DEFAULT": BoundingBox, Confidence, Landmarks, Pose, and Quality. // "ALL": See https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Rekognition/TFaceDetail.html Attributes = new List<string>() { "ALL" }, }; try { DetectFacesResponse detectFacesResponse = await rekognitionClient.DetectFacesAsync(detectFacesRequest); bool hasAll = detectFacesRequest.Attributes.Contains("ALL"); foreach (FaceDetail face in detectFacesResponse.FaceDetails) { Console.WriteLine($"BoundingBox: top={face.BoundingBox.Left} left={face.BoundingBox.Top} width={face.BoundingBox.Width} height={face.BoundingBox.Height}"); Console.WriteLine($"Confidence: {face.Confidence}"); Console.WriteLine($"Landmarks: {face.Landmarks.Count}"); Console.WriteLine($"Pose: pitch={face.Pose.Pitch} roll={face.Pose.Roll} yaw={face.Pose.Yaw}"); Console.WriteLine($"Brightness: {face.Quality.Brightness}\tSharpness: {face.Quality.Sharpness}"); if (hasAll) { Console.WriteLine($"Estimated age is between {face.AgeRange.Low} and {face.AgeRange.High} years old."); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }

이미지 내 모든 얼굴에 대한 경계 상자 정보를 표시합니다.

using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to display the details of the /// bounding boxes around the faces detected in an image. /// </summary> public class ImageOrientationBoundingBox { public static async Task Main() { string photo = @"D:\Development\AWS-Examples\Rekognition\target.jpg"; // "photo.jpg"; var rekognitionClient = new AmazonRekognitionClient(); var image = new Amazon.Rekognition.Model.Image(); try { using var fs = new FileStream(photo, FileMode.Open, FileAccess.Read); byte[] data = null; data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); image.Bytes = new MemoryStream(data); } catch (Exception) { Console.WriteLine("Failed to load file " + photo); return; } int height; int width; // Used to extract original photo width/height using (var imageBitmap = new Bitmap(photo)) { height = imageBitmap.Height; width = imageBitmap.Width; } Console.WriteLine("Image Information:"); Console.WriteLine(photo); Console.WriteLine("Image Height: " + height); Console.WriteLine("Image Width: " + width); try { var detectFacesRequest = new DetectFacesRequest() { Image = image, Attributes = new List<string>() { "ALL" }, }; DetectFacesResponse detectFacesResponse = await rekognitionClient.DetectFacesAsync(detectFacesRequest); detectFacesResponse.FaceDetails.ForEach(face => { Console.WriteLine("Face:"); ShowBoundingBoxPositions( height, width, face.BoundingBox, detectFacesResponse.OrientationCorrection); Console.WriteLine($"BoundingBox: top={face.BoundingBox.Left} left={face.BoundingBox.Top} width={face.BoundingBox.Width} height={face.BoundingBox.Height}"); Console.WriteLine($"The detected face is estimated to be between {face.AgeRange.Low} and {face.AgeRange.High} years old.\n"); }); } catch (Exception ex) { Console.WriteLine(ex.Message); } } /// <summary> /// Display the bounding box information for an image. /// </summary> /// <param name="imageHeight">The height of the image.</param> /// <param name="imageWidth">The width of the image.</param> /// <param name="box">The bounding box for a face found within the image.</param> /// <param name="rotation">The rotation of the face's bounding box.</param> public static void ShowBoundingBoxPositions(int imageHeight, int imageWidth, BoundingBox box, string rotation) { float left; float top; if (rotation == null) { Console.WriteLine("No estimated orientation. Check Exif data."); return; } // Calculate face position based on image orientation. switch (rotation) { case "ROTATE_0": left = imageWidth * box.Left; top = imageHeight * box.Top; break; case "ROTATE_90": left = imageHeight * (1 - (box.Top + box.Height)); top = imageWidth * box.Left; break; case "ROTATE_180": left = imageWidth - (imageWidth * (box.Left + box.Width)); top = imageHeight * (1 - (box.Top + box.Height)); break; case "ROTATE_270": left = imageHeight * box.Top; top = imageWidth * (1 - box.Left - box.Width); break; default: Console.WriteLine("No estimated orientation information. Check Exif data."); return; } // Display face location information. Console.WriteLine($"Left: {left}"); Console.WriteLine($"Top: {top}"); Console.WriteLine($"Face Width: {imageWidth * box.Width}"); Console.WriteLine($"Face Height: {imageHeight * box.Height}"); } }

다음 코드 예시에서는 DetectLabels을 사용하는 방법을 보여 줍니다.

자세한 내용은 이미지에서 레이블 감지를 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to detect labels within an image /// stored in an Amazon Simple Storage Service (Amazon S3) bucket. /// </summary> public class DetectLabels { public static async Task Main() { string photo = "del_river_02092020_01.jpg"; // "input.jpg"; string bucket = "igsmiths3photos"; // "bucket"; var rekognitionClient = new AmazonRekognitionClient(); var detectlabelsRequest = new DetectLabelsRequest { Image = new Image() { S3Object = new S3Object() { Name = photo, Bucket = bucket, }, }, MaxLabels = 10, MinConfidence = 75F, }; try { DetectLabelsResponse detectLabelsResponse = await rekognitionClient.DetectLabelsAsync(detectlabelsRequest); Console.WriteLine("Detected labels for " + photo); foreach (Label label in detectLabelsResponse.Labels) { Console.WriteLine($"Name: {label.Name} Confidence: {label.Confidence}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }

컴퓨터에 저장된 이미지 파일에서 레이블을 감지합니다.

using System; using System.IO; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to detect labels within an image /// stored locally. /// </summary> public class DetectLabelsLocalFile { public static async Task Main() { string photo = "input.jpg"; var image = new Amazon.Rekognition.Model.Image(); try { using var fs = new FileStream(photo, FileMode.Open, FileAccess.Read); byte[] data = null; data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); image.Bytes = new MemoryStream(data); } catch (Exception) { Console.WriteLine("Failed to load file " + photo); return; } var rekognitionClient = new AmazonRekognitionClient(); var detectlabelsRequest = new DetectLabelsRequest { Image = image, MaxLabels = 10, MinConfidence = 77F, }; try { DetectLabelsResponse detectLabelsResponse = await rekognitionClient.DetectLabelsAsync(detectlabelsRequest); Console.WriteLine($"Detected labels for {photo}"); foreach (Label label in detectLabelsResponse.Labels) { Console.WriteLine($"{label.Name}: {label.Confidence}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }

다음 코드 예시에서는 DetectModerationLabels을 사용하는 방법을 보여 줍니다.

자세한 내용은 부적절한 이미지 감지를 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to detect unsafe content in a /// JPEG or PNG format image. /// </summary> public class DetectModerationLabels { public static async Task Main(string[] args) { string photo = "input.jpg"; string bucket = "bucket"; var rekognitionClient = new AmazonRekognitionClient(); var detectModerationLabelsRequest = new DetectModerationLabelsRequest() { Image = new Image() { S3Object = new S3Object() { Name = photo, Bucket = bucket, }, }, MinConfidence = 60F, }; try { var detectModerationLabelsResponse = await rekognitionClient.DetectModerationLabelsAsync(detectModerationLabelsRequest); Console.WriteLine("Detected labels for " + photo); foreach (ModerationLabel label in detectModerationLabelsResponse.ModerationLabels) { Console.WriteLine($"Label: {label.Name}"); Console.WriteLine($"Confidence: {label.Confidence}"); Console.WriteLine($"Parent: {label.ParentName}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }

다음 코드 예시에서는 DetectText을 사용하는 방법을 보여 줍니다.

자세한 내용은 이미지에서 텍스트 감지를 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to detect text in an image. The /// example was created using the AWS SDK for .NET version 3.7 and .NET /// Core 5.0. /// </summary> public class DetectText { public static async Task Main() { string photo = "Dad_photographer.jpg"; // "input.jpg"; string bucket = "igsmiths3photos"; // "bucket"; var rekognitionClient = new AmazonRekognitionClient(); var detectTextRequest = new DetectTextRequest() { Image = new Image() { S3Object = new S3Object() { Name = photo, Bucket = bucket, }, }, }; try { DetectTextResponse detectTextResponse = await rekognitionClient.DetectTextAsync(detectTextRequest); Console.WriteLine($"Detected lines and words for {photo}"); detectTextResponse.TextDetections.ForEach(text => { Console.WriteLine($"Detected: {text.DetectedText}"); Console.WriteLine($"Confidence: {text.Confidence}"); Console.WriteLine($"Id : {text.Id}"); Console.WriteLine($"Parent Id: {text.ParentId}"); Console.WriteLine($"Type: {text.Type}"); }); } catch (Exception e) { Console.WriteLine(e.Message); } } }

다음 코드 예시에서는 GetCelebrityInfo을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Shows how to use Amazon Rekognition to retrieve information about the /// celebrity identified by the supplied celebrity Id. /// </summary> public class CelebrityInfo { public static async Task Main() { string celebId = "nnnnnnnn"; var rekognitionClient = new AmazonRekognitionClient(); var celebrityInfoRequest = new GetCelebrityInfoRequest { Id = celebId, }; Console.WriteLine($"Getting information for celebrity: {celebId}"); var celebrityInfoResponse = await rekognitionClient.GetCelebrityInfoAsync(celebrityInfoRequest); // Display celebrity information. Console.WriteLine($"celebrity name: {celebrityInfoResponse.Name}"); Console.WriteLine("Further information (if available):"); celebrityInfoResponse.Urls.ForEach(url => { Console.WriteLine(url); }); } }

다음 코드 예시에서는 IndexFaces을 사용하는 방법을 보여 줍니다.

자세한 내용은 컬렉션에 얼굴 추가를 참조하십시오.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Collections.Generic; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to detect faces in an image /// that has been uploaded to an Amazon Simple Storage Service (Amazon S3) /// bucket and then adds the information to a collection. /// </summary> public class AddFaces { public static async Task Main() { string collectionId = "MyCollection2"; string bucket = "doc-example-bucket"; string photo = "input.jpg"; var rekognitionClient = new AmazonRekognitionClient(); var image = new Image { S3Object = new S3Object { Bucket = bucket, Name = photo, }, }; var indexFacesRequest = new IndexFacesRequest { Image = image, CollectionId = collectionId, ExternalImageId = photo, DetectionAttributes = new List<string>() { "ALL" }, }; IndexFacesResponse indexFacesResponse = await rekognitionClient.IndexFacesAsync(indexFacesRequest); Console.WriteLine($"{photo} added"); foreach (FaceRecord faceRecord in indexFacesResponse.FaceRecords) { Console.WriteLine($"Face detected: Faceid is {faceRecord.Face.FaceId}"); } } }

다음 코드 예시에서는 ListCollections을 사용하는 방법을 보여 줍니다.

자세한 내용은 컬렉션 나열을 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses Amazon Rekognition to list the collection IDs in the /// current account. /// </summary> public class ListCollections { public static async Task Main() { var rekognitionClient = new AmazonRekognitionClient(); Console.WriteLine("Listing collections"); int limit = 10; var listCollectionsRequest = new ListCollectionsRequest { MaxResults = limit, }; var listCollectionsResponse = new ListCollectionsResponse(); do { if (listCollectionsResponse is not null) { listCollectionsRequest.NextToken = listCollectionsResponse.NextToken; } listCollectionsResponse = await rekognitionClient.ListCollectionsAsync(listCollectionsRequest); listCollectionsResponse.CollectionIds.ForEach(id => { Console.WriteLine(id); }); } while (listCollectionsResponse.NextToken is not null); } }

다음 코드 예시에서는 ListFaces을 사용하는 방법을 보여 줍니다.

자세한 내용은 컬렉션에서 얼굴 나열을 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to retrieve the list of faces /// stored in a collection. /// </summary> public class ListFaces { public static async Task Main() { string collectionId = "MyCollection2"; var rekognitionClient = new AmazonRekognitionClient(); var listFacesResponse = new ListFacesResponse(); Console.WriteLine($"Faces in collection {collectionId}"); var listFacesRequest = new ListFacesRequest { CollectionId = collectionId, MaxResults = 1, }; do { listFacesResponse = await rekognitionClient.ListFacesAsync(listFacesRequest); listFacesResponse.Faces.ForEach(face => { Console.WriteLine(face.FaceId); }); listFacesRequest.NextToken = listFacesResponse.NextToken; } while (!string.IsNullOrEmpty(listFacesResponse.NextToken)); } }

다음 코드 예시에서는 RecognizeCelebrities을 사용하는 방법을 보여 줍니다.

자세한 내용은 유명 인사 인식을 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.IO; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Shows how to use Amazon Rekognition to identify celebrities in a photo. /// </summary> public class CelebritiesInImage { public static async Task Main(string[] args) { string photo = "moviestars.jpg"; var rekognitionClient = new AmazonRekognitionClient(); var recognizeCelebritiesRequest = new RecognizeCelebritiesRequest(); var img = new Amazon.Rekognition.Model.Image(); byte[] data = null; try { using var fs = new FileStream(photo, FileMode.Open, FileAccess.Read); data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); } catch (Exception) { Console.WriteLine($"Failed to load file {photo}"); return; } img.Bytes = new MemoryStream(data); recognizeCelebritiesRequest.Image = img; Console.WriteLine($"Looking for celebrities in image {photo}\n"); var recognizeCelebritiesResponse = await rekognitionClient.RecognizeCelebritiesAsync(recognizeCelebritiesRequest); Console.WriteLine($"{recognizeCelebritiesResponse.CelebrityFaces.Count} celebrity(s) were recognized.\n"); recognizeCelebritiesResponse.CelebrityFaces.ForEach(celeb => { Console.WriteLine($"Celebrity recognized: {celeb.Name}"); Console.WriteLine($"Celebrity ID: {celeb.Id}"); BoundingBox boundingBox = celeb.Face.BoundingBox; Console.WriteLine($"position: {boundingBox.Left} {boundingBox.Top}"); Console.WriteLine("Further information (if available):"); celeb.Urls.ForEach(url => { Console.WriteLine(url); }); }); Console.WriteLine($"{recognizeCelebritiesResponse.UnrecognizedFaces.Count} face(s) were unrecognized."); } }

다음 코드 예시에서는 SearchFaces을 사용하는 방법을 보여 줍니다.

자세한 내용은 얼굴 검색(face ID)을 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to find faces in an image that /// match the face Id provided in the method request. /// </summary> public class SearchFacesMatchingId { public static async Task Main() { string collectionId = "MyCollection"; string faceId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; var rekognitionClient = new AmazonRekognitionClient(); // Search collection for faces matching the face id. var searchFacesRequest = new SearchFacesRequest { CollectionId = collectionId, FaceId = faceId, FaceMatchThreshold = 70F, MaxFaces = 2, }; SearchFacesResponse searchFacesResponse = await rekognitionClient.SearchFacesAsync(searchFacesRequest); Console.WriteLine("Face matching faceId " + faceId); Console.WriteLine("Matche(s): "); searchFacesResponse.FaceMatches.ForEach(face => { Console.WriteLine($"FaceId: {face.Face.FaceId} Similarity: {face.Similarity}"); }); } }

다음 코드 예시에서는 SearchFacesByImage을 사용하는 방법을 보여 줍니다.

자세한 내용은 얼굴(이미지) 검색을 참조하세요.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to search for images matching those /// in a collection. /// </summary> public class SearchFacesMatchingImage { public static async Task Main() { string collectionId = "MyCollection"; string bucket = "bucket"; string photo = "input.jpg"; var rekognitionClient = new AmazonRekognitionClient(); // Get an image object from S3 bucket. var image = new Image() { S3Object = new S3Object() { Bucket = bucket, Name = photo, }, }; var searchFacesByImageRequest = new SearchFacesByImageRequest() { CollectionId = collectionId, Image = image, FaceMatchThreshold = 70F, MaxFaces = 2, }; SearchFacesByImageResponse searchFacesByImageResponse = await rekognitionClient.SearchFacesByImageAsync(searchFacesByImageRequest); Console.WriteLine("Faces matching largest face in image from " + photo); searchFacesByImageResponse.FaceMatches.ForEach(face => { Console.WriteLine($"FaceId: {face.Face.FaceId}, Similarity: {face.Similarity}"); }); } }

시나리오

다음 코드 예시에서는 사용자가 레이블을 사용하여 사진을 관리할 수 있는 서버리스 애플리케이션을 생성하는 방법을 보여줍니다.

AWS SDK for .NET

Amazon Rekognition을 사용하여 이미지에서 레이블을 감지하고 나중에 검색할 수 있도록 저장하는 사진 자산 관리 애플리케이션을 개발하는 방법을 보여줍니다.

전체 소스 코드와 설정 및 실행 방법에 대한 지침은 의 전체 예제를 참조하십시오 GitHub.

이 예제의 출처에 대한 자세한 내용은 AWS  커뮤니티의 게시물을 참조하십시오.

이 예시에서 사용되는 서비스
  • API게이트웨이

  • DynamoDB

  • Lambda

  • Amazon Rekognition

  • Amazon S3

  • 아마존 SNS

다음 코드 예제는 Amazon Rekognition을 사용하여 이미지에서 범주별로 객체를 감지하는 앱을 빌드하는 방법을 보여줍니다.

AWS SDK for .NET

Amazon Rekognition을 사용하는 방법을 보여 줍니다. NETAPIAmazon Rekognition을 사용하여 Amazon Simple S3 (Amazon Simple Storage Service) 버킷에 있는 이미지에서 범주별로 객체를 식별하는 앱을 생성합니다. 앱은 Amazon 심플 이메일 서비스 (AmazonSES) 를 사용하여 결과가 포함된 이메일 알림을 관리자에게 보냅니다.

전체 소스 코드와 설정 및 실행 방법에 대한 지침은 에서 전체 예제를 참조하십시오 GitHub.

이 예시에서 사용되는 서비스
  • Amazon Rekognition

  • Amazon S3

  • 아마존 SES