기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Amazon Rekognition Image는 입력 이미지에서 눈, 코, 입 등 주요 얼굴 특성을 찾는 DetectFaces 작업을 제공합니다. Amazon Rekognition Image는 이미지에서 가장 큰 얼굴 100개를 감지합니다.
입력 이미지를 이미지 바이트 배열(base64 인코딩 이미지 바이트)로 제공하거나 Amazon S3 객체를 지정할 수 있습니다. 이 절차에서는 S3 버킷에 이미지(JPEG 또는 PNG)를 업로드하고 객체 키 이름을 지정합니다.
이미지에서 얼굴 감지
-
아직 설정하지 않았다면 다음과 같이 하세요.
-
AmazonRekognitionFullAccess
권한과AmazonS3ReadOnlyAccess
권한을 가진 사용자를 생성하거나 업데이트합니다. 자세한 내용은 1단계: AWS 계정 설정 및 사용자 생성 단원을 참조하십시오. -
AWS CLI 및 AWS SDKs를 설치하고 구성합니다. 자세한 내용은 2단계: AWS CLI 및 AWS SDKs 설정 단원을 참조하십시오.
-
-
한 개 이상의 얼굴이 포함된 이미지를 S3 버킷에 업로드합니다.
이에 관한 지침은 Amazon Simple Storage Service 사용 설명서에서 Amazon S3에 객체 업로드를 참조하세요.
-
다음 예제를 사용하여
DetectFaces
를 호출합니다.이 예제에서는 감지된 얼굴의 추정 연령 범위를 표시하고 감지된 모든 얼굴 속성의 JSON을 나열합니다.
photo
의 값을 이미지 파일 이름으로 변경합니다.amzn-s3-demo-bucket
의 값을 이미지가 저장된 Amazon S3 버킷으로 변경합니다.//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.AmazonRekognitionException; import com.amazonaws.services.rekognition.model.Image; import com.amazonaws.services.rekognition.model.S3Object; import com.amazonaws.services.rekognition.model.AgeRange; import com.amazonaws.services.rekognition.model.Attribute; import com.amazonaws.services.rekognition.model.DetectFacesRequest; import com.amazonaws.services.rekognition.model.DetectFacesResult; import com.amazonaws.services.rekognition.model.FaceDetail; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; public class DetectFaces { public static void main(String[] args) throws Exception { String photo = "input.jpg"; String bucket = "bucket"; AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); DetectFacesRequest request = new DetectFacesRequest() .withImage(new Image() .withS3Object(new S3Object() .withName(photo) .withBucket(bucket))) .withAttributes(Attribute.ALL); // Replace Attribute.ALL with Attribute.DEFAULT to get default values. try { DetectFacesResult result = rekognitionClient.detectFaces(request); List < FaceDetail > faceDetails = result.getFaceDetails(); for (FaceDetail face: faceDetails) { if (request.getAttributes().contains("ALL")) { AgeRange ageRange = face.getAgeRange(); System.out.println("The detected face is estimated to be between " + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() + " years old."); System.out.println("Here's the complete set of attributes:"); } else { // non-default attributes have null values. System.out.println("Here's the default set of attributes:"); } ObjectMapper objectMapper = new ObjectMapper(); System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face)); } } catch (AmazonRekognitionException e) { e.printStackTrace(); } } }
DetectFaces 작업 요청
DetectFaces
에 대한 입력은 이미지입니다. 이 예제에서는 Amazon S3 버킷에서 이미지를 불러옵니다. Attributes
파라미터는 모든 얼굴 속성을 반환하도록 지정합니다. 자세한 내용은 이미지 작업 단원을 참조하십시오.
{
"Image": {
"S3Object": {
"Bucket": "amzn-s3-demo-bucket",
"Name": "input.jpg"
}
},
"Attributes": [
"ALL"
]
}
DetectFaces 작업 응답
DetectFaces
는 감지된 각 얼굴에 대해 다음 정보를 반환합니다.
-
경계 상자 - 얼굴 주위를 두르는 경계 상자의 좌표.
-
신뢰도 - 경계 상자에 얼굴이 포함될 신뢰도 수준.
-
얼굴 표식 – 얼굴 표식의 배열. 응답은 왼쪽 눈, 오른쪽 눈, 입 같은 각각의 표식의 x, y 좌표를 제공합니다.
-
얼굴 속성 -
FaceDetail
객체로 반환되는, 얼굴의 가려짐 여부와 같은 얼굴 속성의 집합. 이 집합에는 AgeRange, Beard, Emotions, EyeDirection, Eyeglasses, EyesOpen, FaceOccluded, Gender, MouthOpen, Mustache, Smile, Sunglasses가 포함됩니다. 응답은 각 속성의 값을 제공합니다. 이 값은 부울(사람이 선글라스를 착용하고 있는지 아닌지), 문자열(남성인지 여성인지), 각도값(시선 방향의 피치나 요) 등 다양한 유형이 될 수 있습니다. 또한 대부분의 속성의 경우, 응답은 해당 속성에 대해 감지된 값의 신뢰도도 제공합니다. 단, FaceOccluded 속성과 EyeDirection 속성은DetectFaces
를 사용할 때는 지원되지만,StartFaceDetection
및GetFaceDetection
을 사용하여 비디오를 분석할 때는 지원되지 않습니다. -
품질 – 얼굴의 밝기와 선명도를 기술합니다. 최상의 얼굴 감지을 보장하는 것에 관한 내용은 얼굴 비교 입력 이미지에 대한 권장 사항 단원을 참조하십시오.
-
포즈 – 이미지 내 얼굴의 회전을 기술합니다.
요청에는 반환하려는 얼굴 속성의 배열이 표시될 수 있습니다. 얼굴 속성의 DEFAULT
하위 집합(BoundingBox
, Confidence
, Pose
, Quality
, Landmarks
)은 항상 반환됩니다. ["DEFAULT", "FACE_OCCLUDED", "EYE_DIRECTION"]
를 사용하여 특정 얼굴 속성(기본 목록에 더해) 여러 개나 ["FACE_OCCLUDED"]
와 같은 단일 속성의 반환을 요청할 수 있습니다. ["ALL"]
을 사용하여 모든 얼굴 속성의 반환을 요청할 수 있습니다. 더 많은 속성을 요청하면 응답 시간이 늘어날 수 있습니다.
다음은 DetectFaces
API 직접 호출 응답의 예입니다.
{
"FaceDetails": [
{
"BoundingBox": {
"Width": 0.7919622659683228,
"Height": 0.7510867118835449,
"Left": 0.08881539851427078,
"Top": 0.151064932346344
},
"AgeRange": {
"Low": 18,
"High": 26
},
"Smile": {
"Value": false,
"Confidence": 89.77348327636719
},
"Eyeglasses": {
"Value": true,
"Confidence": 99.99996948242188
},
"Sunglasses": {
"Value": true,
"Confidence": 93.65237426757812
},
"Gender": {
"Value": "Female",
"Confidence": 99.85968780517578
},
"Beard": {
"Value": false,
"Confidence": 77.52591705322266
},
"Mustache": {
"Value": false,
"Confidence": 94.48904418945312
},
"EyesOpen": {
"Value": true,
"Confidence": 98.57169342041016
},
"MouthOpen": {
"Value": false,
"Confidence": 74.33953094482422
},
"Emotions": [
{
"Type": "SAD",
"Confidence": 65.56403350830078
},
{
"Type": "CONFUSED",
"Confidence": 31.277774810791016
},
{
"Type": "DISGUSTED",
"Confidence": 15.553778648376465
},
{
"Type": "ANGRY",
"Confidence": 8.012762069702148
},
{
"Type": "SURPRISED",
"Confidence": 7.621500015258789
},
{
"Type": "FEAR",
"Confidence": 7.243380546569824
},
{
"Type": "CALM",
"Confidence": 5.8196024894714355
},
{
"Type": "HAPPY",
"Confidence": 2.2830512523651123
}
],
"Landmarks": [
{
"Type": "eyeLeft",
"X": 0.30225440859794617,
"Y": 0.41018882393836975
},
{
"Type": "eyeRight",
"X": 0.6439348459243774,
"Y": 0.40341562032699585
},
{
"Type": "mouthLeft",
"X": 0.343580037355423,
"Y": 0.6951127648353577
},
{
"Type": "mouthRight",
"X": 0.6306480765342712,
"Y": 0.6898072361946106
},
{
"Type": "nose",
"X": 0.47164231538772583,
"Y": 0.5763645172119141
},
{
"Type": "leftEyeBrowLeft",
"X": 0.1732882857322693,
"Y": 0.34452149271965027
},
{
"Type": "leftEyeBrowRight",
"X": 0.3655243515968323,
"Y": 0.33231860399246216
},
{
"Type": "leftEyeBrowUp",
"X": 0.2671719491481781,
"Y": 0.31669262051582336
},
{
"Type": "rightEyeBrowLeft",
"X": 0.5613729953765869,
"Y": 0.32813435792922974
},
{
"Type": "rightEyeBrowRight",
"X": 0.7665090560913086,
"Y": 0.3318614959716797
},
{
"Type": "rightEyeBrowUp",
"X": 0.6612788438796997,
"Y": 0.3082450032234192
},
{
"Type": "leftEyeLeft",
"X": 0.2416982799768448,
"Y": 0.4085965156555176
},
{
"Type": "leftEyeRight",
"X": 0.36943578720092773,
"Y": 0.41230902075767517
},
{
"Type": "leftEyeUp",
"X": 0.29974061250686646,
"Y": 0.3971870541572571
},
{
"Type": "leftEyeDown",
"X": 0.30360740423202515,
"Y": 0.42347756028175354
},
{
"Type": "rightEyeLeft",
"X": 0.5755768418312073,
"Y": 0.4081145226955414
},
{
"Type": "rightEyeRight",
"X": 0.7050536870956421,
"Y": 0.39924031496047974
},
{
"Type": "rightEyeUp",
"X": 0.642906129360199,
"Y": 0.39026668667793274
},
{
"Type": "rightEyeDown",
"X": 0.6423097848892212,
"Y": 0.41669243574142456
},
{
"Type": "noseLeft",
"X": 0.4122826159000397,
"Y": 0.5987403392791748
},
{
"Type": "noseRight",
"X": 0.5394935011863708,
"Y": 0.5960900187492371
},
{
"Type": "mouthUp",
"X": 0.478581964969635,
"Y": 0.6660456657409668
},
{
"Type": "mouthDown",
"X": 0.483366996049881,
"Y": 0.7497162818908691
},
{
"Type": "leftPupil",
"X": 0.30225440859794617,
"Y": 0.41018882393836975
},
{
"Type": "rightPupil",
"X": 0.6439348459243774,
"Y": 0.40341562032699585
},
{
"Type": "upperJawlineLeft",
"X": 0.11031254380941391,
"Y": 0.3980775475502014
},
{
"Type": "midJawlineLeft",
"X": 0.19301874935626984,
"Y": 0.7034031748771667
},
{
"Type": "chinBottom",
"X": 0.4939905107021332,
"Y": 0.8877836465835571
},
{
"Type": "midJawlineRight",
"X": 0.7990140914916992,
"Y": 0.6899225115776062
},
{
"Type": "upperJawlineRight",
"X": 0.8548634648323059,
"Y": 0.38160091638565063
}
],
"Pose": {
"Roll": -5.83309268951416,
"Yaw": -2.4244730472564697,
"Pitch": 2.6216139793395996
},
"Quality": {
"Brightness": 96.16363525390625,
"Sharpness": 95.51618957519531
},
"Confidence": 99.99872589111328,
"FaceOccluded": {
"Value": true,
"Confidence": 99.99726104736328
},
"EyeDirection": {
"Yaw": 16.299732,
"Pitch": -6.407457,
"Confidence": 99.968704
}
}
],
"ResponseMetadata": {
"RequestId": "8bf02607-70b7-4f20-be55-473fe1bba9a2",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"x-amzn-requestid": "8bf02607-70b7-4f20-be55-473fe1bba9a2",
"content-type": "application/x-amz-json-1.1",
"content-length": "3409",
"date": "Wed, 26 Apr 2023 20:18:50 GMT"
},
"RetryAttempts": 0
}
}
다음 사항에 유의하세요.
-
Pose
데이터는 감지된 얼굴의 회전을 기술합니다.BoundingBox
와Pose
데이터의 조합을 사용하여 애플리케이션이 표시하는 얼굴 주위에 경계 상자를 그릴 수 있습니다. -
Quality
는 얼굴의 밝기와 선명도를 기술합니다. 이는 여러 이미지에서 얼굴을 비교해 가장 좋은 얼굴을 찾는 데 유용할 수 있습니다. -
이전 응답은 서비스가 감지할 수 있는 모든 얼굴
landmarks
, 모든 얼굴 속성 및 감정을 보여 줍니다. 응답에서 이 모두를 얻으려면attributes
파라미터를 값ALL
로 지정해야 합니다.DetectFaces
API는 기본적으로BoundingBox
,Confidence
,Pose
,Quality
,landmarks
와 같은 5가지 얼굴 속성만 반환합니다. 기본 표식은eyeLeft
,eyeRight
,nose
,mouthLeft
,mouthRight
가 반환됩니다.