Commit 136cb64b by 김영표

Merge branch 'issue/INNODEV-2812' into 'master'

INNODEV-2812 Python 이해

See merge request !1
parents 45b070a0 7137578f
type,label,data,conf,dtype,extra_info,bbox
"테스트 폼_04_테스트 완료_전체 ","제목 ","실용신안등록증 ","0.9544 ","str "," ","[[176, 178], [322, 178], [322, 205], [176, 205]] "
"0.8708 ","등록번호 ","제 0333149 호 ","0.9779 ","str "," ","[[125, 220], [248, 220], [248, 239], [125, 239]] "
"test_form_COPY_3 ","출원번호 ","체 2003 0025072 호 ","0.9755 ","str "," ","[[350, 219], [437, 219], [437, 229], [350, 229]] "
"[[34, 65], [451, 65], [451, 684], [34, 684]] ","출원일 ","2003년\n08월\n04일 ","0.9785 ","str "," ","[[350, 231], [436, 231], [436, 242], [350, 242]] "
,"등록일 ","2003년 11월\n04일 ","0.9656 ","str "," ","[[350, 244], [436, 244], [436, 255], [350, 255]] "
,"고안_명칭 ","성진엔지니어링 (주)( 150111-0026597 ) ","0.9787 ","str "," ","[[136, 344], [396, 344], [396, 358], [136, 358]] "
,"담당자 ","충청북도 청주시 흥덕구 봉명동 901번지 ","0.9788 ","str "," ","[[136, 373], [395, 373], [395, 387], [136, 387]] "
,"고안자 ","충청북도청주시흥덕구신봉동삼성아파트7/406 ","0.9646 ","str "," ","[[135, 436], [397, 436], [397, 452], [135, 452]] "
,"내용 ","원부에 공안은였집음을 증명합니다.\n위의\n실용신안법에 의하여 실용신안등록 ","0.8894 ","str "," ","[[51, 510], [445, 510], [445, 548], [51, 548]] "
,"날짜 ","2003년\n11월\n04일 ","0.9785 ","str "," ","[[308, 559], [424, 559], [424, 572], [308, 572]] "
,"날인자 ","특\n허 청 ","0.9749 ","str "," ","[[134, 629], [360, 629], [360, 657], [134, 657]] "
,"도장 "," ","1.0 ","image "," ","[[302, 597], [385, 597], [385, 678], [302, 678]] "
\ No newline at end of file
import requests
import json
import os
import argparse
# 엔진 경로 설정
ENGINE_ADDRESS = 'http://192.168.1.149:62975'
def run_ocr(image_path):
"""
해당 경로(image_path)에서 이미지 파일을 가져와서 ocr인식을 수행합니다.
:param image_path: ocr인식을 수행할 이미지 경로
:return: ocr인식이 수행된 결과를 json 형식으로 반환
"""
global ENGINE_ADDRESS
# 경로 설정
run_address = '/sdk/ocr'
url = ENGINE_ADDRESS + run_address
# 파라미터 지정
data = {
'api_key': 'SNOCR-0fb7010e88fd4ad99033947351711c43',
'type': 'local',
'boxes_type': 'all',
'path': image_path,
'lang': 'all',
'recog_form': 'true' # 서식 인식 여부
}
# 인식
response = requests.post(url, data=data)
result = response.json()
return result
def download_csv_file(ocr_result, output_file_path):
"""
ocr인식이 수행된 결과를 csv파일로 저장합니다.
:param ocr_result: dict형식의 ocr 인식 결과
:param output_file_path: 저장할 csv 파일명
:return: None
"""
global ENGINE_ADDRESS
# 경로 설정
ocr_file_address = '/sdk/out/' + ocr_result['result']['csv_file_name']
url = ENGINE_ADDRESS + ocr_file_address
# 파라미터 지정
data = {'api_key': 'SNOCR-0fb7010e88fd4ad99033947351711c43'}
# 파일 받고 저장
response = requests.post(url, data=data)
res_content = response.content
with open(output_file_path + '.csv', 'wb') as csv_file:
csv_file.write(res_content)
def main(image_dir_path, output_dir_path):
"""
ocr인식이 수행될 이미지 디렉토리 경로와 ocr인식 결과를 저장할 디렉토리 경로를 받아 이미지 ocr을 수행하고 csv로 저장합니다.
:param image_dir_path: ocr인식이 수행될 이미지가 들어있는 디렉토리 경로
:param output_dir_path: ocr인식 결과(.csv)가 저장될 디렉토리 경로
:return: None
"""
extension_li = ['png', 'jpg', 'jpeg']
print(os.getcwd())
file_names = [file_name for file_name in os.listdir(image_dir_path) if file_name.split('.')[1] in extension_li]
# 반복 인식 후 저장
for file_name in file_names:
# 인식
img_path = os.path.join(image_dir_path, file_name)
ocr_result = run_ocr(img_path)
# csv파일 받고 저장
output_file_path = os.path.join(output_dir_path, file_name.split('.')[0])
download_csv_file(ocr_result, output_file_path)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input_dir_path", type=str, action="store", default='../../../Downloads')
parser.add_argument("-o", "--output_dir_path", type=str, action="store", default='./test')
args = parser.parse_args()
main(args.input_dir_path, args.output_dir_path)
# main(image_dir_path='../../../Downloads', output_dir_path='./test')
type,label,data,conf,dtype,extra_info,bbox
"테스트 폼_04_테스트 완료_전체 ","제목 ","실용신안등록증 ","0.9594 ","str "," ","[[178, 172], [326, 172], [326, 200], [178, 200]] "
"0.7003 ","등록번호 ","제 0301079 호 ","0.9787 ","str "," ","[[127, 217], [251, 217], [251, 236], [127, 236]] "
"test_form_COPY_3 ","출원번호 ","제 2002-0024393 호 ","0.9791 ","str "," ","[[357, 219], [444, 219], [444, 229], [357, 229]] "
"[[32, 57], [458, 57], [458, 689], [32, 689]] ","출원일 ","2002년\n08월 01일 ","0.9678 ","str "," ","[[357, 232], [443, 232], [443, 244], [357, 244]] "
,"등록일 ","2003년 01월 03일 ","0.9769 ","str "," ","[[356, 245], [443, 245], [443, 257], [356, 257]] "
,"고안_명칭 "," ","-1.0 ","str "," ","[[136, 305], [402, 305], [402, 348], [136, 348]] "
,"담당자 ","충청북도 청주시 흥덕구 봉명동 901번지 ","0.978 ","str "," ","[[137, 370], [401, 370], [401, 385], [137, 385]] "
,"고안자 ","경기도김포시감정동265-10 ","0.9548 ","str "," ","[[136, 438], [403, 438], [403, 452], [136, 452]] "
,"내용 ","위의 고안은 실용신안법에 의하여 실용신안등록\n원부에 등록되었음을 증명합니다. ","0.9781 ","str "," ","[[48, 511], [452, 511], [452, 557], [48, 557]] "
,"날짜 ","2003년\n01월\n03일 ","0.9775 ","str "," ","[[309, 565], [431, 565], [431, 577], [309, 577]] "
,"날인자 ","특\n허 청 ","0.9757 ","str "," ","[[133, 630], [365, 630], [365, 657], [133, 657]] "
,"도장 "," ","1.0 ","image "," ","[[306, 600], [390, 600], [390, 682], [306, 682]] "
\ No newline at end of file
type,label,data,conf,dtype,extra_info,bbox
"테스트 폼_04_테스트 완료_전체 ","제목 ","실용신안등록증 ","0.9607 ","str "," ","[[129, 107], [251, 107], [251, 131], [129, 131]] "
"0.84 ","등록번호 ","제 0295058 호 ","0.9765 ","str "," ","[[88, 142], [189, 142], [189, 158], [88, 158]] "
"test_form_COPY_3 ","출원번호 ","A 2003-0304376 6 ","0.9177 ","str "," ","[[277, 144], [347, 144], [347, 154], [277, 154]] "
"[[9, 13], [359, 13], [359, 533], [9, 533]] ","출원일 ","2003년\n04월 14일 ","0.8547 ","str "," ","[[277, 156], [347, 156], [347, 165], [277, 165]] "
,"등록일 ","2002년\nDDS\n61일 ","0.9285 ","str "," ","[[277, 167], [347, 167], [347, 176], [277, 176]] "
,"고안_명칭 ","세일정밀 공업 ","0.9495 ","str "," ","[[93, 247], [313, 247], [313, 259], [93, 259]] "
,"담당자 ","인천광역시 계영구 작전동 605-2 ","0.9689 ","str "," ","[[93, 269], [312, 269], [312, 281], [93, 281]] "
,"고안자 ","인천광이시계양구작전동26-1뉴서율2차201동1304호 ","0.9333 ","str "," ","[[91, 324], [314, 324], [314, 338], [91, 338]] "
,"내용 ","위의 고안은 실용신안법에 의하여 실용신안등록\n원부에 등록되었음을 증명합니다. ","0.9774 ","str "," ","[[19, 385], [354, 385], [354, 424], [19, 424]] "
,"날짜 ","2002년\n10월 31일 ","0.9771 ","str "," ","[[235, 430], [337, 430], [337, 441], [235, 441]] "
,"날인자 ","특\n허\n청 ","0.9755 ","str "," ","[[94, 485], [283, 485], [283, 510], [94, 510]] "
,"도장 "," ","1.0 ","image "," ","[[234, 459], [303, 459], [303, 527], [234, 527]] "
\ No newline at end of file
type,label,data,conf,dtype,extra_info,bbox
"테스트 폼_04_테스트 완료_전체 ","제목 ","실용신안등록증 ","0.9544 ","str "," ","[[176, 178], [322, 178], [322, 205], [176, 205]] "
"0.8708 ","등록번호 ","제 0333149 호 ","0.9779 ","str "," ","[[125, 220], [248, 220], [248, 239], [125, 239]] "
"test_form_COPY_3 ","출원번호 ","체 2003 0025072 호 ","0.9755 ","str "," ","[[350, 219], [437, 219], [437, 229], [350, 229]] "
"[[34, 65], [451, 65], [451, 684], [34, 684]] ","출원일 ","2003년\n08월\n04일 ","0.9785 ","str "," ","[[350, 231], [436, 231], [436, 242], [350, 242]] "
,"등록일 ","2003년 11월\n04일 ","0.9656 ","str "," ","[[350, 244], [436, 244], [436, 255], [350, 255]] "
,"고안_명칭 ","성진엔지니어링 (주)( 150111-0026597 ) ","0.9787 ","str "," ","[[136, 344], [396, 344], [396, 358], [136, 358]] "
,"담당자 ","충청북도 청주시 흥덕구 봉명동 901번지 ","0.9788 ","str "," ","[[136, 373], [395, 373], [395, 387], [136, 387]] "
,"고안자 ","충청북도청주시흥덕구신봉동삼성아파트7/406 ","0.9646 ","str "," ","[[135, 436], [397, 436], [397, 452], [135, 452]] "
,"내용 ","원부에 공안은였집음을 증명합니다.\n위의\n실용신안법에 의하여 실용신안등록 ","0.8894 ","str "," ","[[51, 510], [445, 510], [445, 548], [51, 548]] "
,"날짜 ","2003년\n11월\n04일 ","0.9785 ","str "," ","[[308, 559], [424, 559], [424, 572], [308, 572]] "
,"날인자 ","특\n허 청 ","0.9749 ","str "," ","[[134, 629], [360, 629], [360, 657], [134, 657]] "
,"도장 "," ","1.0 ","image "," ","[[302, 597], [385, 597], [385, 678], [302, 678]] "
\ No newline at end of file
type,label,data,conf,dtype,extra_info,bbox
"테스트 폼_04_테스트 완료_전체 ","제목 ","실용신안등록증 ","0.9594 ","str "," ","[[178, 172], [326, 172], [326, 200], [178, 200]] "
"0.7003 ","등록번호 ","제 0301079 호 ","0.9787 ","str "," ","[[127, 217], [251, 217], [251, 236], [127, 236]] "
"test_form_COPY_3 ","출원번호 ","제 2002-0024393 호 ","0.9791 ","str "," ","[[357, 219], [444, 219], [444, 229], [357, 229]] "
"[[32, 57], [458, 57], [458, 689], [32, 689]] ","출원일 ","2002년\n08월 01일 ","0.9678 ","str "," ","[[357, 232], [443, 232], [443, 244], [357, 244]] "
,"등록일 ","2003년 01월 03일 ","0.9769 ","str "," ","[[356, 245], [443, 245], [443, 257], [356, 257]] "
,"고안_명칭 "," ","-1.0 ","str "," ","[[136, 305], [402, 305], [402, 348], [136, 348]] "
,"담당자 ","충청북도 청주시 흥덕구 봉명동 901번지 ","0.978 ","str "," ","[[137, 370], [401, 370], [401, 385], [137, 385]] "
,"고안자 ","경기도김포시감정동265-10 ","0.9548 ","str "," ","[[136, 438], [403, 438], [403, 452], [136, 452]] "
,"내용 ","위의 고안은 실용신안법에 의하여 실용신안등록\n원부에 등록되었음을 증명합니다. ","0.9781 ","str "," ","[[48, 511], [452, 511], [452, 557], [48, 557]] "
,"날짜 ","2003년\n01월\n03일 ","0.9775 ","str "," ","[[309, 565], [431, 565], [431, 577], [309, 577]] "
,"날인자 ","특\n허 청 ","0.9757 ","str "," ","[[133, 630], [365, 630], [365, 657], [133, 657]] "
,"도장 "," ","1.0 ","image "," ","[[306, 600], [390, 600], [390, 682], [306, 682]] "
\ No newline at end of file
type,label,data,conf,dtype,extra_info,bbox
"테스트 폼_04_테스트 완료_전체 ","제목 ","실용신안등록증 ","0.9767 ","str "," ","[[171, 162], [321, 162], [321, 191], [171, 191]] "
"0.9121 ","등록번호 ","제 0359606 호 ","0.978 ","str "," ","[[124, 210], [245, 210], [245, 229], [124, 229]] "
"test_form_COPY_3 ","출원번호 ","제 2004-0014724 호 ","0.9613 ","str "," ","[[358, 209], [442, 209], [442, 219], [358, 219]] "
"[[22, 45], [457, 45], [457, 690], [22, 690]] ","출원일 ","2004년 05월\n27일 ","0.9772 ","str "," ","[[358, 225], [440, 225], [440, 236], [358, 236]] "
,"등록일 ","2004년 08월\n10일 ","0.9788 ","str "," ","[[358, 241], [440, 241], [440, 252], [358, 252]] "
,"고안_명칭 ","트리클링 장치\n성진엔지니어링 (주)( 150111-0026597 ) ","0.9785 ","str "," ","[[136, 294], [399, 294], [399, 349], [136, 349]] "
,"담당자 ","충청북도 청주시 흥덕구 봉명동 901번지 ","0.9496 ","str "," ","[[136, 360], [398, 360], [398, 377], [136, 377]] "
,"고안자 ","충청북도청주시흥덕구신봉동심성아파트7/406 ","0.9742 ","str "," ","[[136, 431], [400, 431], [400, 446], [136, 446]] "
,"내용 ","위의 고안은 실용신안법에 의하여 실용신안등록\n원부에 등록되었음을 증명합니다. ","0.9774 ","str "," ","[[46, 506], [450, 506], [450, 552], [46, 552]] "
,"날짜 ","2004년\n08월 10일 ","0.9792 ","str "," ","[[314, 558], [429, 558], [429, 571], [314, 571]] "
,"날인자 ","특\n허 청 ","0.9752 ","str "," ","[[129, 631], [361, 631], [361, 659], [129, 659]] "
,"도장 "," ","1.0 ","image "," ","[[301, 599], [387, 599], [387, 683], [301, 683]] "
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment