이미지를 분석해주는 AWS 의 rekognition 을 이용해봅시다.
먼저 첫번째로 하셔야 하는 일은 AWS IAM 에서 rekognition 의 접근을 허락하도록 합니다.
접근을 허락했다면 이제 비쥬얼코드에 작성하여 rekognition 을 이용해 봅시다.
# import
from flask import request
from flask_restful import Resource
import boto3
from config import Config
클래스를 하나 만듭니다. ObjectDetectionResource 로 만들겠습니다.
class ObjectDetectionResource(Resource) :
#S3 에 저장되 있는 이미지를 객체 탐지하는 API
def get(self) :
# 클라이언트로부터 파일명을 받아온다.
filename = request.args.get('filename')
# 위 파일은 이미 S3 에 있는 상황
# 따라서 AWS의 rekognition 인공지능 서비스를 이용해서
# object detection 을 한다.
# 리코그니션 서비스를 이용할 수 있는지 IAM의 유저 권한을 확인해야 한다.
client = boto3.client('rekognition',
'ap-northeast-2',
aws_access_key_id=Config.AWS_ACCESS_KEY_ID,
aws_secret_access_key = Config.AWS_SECERT_ACCESS_KEY)
response=client.detect_labels(Image={'S3Object':{'Bucket':Config.S3_BUCKET , 'Name' : filename } } ,
MaxLabels = 10 )
return {'result': 'success',
'Labels': response['Labels']},200
로컬로 이 서버를 실행하고 포스트맨을 통해 확인해봅시다.
'개발 > 백엔드' 카테고리의 다른 글
server - open api 이용해보기. (0) | 2023.01.13 |
---|---|
server - AWS S3 에 이미지 업로드 하기. (0) | 2023.01.12 |
server - aws lambda - github 연결하여 자동배포하기. (0) | 2023.01.12 |
server - aws lambda layer 추가 (0) | 2023.01.11 |
server - AWS lambda 배포 지역 변경하기. (credentials 에러) (0) | 2023.01.11 |