티스토리 뷰

개요


Video Streams를 Rekognition으로 분석하여 Kinesis Data Streams 분석 결과를 실시간으로 Data Streams에 전달하는 과정을 살펴보자

https://docs.aws.amazon.com/ko_kr/rekognition/latest/dg/recognize-faces-in-a-video-stream.html

사전 지식


Kinesis

Kinesis 제품군에는 Kinesis Data Stream, Kinesis Data Firehose, Kinesis Video Stream, Kinesis Data Analytics 의 4가지가 있다.

Kinesis Data Stream

확장 가능하고 내구성이 뛰어난 실시간 데이터 스트리밍 서비스. 수십만개의 소스에서 초당 GB의 데이터를 지속적으로 캡쳐 할 수 있다.
Collect 한 데이터를 임시로 보관하는 일종의 '버퍼'. 24시간에서 168시간 까지.

Kinesis Video Stream

Stream Video를 안전하게 AWS로 전송하기 위한 서비스. KVS로 전송 후 Analytics나 ML 등에 활용 할 수 있다.

Rekognition

https://aws.amazon.com/ko/rekognition/
데모 : https://us-west-2.console.aws.amazon.com/rekognition/home?region=us-west-2#/label-detection
주의할 점 : Rekognition에서 Streaming Video를 분석하는 기능과, 저장된 Video를 분석하는 기능은 서로 다르다. Rekognition 요금 페이지에서 확인 가능.

스트리밍 비디오 작업


Kinesis Video Stream에 있는 Stream Video를 Rekognition을 통해 분석 후 Kinesis Data Stream으로 보내는 파이프라인을 작성 해보자.

이 과정은 Streaming Video에서 Collection안에 있는 얼굴을 찾는 일을 한다

https://docs.aws.amazon.com/ko_kr/rekognition/latest/dg/streaming-video.html

이를 위해서 Stream Processor가 필요하다. (후반부 서술)

Kinesis Data Stream 생성


Kinesis Video StreamRekognitionKinesis Data Stream을 전달 받을 Kinesis Data Stream을 생성 하고 ARN을 기록해둔다.

AWS 웹 콘솔에서 Create 버튼을 눌러서 생성하면 된다.

Collection 만들기


아무 얼굴이나 분석하는 것은 아니다. Collection에 등록한 얼굴만 분석 가능하다. 이를 위해 AWS CLI를 이용하여 RekognitionCollection을 생성하자. (웹콘솔에>서는 지원 안하는 것으로 보인다.)

aws rekognition create-collection --collection-id "JhbCollection"

Collection에 얼굴 추가

https://docs.aws.amazon.com/ko_kr/rekognition/latest/dg/add-faces-to-collection-procedure.html

aws rekognition index-faces \
      --image '{"S3Object":{"Bucket":"bucket-name","Name":"file-name"}}' \
      --collection-id "JhbCollection" \
      --max-faces 1 \
      --quality-filter "AUTO" \
      --detection-attributes "ALL" \
      --external-image-id "Jhb"

이때 AWS 계정이 Access하고 있는 Default Region과 S3 Bucket의 리전을 동일하게 한>다.

Region이 다를 경우 InvalidS3ObjectException: An error occurred (InvalidS3ObjectException) when calling the IndexFaces operation 라는 에러가 발생한다.

결과적으로 아래와 같이 Face가 Index 된다.

Results for Jhb
Faces indexed:
        {
            "Effect": "Allow",
            "Action": [
                "kinesis:PutRecord",
                "kinesis:PutRecords"
            ],
            "Resource": "[kinesis-data-arn]"
        },
        {
            "Effect": "Allow",
            "Action": [
                "kinesisvideo:GetDataEndpoint",
                "kinesisvideo:GetMedia"
            ],
            "Resource": "[kinesis-video-arn]"
        }
    ]
}

이렇게 생성한 Role의 ARN을 기록해놓자.

Stream Processor


여기까지 진행하면 이제 Kinesis Video Stream, Rekognition, Kinesis Data Stream과 필요한 IAM Role 이 준비 되었다.

이를 이용하여 Stream Processor를 생성하자. 아래의 예시는 streamProcessorForJhb라는 이름의 Stream Processor를 얼굴 인식 판별률을 85.5%로 하여 생성한다.

$ aws rekognition create-stream-processor \
  --input '{"KinesisVideoStream":{"Arn":"VIDEO_STREAM_ARN"}}' \
  --name streamProcessorForJhb \
  --role-arn "ROLEARN" \
  --stream-processor-output '{"KinesisDataStream":{"Arn":"DATASTREAMARN"}}' \
  --settings '{"FaceSearch":{"CollectionId":"COLLECTIONID", "FaceMatchThreshold": 85.5}}'

Start Stream-processor

아래의 명령어를 통해 RekognitionStream Process를 시작한다.

$ aws rekognition start-stream-processor --name streamProcessorForJhb

Stop Stream-Processor

아래의 명령을 통해 RekognitionStream Process를 종료한다.

aws rekognition stop-stream-processor --name streamProcessorForJhb

결과물


최종적으로 Kinesis Data Stream에 쌓이는 Payload는 아래와 같다.

{
  "InputInformation": {
    "KinesisVideo": {
      "StreamArn": "arn:aws:kinesisvideo:us-west-2:332346530000:stream/Raspberry1/1568808910000",
      "FragmentNumber": "91343852333181506862203065875037152061796366840",
      "ServerTimestamp": 1.571298112727E9,
      "ProducerTimestamp": 1.571298112105E9,
      "FrameOffsetInSeconds": 0.5019999742507935
    }
          {
            "X": 0.7019036,
            "Y": 0.8969137,
            "Type": "eyeRight"
          },
          {
            "X": 0.59382737,
            "Y": 0.91361463,
            "Type": "mouthLeft"
          },
          {
            "X": 0.6380028,
            "Y": 0.9727975,
            "Type": "mouthRight"
          },
          {
            "X": 0.6451906,
            "Y": 0.8998076,
            "Type": "nose"
          }
        ],
        "Pose": {
          "Pitch": 3.806123,
          "Roll": 43.06001,
          "Pitch": 3.806123,
          "Roll": 43.06001,
          "Yaw": -1.822273
        },
        "Quality": {
          "Brightness": 85.92424,
          "Sharpness": 46.0298
        }
      },
      "MatchedFaces": [
        {
          "Similarity": 98.73166,
          "Face": {
            "BoundingBox": {
              "Height": 0.751345,
              "Width": 0.70821,
              "Left": 0.159309,
              "Top": 0.133466
            },
            "FaceId": "3bc6711b-5f72-4192-a2b9-97763361ded0",
            "Confidence": 99.9996,
            "ImageId": "75248949-886b-357a-8e21-161de2a3aa16",
            "ExternalImageId": "Josh"
          }
            "ExternalImageId": "Josh"
          }
        }
      ]
    },
    {
      "DetectedFace": {
        "BoundingBox": {
          "Height": 0.26980263,
          "Width": 0.16640267,
          "Left": 0.47855082,
          "Top": 0.29992324
        },
        "Confidence": 100.0,
        "Landmarks": [
          {
            "X": 0.572644,
            "Y": 0.37542638,
            "Type": "eyeLeft"
          },
          {
            "X": 0.6029233,
            "Y": 0.4477648,
            "Type": "eyeRight"
            "Y": 0.4477648,
            "Type": "eyeRight"
          },
          {
            "X": 0.5170879,
            "Y": 0.4593469,
            "Type": "mouthLeft"
          },
          {
            "X": 0.5408632,
            "Y": 0.51833594,
            "Type": "mouthRight"
          },
          {
            "X": 0.5786778,
            "Y": 0.46212,
            "Type": "nose"
          }
        ],
        "Pose": {
          "Pitch": 10.257913,
          "Roll": 58.25943,
          "Yaw": 35.188484
        },
          "Yaw": 35.188484
        },
        "Quality": {
          "Brightness": 64.466415,
          "Sharpness": 46.0298
        }
      },
      "MatchedFaces": [
        {
          "Similarity": 95.14247,
          "Face": {
            "BoundingBox": {
              "Height": 0.433341,
              "Width": 0.182538,
              "Left": 0.405325,
              "Top": 0.172389
            },
            "FaceId": "bb1a6bd9-b42e-4744-bb3e-7fefa49ca397",
            "Confidence": 100.0,
            "ImageId": "bc5df041-325a-38d8-a9de-c2e99796e865",
            "ExternalImageId": "Jhb"
          }
        }
      ]
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함