728x90
얼굴 비교
text 감지
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_text(Image={'S3Object':{'Bucket':Config.S3_BUCKET,'Name':new_file_name}})
print(response)
textDetections=response['TextDetections']
print(textDetections)
print ('Detected text\n----------')
textList = []
for text in textDetections:
print ('Detected text:' + text['DetectedText'])
textList.append(text['DetectedText'])
print ('Confidence: ' + "{:.2f}".format(text['Confidence']) + "%")
print ('Id: {}'.format(text['Id']))
if 'ParentId' in text:
print ('Parent Id: {}'.format(text['ParentId']))
print ('Type:' + text['Type'])
print()
# 위의 response에서 필요한 데이터만 가져와서
# 클라이언트에게 보내준다
# labels : [ ]
return {'result':'success','textList':textList},200
포스트맨 실행 결과 ( 한글 )
포스트맨 실행 결과 ( 영어 )
위 결과를 보니 자동 언어 식별과 다국어 문서에 대한 인식율은 낮아 보입니다.
'Rest API' 카테고리의 다른 글
chatGPT API(gpt-3.5-turbo)를 활용한 상담기능 서비스 개발 (0) | 2023.04.03 |
---|---|
CLOVA Summary를 활용해 리뷰 요약 API 만들기 (0) | 2023.04.03 |
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.13 |