Commit 20c840b1 by 최애림

INNODEV-2812 Python 이해

- restAPI를 활용한 OCR TEST
- 인식 결과 파일 CSV로 저장
parent 45b070a0
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 os
import requests
import pprint
# print(os.getcwd())
############################# 인식 수행 #########################################
# 엔진 경로 설정
engine_address = 'http://192.168.1.149:62975'
ocr_sdk_path = '/sdk/ocr'
url = engine_address + ocr_sdk_path
# 파라미터 지정
img_path = '../../../Downloads/0025_0023.jpg'
data = {
'api_key': 'SNOCR-0fb7010e88fd4ad99033947351711c43',
'type': 'local',
'boxes_type': 'all',
'path': img_path,
'lang': 'all',
'recog_form': 'true', # 서식 인식 여부
}
# 인식
response = requests.post(url, data=data)
# 출력
# print(response.status_code)
# print(response.text)
pprint.pprint(response.json())
result = response.json()
# csv파일 이름 받기
print(result['result']['csv_file_name'])
############################# 여러개 인식 수행 #########################################
# 경로 설정
base_path = '../../../Downloads/'
img_paths = [base_path + file for file in os.listdir(base_path) if file.split('.')[1] == 'jpg']
print(img_paths)
# 반복 인식
for img_path in img_paths:
data['path'] = img_path
res = requests.post(url, data=data)
print(res.json())
############################# 인식 후 csv파일 저장 #########################################
# 경로 설정
ocr_file_path = '/sdk/out/' + result['result']['csv_file_name']
url2 = engine_address + ocr_file_path
# 파라미터 설정
data2 = {'api_key': 'SNOCR-0fb7010e88fd4ad99033947351711c43'}
# 받아오기
response2 = requests.post(url2, data = data2)
res_content = response2.content
# 저장
with open('test.csv', 'wb') as csv_file:
csv_file.write(res_content)
############################# 여러개 인식 후 csv파일 저장 #########################################
# 경로 설정: jpg 파일만 리스트화
base_path = '../../../Downloads/'
img_paths = [base_path + file for file in os.listdir(base_path) if file.split('.')[1] == 'jpg']
# 반복 인식 후 저장
for img_path in img_paths:
# 인식
data['path'] = img_path
res = requests.post(url, data=data)
result2 = res.json()['result']['csv_file_name']
# csv파일 받기
res2 = requests.post(engine_address + '/sdk/out/' + result2, data=data2)
res_content2 = res2.content
# 바이트를 문자로 변환 후 저장
save_name = img_path[-13:-4]
with open('test' + save_name + '.csv', 'wb') as w:
w.write(res_content2)
\ 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.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