Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HUST-2019-ncov-submit-fucker
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
recolic-hust
HUST-2019-ncov-submit-fucker
Commits
a1ca342a
There was an error fetching the commit references. Please try again later.
Commit
a1ca342a
authored
5 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
Add hust_code OCR
parent
0d228b85
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hust_code.py
+31
-19
31 additions, 19 deletions
hust_code.py
with
31 additions
and
19 deletions
hust_code.py
+
31
−
19
View file @
a1ca342a
from
PIL
import
Image
from
PIL
import
Image
import
sys
import
sys
,
subprocess
i
,
o
=
sys
.
argv
[
1
:]
tmp_fname
=
'
/tmp/.recolic-hust.ocr-tmp.png
'
im
=
Image
.
open
(
i
)
def
prepare_ocr
(
input_fname
,
output_fname
):
# In pass.hust.edu.cn verification code, the second frame is COMPLETE!
im
=
Image
.
open
(
input_fname
)
# let's get the second frame.
# In pass.hust.edu.cn verification code, the second frame is COMPLETE!
im
.
seek
(
im
.
tell
()
+
1
)
# let's get the second frame.
im
.
save
(
o
)
im
.
seek
(
im
.
tell
()
+
1
)
# To white-black
im
=
im
.
convert
(
'
L
'
)
im
=
im
.
point
(
lambda
x
:
0
if
x
<
254
else
255
,
'
1
'
)
# Try to crop. The Silly ocr doesn't like a single_line good image...
# Should use `tesseract output.png stdout --psm 8 -c tessedit_char_whitelist=0123456789` for cropped image.
#w, h = im.size
#if w == 90 and h == 58:
# im = im.crop((0, 18, w, 39))
#else:
# print('WARNING: Expected image w=90, h=58, Got image w={}, h={}.'.format(w, h))
# Save for OCR
im
.
save
(
output_fname
)
im
=
Image
.
open
(
o
)
def
do_ocr
(
input_fname
):
# To white-black
output
=
subprocess
.
check_output
([
'
tesseract
'
,
input_fname
,
'
stdout
'
]).
decode
(
'
utf-8
'
)
im
=
im
.
convert
(
'
L
'
)
for
line
in
output
.
split
(
'
\n
'
):
im
=
im
.
point
(
lambda
x
:
0
if
x
<
254
else
255
,
'
1
'
)
line
=
line
.
strip
()
# Try to crop
if
len
(
line
)
==
4
and
line
.
isdigit
():
w
,
h
=
im
.
size
return
line
if
w
==
90
and
h
==
58
:
return
None
im
=
im
.
crop
((
0
,
18
,
w
,
39
))
else
:
print
(
'
WARNING: Expected image w=90, h=58, Got image w={}, h={}.
'
.
format
(
w
,
h
))
# Save for OCR
im
.
save
(
o
)
#i = sys.argv[1]
#prepare_ocr(i, tmp_fname)
#print(do_ocr(tmp_fname))
def
recognize_hust_code
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment