«   2024/09   »
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
Archives
Today
Total
09-21 13:21
관리 메뉴

DevTzu

[Java Spring] AWS Amazon Rekognition 시작하기 / 아마존 레코그니션 설정 본문

study

[Java Spring] AWS Amazon Rekognition 시작하기 / 아마존 레코그니션 설정

DevTzu 2022. 10. 15. 09:00
반응형

기존 Spring 프레임워크 프로젝트에 AWS Amazon Rekognition 설정을 해보았습니다.

 

 

- AWS Rekognition란?
Amazon Rekognition Rekognition을 사용하면 애플리케이션에 이미지 및 비디오 분석을 쉽게 추가할 수 있습니다. Amazon Rekognition API에 이미지나 비디오를 제공하면 서비스에서 객체, 사람, 텍스트, 장면 및 활동을 식별할 수 있습니다. 부적절한 콘텐츠를 감지할 수도 있습니다. Amazon Rekognition Rekognition은 매우 정확한 얼굴 분석, 얼굴 비교 및 얼굴 검색 기능도 제공합니다. 사용자 확인, 카탈로그 작성, 인원 계산 및 공공 안전을 포함하여 다양한 사용 사례에서 얼굴을 탐지, 분석, 비교할 수 있습니다.

https://docs.aws.amazon.com/ko_kr/rekognition/latest/dg/what-is.html

 

Amazon Rekognition 란 무엇입니까? - Amazon Rekognition

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다. Amazon Rekognition 란 무엇입니까? Amazon Rekognition Rekognition을 사용하면 애플리케

docs.aws.amazon.com

 

 

 

요구사항

거실, 주방, 침실 사진을 분석하여 사진 속 가구, 제품을 식별하여 의자인지, 침대인지, 액자인지 등 사진 속 가구를 분석 및 추출해야 되는 상황입니다.

그래서 구글링 시작

아마존 레코그니션이 제가 원하는 기능을 구현할 수 있게 API를 제공하고있음을 알게 되었습니다.

데모 사이트에서 직접 원하는 사진을 업로드하여 분석한 결과를 확인해 볼 수 있습니다.

침실 사진을 업로드하자 침대, 테이블, 조명, 액자 등 사진 속 제품을 뽑아주었습니다.

 

Amazon Rekognition을 기존 Java Spring 프로젝트에 세팅해보기로 합니다.

 

 

 

데모

Amazon Rekognition 데모

https://ap-northeast-1.console.aws.amazon.com/rekognition/home?region=ap-northeast-1#/label-detection 

 

https://ap-northeast-1.console.aws.amazon.com/rekognition/home?region=ap-northeast-1#/label-detection

 

ap-northeast-1.console.aws.amazon.com

 

 

 

Java Spring 프로젝트에 Amazon Rekognition 세팅

순서대로 따라 해 보세요.

1. AWS Console에서 IAM 메뉴 접속

2. IAM 사용자 생성에서 만든 사용자의 액세스 키를 만들기

3. 윈도우 %HOMEPATH%\ 경로에 [.aws] 이름의 폴더를 만들고, credentials, config 파일에 엑세스키 넣어서 저장

https://docs.aws.amazon.com/ko_kr/rekognition/latest/dg/setup-awscli-sdk.html

 

2단계: 설정AWS CLI과AWSSDK - Amazon Rekognition

이 페이지에 작업이 필요하다는 점을 알려 주셔서 감사합니다. 실망시켜 드려 죄송합니다. 잠깐 시간을 내어 설명서를 향상시킬 수 있는 방법에 대해 말씀해 주십시오.

docs.aws.amazon.com

 

 

4. pox.xml 파일에 Amazon Rekognition SDK 의존성 추가하기

        <!-- aws rekognition -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-rekognition</artifactId>
            <version>1.12.319</version>
        </dependency>

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-core</artifactId>
            <version>1.12.319</version>
        </dependency>

 

 

5. Rekognition 이미지 분석 샘플코드 작성하기

@Override
public void test(byte[] bytes) {

    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); // latest version

    DetectLabelsRequest request = new DetectLabelsRequest()
            .withImage(new Image().withBytes(ByteBuffer.wrap(bytes)));

    try {
        DetectLabelsResult result = rekognitionClient.detectLabels(request);
        List <Label> labels = result.getLabels();

        System.out.println("Detected labels for ");
        for (Label label: labels) {
            System.out.println(label.getName() + ": " + label.getConfidence().toString());

            List<Instance> instances = label.getInstances();
            System.out.println("Instances of " + label.getName());
            if (instances.isEmpty()) {
                System.out.println("  " + "None");
            } else {
                for (Instance instance : instances) {
                    System.out.println("  Confidence: " + instance.getConfidence().toString());
                    System.out.println("  Bounding box: " + instance.getBoundingBox().toString());
                }
            }
        }
    } catch(AmazonRekognitionException e) {
        e.printStackTrace();
    }
}

 

 

6. 응답값 확인

{
    "Labels": [
        {
            "Name": "Table",
            "Confidence": 98.74653625488281,
            "Instances": [],
            "Parents": [
                {
                    "Name": "Furniture"
                }
            ]
        },
        {
            "Name": "Coffee Table",
            "Confidence": 96.0590591430664,
            "Instances": [],
            "Parents": [
                {
                    "Name": "Table"
                },
                {
                    "Name": "Furniture"
                }
            ]
        },
        {
            "Name": "Chair",
            "Confidence": 94.5425796508789,
            "Instances": [
                {
                    "BoundingBox": {
                        "Width": 0.24107110500335693,
                        "Height": 0.34586310386657715,
                        "Left": 0.01621982455253601,
                        "Top": 0.3826943635940552
                    },
                    "Confidence": 94.5425796508789
                },
                {
                    "BoundingBox": {
                        "Width": 0.20670904219150543,
                        "Height": 0.2845335304737091,
                        "Left": 0.5079503059387207,
                        "Top": 0.3776218295097351
                    },
                    "Confidence": 82.19131469726562
                }
            ],
            "Parents": [
                {
                    "Name": "Furniture"
                }
            ]
        },
    ],
    "LabelModelVersion": "2.0"
}

 

 

 

간단한 코딩으로 아마존 Rekognition 이미지 분석 API를 사용해 보았습니다.

제가 원하는 이미지 분석 기능을 쉽게 이용해 볼 수 있었는데요.

지금까지 한 부분은 가장 기본적은 기능을 사용한 것입니다.

Rekognition API에서 제공하는 기능을 좀 더 스터디하여 어디까지 활용 가능한지 알아보면 좋을 것 같습니다.

이후 더 좋은 내용이 있으면 블로그에 작성하도록 하겠습니다.

 

 

 

이상.

 

 

#AWS #Amazon #Rekognition #아마존 #레코그니션 #초기설정

반응형
Comments