Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
study
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
최애림
study
Commits
cdb28ffd
Commit
cdb28ffd
authored
Apr 17, 2023
by
최애림
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
INNODEV-2812
Python 이해
- python docstring 방식으로 함수마다 주석 추가 - python argparse를 이용하여 파라미터값을 입력받도록 함
parent
242c698d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
1 deletions
+34
-1
restapi/ocrtest.py
+34
-1
No files found.
restapi/ocrtest.py
View file @
cdb28ffd
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인식이 수행된 결과를 j환son 형식으로 반
"""
global
ENGINE_ADDRESS
# 경로 설정
...
...
@@ -26,12 +32,17 @@ def run_ocr(image_path):
# 인식
response
=
requests
.
post
(
url
,
data
=
data
)
result
=
response
.
json
()
# result_dict = json.loads(result)
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
# 경로 설정
...
...
@@ -49,7 +60,14 @@ def download_csv_file(ocr_result, output_file_path):
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
]
# 반복 인식 후 저장
...
...
@@ -61,3 +79,18 @@ def main(image_dir_path, output_dir_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')
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment