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
98e8884c
authored
2024-10-29 14:40:43 +0800
by
chenyao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
ocr_process添加try-except处理前半部分
1 parent
75d18a3c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/management/commands/ocr_process.py
View file @
98e8884
...
...
@@ -178,6 +178,8 @@ class Command(BaseCommand, LoggerMixin):
# self.online_log.info('{0} [edms download success] [pdf_path={1}]'.format(self.log_base, pdf_path))
def
bs_process
(
self
,
wb
,
ocr_data
,
bs_summary
,
unknown_summary
,
classify
,
res_list
,
pno
,
ino
,
part_idx
):
# 添加 try-except 处理
try
:
sheets
=
ocr_data
.
get
(
'data'
,
[])
if
not
sheets
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS_EMPTY
))
...
...
@@ -265,9 +267,14 @@ class Command(BaseCommand, LoggerMixin):
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS
))
else
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS_EMPTY
))
except
Exception
as
e
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_FAILED
))
self
.
online_log
.
error
(
'{0} [bs_process error] [error={1}]'
.
format
(
self
.
log_base
,
traceback
.
format_exc
()))
def
contract_process
(
self
,
classify
,
ocr_data
,
contract_result
,
res_list
,
pno
,
ino
,
part_idx
,
img_path
,
contract_result_compare
):
# 添加 try-except 处理
try
:
contract_dict
=
ocr_data
.
get
(
'data'
)
if
not
contract_dict
or
contract_dict
.
get
(
'page_num'
)
is
None
or
contract_dict
.
get
(
'page_info'
)
is
None
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS_EMPTY
))
...
...
@@ -343,6 +350,8 @@ class Command(BaseCommand, LoggerMixin):
contract_result_compare
.
setdefault
(
classify
,
dict
())[
consts
.
ASP_KEY
]
=
contract_dict
.
get
(
consts
.
ASP_KEY
,
False
)
# "position" = [xmin, ymin, xmax, ymax]
contract_result_compare
.
setdefault
(
classify
,
dict
())[
page_num_only
]
=
page_compare_dict
except
Exception
as
e
:
self
.
online_log
.
error
(
'{0} [contract_process error] [error={1}]'
.
format
(
self
.
log_base
,
traceback
.
format_exc
()))
@staticmethod
def
rebuild_position
(
src_position
):
...
...
@@ -372,6 +381,8 @@ class Command(BaseCommand, LoggerMixin):
def
license1_process
(
self
,
ocr_data
,
license_summary
,
classify
,
res_list
,
pno
,
ino
,
part_idx
,
img_path
,
do_dda
,
dda_id_bc_mapping
):
# 添加 try-except 处理
try
:
# 类别:'0'身份证, '1'居住证
license_data
=
ocr_data
.
get
(
'data'
)
if
not
license_data
:
...
...
@@ -713,8 +724,13 @@ class Command(BaseCommand, LoggerMixin):
res_dict
[
consts
.
SECTION_IMG_PATH_KEY
]
=
section_img_path
license_summary
.
setdefault
(
classify
,
[])
.
extend
(
license_data
)
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS
))
except
Exception
as
e
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_FAILED
))
self
.
online_log
.
error
(
'{0} [license1_process error] [error={1}]'
.
format
(
self
.
log_base
,
traceback
.
format_exc
()))
def
license2_process
(
self
,
ocr_res_2
,
license_summary
,
pid
,
classify
,
res_list
,
pno
,
ino
,
part_idx
,
img_path
,
do_dda
,
dda_id_bc_mapping
,
file_data
):
# 添加 try-except 处理
try
:
if
ocr_res_2
.
get
(
'ErrorCode'
)
in
consts
.
SUCCESS_CODE_SET
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_SUCCESS
))
if
pid
==
consts
.
BC_PID
:
...
...
@@ -777,9 +793,14 @@ class Command(BaseCommand, LoggerMixin):
' [part_idx={2}]'
.
format
(
self
.
log_base
,
img_path
,
part_idx
))
else
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_FAILED_2
))
except
Exception
as
e
:
res_list
.
append
((
pno
,
ino
,
part_idx
,
consts
.
RES_FAILED_2
))
self
.
online_log
.
error
(
'{0} [license2_process error] [error={1}]'
.
format
(
self
.
log_base
,
traceback
.
format_exc
()))
@staticmethod
def
license_rebuild
(
license_summary
):
# 添加 try-except 处理
try
:
ic_merge
=
False
rp_merge
=
False
...
...
@@ -854,17 +875,31 @@ class Command(BaseCommand, LoggerMixin):
page_1_2
=
page_3_4
=
None
return
ic_merge
,
rp_merge
except
Exception
as
e
:
print
(
"license_rebuild error"
)
print
(
traceback
.
format_exc
())
return
False
,
False
def
parse_img_path
(
self
,
img_path
):
# 添加 try-except 处理
try
:
img_name
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
img_path
))
part_list
=
img_name
.
split
(
'_'
)
# page_7_img_11_0
return
int
(
part_list
[
1
])
+
1
,
int
(
part_list
[
3
])
+
1
except
Exception
as
e
:
self
.
online_log
.
error
(
'{0} [parse_img_path error] [error={1}]'
.
format
(
self
.
log_base
,
traceback
.
format_exc
()))
return
0
,
0
def
get_most
(
self
,
value_list
):
# 添加 try-except 处理
try
:
if
value_list
:
most_common
=
Counter
(
value_list
)
.
most_common
(
1
)
return
most_common
[
0
][
0
]
if
most_common
else
None
except
Exception
as
e
:
self
.
online_log
.
error
(
'{0} [get_most error] [error={1}]'
.
format
(
self
.
log_base
,
traceback
.
format_exc
()))
return
None
def
date_format
(
self
,
date_str
,
format_str
):
try
:
...
...
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