왕현성
코딩발자취
왕현성
전체 방문자
오늘
어제
  • 코딩 (277)
    • Python (71)
    • Java (16)
    • MySQL (34)
    • 인공지능 (48)
      • 머신러닝 (16)
      • 딥러닝 (32)
    • 영상처리 (4)
    • Rest API (21)
    • Android Studio (25)
    • streamlit (13)
    • DevOps (22)
      • AWS (9)
      • PuTTY (5)
      • Git (4)
      • Serverless (2)
      • Docker (2)
    • IT 기술 용어 (6)
    • 디버깅 ( 오류 해결 과정 ) (17)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 영상처리역사
  • labelme UnocodeDecodeError
  • alibi-detection
  • 컴퓨터비전
  • PIL
  • matplotlib
  • 의료이미징
  • 영상처리
  • TensorFlow
  • get_long_description
  • labelme
  • PYTHON
  • 기상탐사
  • pip install labelme
  • UnboundLocalError
  • pytorch
  • encoding='utf-8'
  • yolov8
  • numpy
  • 영상기술
  • tune()
  • imageprocessing
  • unsupervised
  • maskimage
  • alibidetect
  • ckpt_file
  • 딥러닝
  • OpenCV
  • 비지도학습
  • ComputerVision

최근 댓글

최근 글

티스토리

250x250
hELLO · Designed By 정상우.
왕현성

코딩발자취

AmazonRekognition을 사용하여 객체탐지(Object detection) / 자동 태그 API 개발
Rest API

AmazonRekognition을 사용하여 객체탐지(Object detection) / 자동 태그 API 개발

2023. 1. 13. 11:11
728x90
  • 해당 기능만을 서술한 포스팅으로, 전체 기능에 대한 소스 코드 확인은 이전 포스팅 글에서 확인 가능합니다.
    https://hyunsungstory.tistory.com/204
 

AmazonRekognition을 사용하여 객체탐지(Object detection) API 개발

Amazon Rekognition란? Amazon Rekognition Rekognition을 사용하면 애플리케이션에 이미지 및 비디오 분석을 쉽게 추가할 수 있습니다. Amazon Rekognition API에 이미지나 비디오를 제공하면 서비스에서 객체, 사람

hyunsungstory.tistory.com

 

 

API 설계는 위와같이 진행 하였고

class PhotoRekognitionResource(Resource) :
    def post(self) :
        
        if 'photo' not in request.files :
            return {'error':'파일 업로드 하세요'},400

        file = request.files['photo']

        # 클라이언트가 보낸 파일의 파일명을
        # 변경시켜서 S3에 올려야 유니크하게 
        # 파일을 관리할 수 있다.

        # 파일명을 유니크하게 만드는 방법
        current_time=datetime.now()
        new_file_name=current_time.isoformat().replace(':','_') + '.jpg'

        print(new_file_name)

        # 파일명을, 유니크한 이름으로 변경한다.
        # 클라이언트에서 보낸 파일명을 대체!

        file.filename = new_file_name

        # S3에 파일을 업로드하면 된다.
        # S3에 파일 업로드하는 라이브러리가 필요
        # boto3 라이브러리를 이용해서 업로드한다.
        # 참고 : 라이브러리 설치는 pip install boto3

        client=boto3.client('s3',
                    aws_access_key_id = Config.ACCESS_KEY ,
                    aws_secret_access_key = Config.SECRET_ACCESS)
        
        try :
            client.upload_fileobj(file,Config.S3_BUCKET,new_file_name,
                                    ExtraArgs ={'ACL':'public-read','ContentType':file.content_type})
        
        except Exception as e :
            return {'error':str(e)}, 500

        # 리코그니션 서비스를 이용할 수 있는지
        # IAM의 유저 권한 확인하고 설정해준다.
        client=boto3.client('rekognition',
                    'ap-northeast-2',
                    aws_access_key_id=Config.ACCESS_KEY,
                    aws_secret_access_key=Config.SECRET_ACCESS)
        response=client.detect_labels(Image={'S3Object':{'Bucket':Config.S3_BUCKET,'Name':new_file_name}},
                            MaxLabels= 10 )

        num=np.arange(0,9+1)
        print(response['Labels'][0]['Name'])
        print(num)
        labels = []
        for x in num :
            labels.append(response['Labels'][x]['Name'])
        
        print (labels)

        

        # 위의 response에서 필요한 데이터만 가져와서
        # 클라이언트에게 보내준다
        # labels : [  ]


        return {'result':'success','labels':labels},200

코드는 이렇게 작성하였습니다.

 

response 변수에 저장한 것은 Json으로 구성되어있는데 구조를 파악하기 위해 

https://jsoneditoronline.org/

 

JSON Editor Online: JSON editor, JSON formatter, query JSON

You need to enable JavaScript to run this app. JSON Editor Online JSON Editor Online is a web-based tool to view, edit, format, repair, compare, query, transform, validate, and share your JSON data. About JSON Editor Online JSON Editor Online is a versatil

jsoneditoronline.org

위 사이트에서 

ctrl + f 를 눌러 ' 는 Json에서 인식을 안 하기 때문에 "로 Replace All 해준 뒤 구조 파악을 한 결과

 

response['Labels'][x]['Name']

위 코드로 데이터 억세스를 하면 자동 태그 추천을 하기 위한 Name만 가져올 수 있었다.

 

포스트맨 테스트 결과

'Rest API' 카테고리의 다른 글

Naver Open API - 뉴스 검색 API , 파파고 번역 API 사용하기  (0) 2023.01.13
AmazonRekognition을 사용하여 객체탐지(Object detection) / 사진과 문장을 업로드하는 SNS의 Posting API 개발  (0) 2023.01.13
AmazonRekognition을 사용하여 객체탐지(Object detection) API 개발  (0) 2023.01.12
API 서버 - 로그인한 회원과 비회원 구분하여 시스템 개발하기 // jwt_required(optional= )  (0) 2023.01.10
API서버 - 실시간 추천 기능 구현  (0) 2023.01.10
    'Rest API' 카테고리의 다른 글
    • Naver Open API - 뉴스 검색 API , 파파고 번역 API 사용하기
    • AmazonRekognition을 사용하여 객체탐지(Object detection) / 사진과 문장을 업로드하는 SNS의 Posting API 개발
    • AmazonRekognition을 사용하여 객체탐지(Object detection) API 개발
    • API 서버 - 로그인한 회원과 비회원 구분하여 시스템 개발하기 // jwt_required(optional= )
    왕현성
    왕현성
    AI 머신비전 학습일지

    티스토리툴바