Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
cd19eb72
authored
2020-12-22 14:51:05 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
id card distinguish
1 parent
e6f25bb7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
3 deletions
src/apps/doc/management/commands/folder_ocr_process.py
src/apps/doc/management/commands/folder_ocr_process.py
View file @
cd19eb7
...
...
@@ -14,7 +14,7 @@ from settings import conf
from
common.mixins
import
LoggerMixin
from
common.tools.pdf_to_img
import
PDFHandler
from
apps.doc
import
consts
from
apps.doc.exceptions
import
OCR1Exception
from
apps.doc.exceptions
import
OCR1Exception
,
OCR4Exception
from
apps.doc.ocr.wb
import
BSWorkbook
...
...
@@ -37,13 +37,59 @@ class Command(BaseCommand, LoggerMixin):
def
signal_handler
(
self
,
sig
,
frame
):
self
.
switch
=
False
# 停止处理文件
def
license1_process
(
self
,
ocr_data
,
license_summary
,
classify
,
res_list
,
pno
,
ino
,
part_idx
):
def
license1_process
(
self
,
ocr_data
,
license_summary
,
classify
,
res_list
,
pno
,
ino
,
part_idx
,
img_path
):
# 类别:'0'身份证, '1'居住证
license_data
=
ocr_data
.
get
(
'data'
,
[])
if
not
license_data
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS_EMPTY
))
return
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS
))
if
classify
==
consts
.
IC_CLASSIFY
:
for
id_card_dict
in
license_data
:
try
:
base64_img
=
id_card_dict
.
pop
(
'base64_img'
)
except
Exception
as
e
:
continue
else
:
card_type
=
-
1
json_data_4
=
{
'mode'
:
1
,
'user_info'
:
{
'image_content'
:
base64_img
,
},
'options'
:
{
'distinguish_type'
:
1
,
'auto_rotate'
:
True
,
},
}
for
times
in
range
(
consts
.
RETRY_TIMES
):
try
:
start_time
=
time
.
time
()
ocr_4_response
=
requests
.
post
(
self
.
ocr_url_4
,
json
=
json_data_4
)
if
ocr_4_response
.
status_code
!=
200
:
raise
OCR4Exception
(
'ocr_4 status code: {0}'
.
format
(
ocr_4_response
.
status_code
))
except
Exception
as
e
:
self
.
cronjob_log
.
warn
(
'{0} [ocr_4 failed] [times={1}] [img_path={2}] [error={3}]'
.
format
(
self
.
log_base
,
times
,
img_path
,
traceback
.
format_exc
()))
else
:
ocr_4_res
=
ocr_4_response
.
json
()
end_time
=
time
.
time
()
speed_time
=
int
(
end_time
-
start_time
)
if
ocr_4_res
.
get
(
'code'
)
==
0
and
ocr_4_res
.
get
(
'result'
,
{})
.
get
(
'rtn'
)
==
0
:
card_type
=
ocr_4_res
.
get
(
'result'
,
{})
.
get
(
'idcard_distinguish_result'
,
{})
.
get
(
'result'
,
-
1
)
self
.
cronjob_log
.
info
(
'{0} [ocr_4 success] [img_path={1}] [speed_time={2}]'
.
format
(
self
.
log_base
,
img_path
,
speed_time
))
break
else
:
self
.
cronjob_log
.
warn
(
'{0} [ocr_4 failed] [img_path={1}]'
.
format
(
self
.
log_base
,
img_path
))
id_card_dict
[
consts
.
IC_TURE_OR_FALSE
]
=
consts
.
IC_RES_MAPPING
.
get
(
card_type
)
license_summary
.
setdefault
(
classify
,
[])
.
extend
(
license_data
)
@staticmethod
...
...
@@ -84,7 +130,8 @@ class Command(BaseCommand, LoggerMixin):
if
isinstance
(
data_list
,
list
):
for
part_idx
,
ocr_data
in
enumerate
(
data_list
):
part_idx
=
part_idx
+
1
self
.
license1_process
(
ocr_data
,
license_summary
,
classify
,
res_list
,
pno
,
ino
,
part_idx
)
self
.
license1_process
(
ocr_data
,
license_summary
,
classify
,
res_list
,
pno
,
ino
,
part_idx
,
img_path
)
else
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_FAILED_3
))
else
:
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment