Toggle navigation
Toggle navigation
This project
Loading...
Sign in
장연우
/
orc-prj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Your Name
2019-01-10 17:49:06 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
611c52b84f1dca7b557a0356a997a0a0e8c0d070
611c52b8
1 parent
1ccf9555
modify main code
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
34 deletions
main.py
main.py
View file @
611c52b
from
pytesseract
import
image_to_string
import
argparse
import
cv2
from
pathlib
import
Path
import
os.path
import
yaml
doc
=
yaml
.
load
(
open
(
'freset.yaml'
,
'r'
))
bil_op
=
doc
[
"bilateralFilterData"
]
th_op
=
doc
[
"thresholdData"
]
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'OCR program'
)
...
...
@@ -12,8 +18,9 @@ def main():
help
=
"Select engine to Google-Vision and Tessreact"
)
args
=
parser
.
parse_args
()
file_path
=
'C:
\\
Users
\\
argos
\\
Desktop
\\
'
+
args
.
img_file
img
=
cv2
.
imread
(
file_path
)
direct
=
Path
(
os
.
path
.
expanduser
(
'~'
))
file_path
=
direct
/
'Desktop'
/
args
.
img_file
img
=
cv2
.
imread
(
str
(
file_path
))
select_freset
(
args
.
op
,
img
)
...
...
@@ -23,40 +30,16 @@ def tesseract_orc_to_file(img):
with
open
(
'result
\\
foo.txt'
,
"w"
)
as
f
:
f
.
write
(
text
)
def
select_freset
(
type
,
img
):
gray
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2GRAY
)
if
type
==
1
:
#gray = cv2.GaussianBlur(gray, ksize=(3, 3), sigmaX=0)
gray
=
cv2
.
bilateralFilter
(
gray
,
9
,
75
,
75
)
_
,
img
=
cv2
.
threshold
(
gray
,
30
,
255
,
cv2
.
THRESH_BINARY
)
elif
type
==
2
:
gray
=
cv2
.
bilateralFilter
(
gray
,
9
,
75
,
75
)
_
,
img
=
cv2
.
threshold
(
gray
,
30
,
255
,
cv2
.
THRESH_BINARY_INV
)
elif
type
==
3
:
gray
=
cv2
.
bilateralFilter
(
gray
,
9
,
75
,
75
)
_
,
img
=
cv2
.
threshold
(
gray
,
225
,
255
,
cv2
.
THRESH_BINARY
)
elif
type
==
4
:
gray
=
cv2
.
bilateralFilter
(
gray
,
9
,
75
,
75
)
_
,
img
=
cv2
.
threshold
(
gray
,
30
,
225
,
cv2
.
THRESH_BINARY_INV
)
elif
type
==
5
:
_
,
img
=
cv2
.
threshold
(
gray
,
30
,
255
,
cv2
.
THRESH_BINARY
)
elif
type
==
6
:
_
,
img
=
cv2
.
threshold
(
gray
,
30
,
255
,
cv2
.
THRESH_BINARY_INV
)
elif
type
==
7
:
_
,
img
=
cv2
.
threshold
(
gray
,
225
,
255
,
cv2
.
THRESH_BINARY
)
elif
type
==
8
:
_
,
img
=
cv2
.
threshold
(
gray
,
225
,
255
,
cv2
.
THRESH_BINARY_INV
)
elif
type
==
9
:
_
,
img
=
cv2
.
threshold
(
gray
,
98
,
255
,
cv2
.
THRESH_BINARY
)
elif
type
==
10
:
_
,
img
=
cv2
.
threshold
(
gray
,
98
,
255
,
cv2
.
THRESH_BINARY_INV
)
elif
type
==
11
:
gray
=
cv2
.
bilateralFilter
(
gray
,
9
,
75
,
75
)
_
,
img
=
cv2
.
threshold
(
gray
,
98
,
255
,
cv2
.
THRESH_BINARY
)
elif
type
==
12
:
gray
=
cv2
.
bilateralFilter
(
gray
,
9
,
75
,
75
)
_
,
img
=
cv2
.
threshold
(
gray
,
98
,
255
,
cv2
.
THRESH_BINARY_INV
)
if
type
<
7
:
gray
=
cv2
.
bilateralFilter
(
gray
,
int
(
bil_op
[
0
]),
int
(
bil_op
[
1
]),
int
(
bil_op
[
2
]))
_
,
img
=
cv2
.
threshold
(
gray
,
int
(
th_op
[
'threshVal'
][
type
%
3
]),
int
(
th_op
[
'threshMax'
][
0
]),
cv2
.
THRESH_BINARY_INV
if
type
%
2
else
cv2
.
THRESH_BINARY
)
elif
type
<
13
:
_
,
img
=
cv2
.
threshold
(
gray
,
int
(
th_op
[
'threshVal'
][
type
%
3
]),
int
(
th_op
[
'threshMax'
][
0
]),
cv2
.
THRESH_BINARY_INV
if
type
%
2
else
cv2
.
THRESH_BINARY
)
tesseract_orc_to_file
(
img
)
...
...
Please
register
or
login
to post a comment