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
0347cfa5
authored
2021-03-24 16:12:29 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
license result rebuild
1 parent
2a706abb
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
41 deletions
src/apps/doc/management/commands/idcard_daily.py
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/ocr/wb.py
src/common/mixins.py
src/apps/doc/management/commands/idcard_daily.py
View file @
0347cfa
...
...
@@ -68,8 +68,8 @@ class Command(BaseCommand, LoggerMixin):
nation
=
idcard_dict
.
get
(
'民族'
)
if
nation
is
None
:
continue
if
idcard_dict
.
get
(
'类别'
)
==
'1'
:
continue
#
if idcard_dict.get('类别') == '1':
#
continue
content_list
.
append
((
idcard_dict
.
get
(
'公民身份号码'
),
nation
))
if
len
(
content_list
)
==
0
:
continue
...
...
src/apps/doc/management/commands/ocr_process.py
View file @
0347cfa
...
...
@@ -298,6 +298,54 @@ class Command(BaseCommand, LoggerMixin):
else
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_FAILED_2
))
@staticmethod
def
license_rebuild
(
license_summary
):
for
classify
in
(
consts
.
IC_CLASSIFY
,
consts
.
MVI_CLASSIFY
):
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
if
classify
==
consts
.
IC_CLASSIFY
:
# 身份证、居住证分开,先正面,后反面
key
,
_
,
_
=
consts
.
FIELD_ORDER_MAP
.
get
(
classify
)
ic_side1_list
=
[]
ic_side2_list
=
[]
rp_side1_list
=
[]
rp_side2_list
=
[]
for
license_dict
in
license_list
:
if
key
in
license_dict
:
if
license_dict
.
get
(
'类别'
)
==
'1'
:
rp_side2_list
.
append
(
license_dict
)
ic_side2_list
.
append
(
license_dict
)
elif
license_dict
.
get
(
'类别'
)
==
'1'
:
rp_side1_list
.
append
(
license_dict
)
else
:
ic_side1_list
.
append
(
license_dict
)
ic_side1_list
.
extend
(
ic_side2_list
)
rp_side1_list
.
extend
(
rp_side2_list
)
license_summary
[
consts
.
RP_CLASSIFY
]
=
rp_side1_list
license_list
=
ic_side1_list
ic_side1_list
=
ic_side2_list
=
rp_side1_list
=
rp_side2_list
=
None
if
classify
==
consts
.
MVI_CLASSIFY
:
# 机动车销售统一发票, 增加不含税价(逻辑计算)
for
license_dict
in
license_list
:
price
=
''
rate_str
=
license_dict
.
get
(
'增值税税率'
)
price_total_str
=
license_dict
.
get
(
'价税合计小写'
)
if
rate_str
is
not
None
and
price_total_str
is
not
None
:
try
:
rate
=
int
(
rate_str
.
rstrip
(
'
%
'
))
price_total
=
float
(
price_total_str
)
except
Exception
as
e
:
pass
else
:
price
=
round
(
price_total
*
100
/
(
rate
+
100
),
2
)
license_dict
[
'不含税价(逻辑计算)'
]
=
price
def
parse_img_path
(
self
,
img_path
):
img_name
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
img_path
))
part_list
=
img_name
.
split
(
'_'
)
...
...
@@ -735,23 +783,24 @@ class Command(BaseCommand, LoggerMixin):
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_FAILED_1
))
self
.
online_log
.
info
(
'{0} [ocr_1 res error] [img={1}]'
.
format
(
self
.
log_base
,
img_path
))
self
.
online_log
.
info
(
'{0} [task={1}] [bs_summary={2}] [unknown_summary={3}] '
'[license_summary={4}]'
.
format
(
self
.
log_base
,
task_str
,
bs_summary
,
unknown_summary
,
license_summary
))
self
.
online_log
.
info
(
'{0} [task={1}] [bs_summary={2}] [unknown_summary={3}]'
.
format
(
self
.
log_base
,
task_str
,
bs_summary
,
unknown_summary
))
self
.
license_log
.
info
(
'[task={0}] [license_summary={1}]'
.
format
(
task_str
,
license_summary
))
#
self.license_log.info('[task={0}] [license_summary={1}]'.format(task_str, license_summary))
idcard_list
=
license_summary
.
get
(
consts
.
IC_CLASSIFY
)
if
idcard_list
:
self
.
idcard_log
.
info
(
'[task={0}] [idcard={1}]'
.
format
(
task_str
,
idcard_list
))
merged_bs_summary
=
self
.
rebuild_bs_summary
(
bs_summary
,
unknown_summary
)
del
unknown_summary
self
.
license_rebuild
(
license_summary
)
self
.
bs_log
.
info
(
'[task={0}] [bs_summary={1}]'
.
format
(
task_str
,
merged_bs_summary
))
#
self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary))
self
.
online_log
.
info
(
'{0} [task={1}] [merged_bs_summary={2}] [
unknown
_summary={3}] '
self
.
online_log
.
info
(
'{0} [task={1}] [merged_bs_summary={2}] [
license
_summary={3}] '
'[res_list={4}]'
.
format
(
self
.
log_base
,
task_str
,
merged_bs_summary
,
unknown_summary
,
res_list
))
del
unknown_summary
license_summary
,
res_list
))
except
Exception
as
e
:
...
...
src/apps/doc/ocr/wb.py
View file @
0347cfa
...
...
@@ -638,43 +638,14 @@ class BSWorkbook(Workbook):
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
if
classify
==
consts
.
IC_CLASSIFY
:
# 身份证、居住证先正面,后反面
key
,
_
,
_
=
consts
.
FIELD_ORDER_MAP
.
get
(
classify
)
side1_list
=
[]
side2_list
=
[]
for
license_dict
in
license_list
:
if
key
in
license_dict
:
side2_list
.
append
(
license_dict
)
else
:
side1_list
.
append
(
license_dict
)
side1_list
.
extend
(
side2_list
)
license_list
=
side1_list
side2_list
=
None
side1_list
=
None
count
=
0
ws
=
self
.
create_sheet
(
name
)
if
scheme_diff
and
document_scheme
==
consts
.
DOC_SCHEME_LIST
[
1
]:
classify
=
consts
.
MVC_CLASSIFY_SE
for
license_dict
in
license_list
:
if
classify
==
consts
.
IC_CLASSIFY
and
license_dict
.
get
(
'类别'
)
==
'1'
:
# 居住证处理
license_summary
.
setdefault
(
consts
.
RP_CLASSIFY
,
[])
.
append
(
license_dict
)
continue
if
side_diff
:
key
,
field_order_yes
,
field_order_no
=
consts
.
FIELD_ORDER_MAP
.
get
(
classify
)
field_order
=
field_order_yes
if
key
in
license_dict
else
field_order_no
if
classify
==
consts
.
MVI_CLASSIFY
:
# 机动车销售统一发票, 增加不含税价(逻辑计算)
price
=
''
rate_str
=
license_dict
.
get
(
'增值税税率'
)
price_total_str
=
license_dict
.
get
(
'价税合计小写'
)
if
rate_str
is
not
None
and
price_total_str
is
not
None
:
try
:
rate
=
int
(
rate_str
.
rstrip
(
'
%
'
))
price_total
=
float
(
price_total_str
)
except
Exception
as
e
:
pass
else
:
price
=
round
(
price_total
*
100
/
(
rate
+
100
),
2
)
license_dict
[
'不含税价(逻辑计算)'
]
=
price
for
search_field
,
write_field
in
field_order
:
field_value
=
license_dict
.
get
(
search_field
,
''
)
if
isinstance
(
field_value
,
list
):
...
...
src/common/mixins.py
View file @
0347cfa
...
...
@@ -40,8 +40,8 @@ class LoggerMixin:
exception_log
=
logging
.
getLogger
(
'exception'
)
online_log
=
logging
.
getLogger
(
'online'
)
folder_log
=
logging
.
getLogger
(
'folder'
)
bs_log
=
logging
.
getLogger
(
'bs'
)
license_log
=
logging
.
getLogger
(
'license'
)
#
bs_log = logging.getLogger('bs')
#
license_log = logging.getLogger('license')
idcard_log
=
logging
.
getLogger
(
'idcard'
)
...
...
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