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
8cf3f917
authored
2021-11-11 17:23:45 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix mvc slice
1 parent
57a6afc2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
7 deletions
src/apps/doc/management/commands/ocr_process.py
src/celery_compare/tasks.py
src/apps/doc/management/commands/ocr_process.py
View file @
8cf3f91
...
...
@@ -452,7 +452,8 @@ class Command(BaseCommand, LoggerMixin):
detail_dict
.
get
(
'words'
,
''
))
tmp_position_list
=
detail_dict
.
get
(
'position'
,
[
0
,
0
,
0
,
0
])
if
len
(
tmp_position_list
)
==
4
:
position_dict
[
cn_key
]
=
{
position_dict
.
setdefault
(
cn_key
,
[])
.
append
(
{
consts
.
FIELD_POSITION_KEY
:
{
'top'
:
tmp_position_list
[
1
],
'left'
:
tmp_position_list
[
0
],
...
...
@@ -460,6 +461,8 @@ class Command(BaseCommand, LoggerMixin):
'width'
:
tmp_position_list
[
2
],
}
}
)
rebuild_data_dict
[
consts
.
ALL_POSITION_KEY_2
]
=
position_dict
rebuild_data_dict
[
consts
.
IMG_PATH_KEY_2
]
=
img_path
rebuild_data_dict
[
consts
.
SECTION_IMG_PATH_KEY_2
]
=
section_img_path
...
...
src/celery_compare/tasks.py
View file @
8cf3f91
...
...
@@ -373,8 +373,8 @@ def ca_compare_license(license_en, ocr_res_dict, field_list):
if
ocr_res_str
is
not
None
:
ocr_res_list
=
json
.
loads
(
ocr_res_str
)
# 副页去除
TODO
3/4页去除
if
ocr_field
==
consts
.
DL_OCR_FIELD
:
# 副页去除 3/4页去除
if
ocr_field
==
consts
.
DL_OCR_FIELD
or
ocr_field
==
consts
.
MVC_OCR_FIELD
:
tmp_list
=
[]
for
res
in
ocr_res_list
:
if
compare_logic
[
'vinNo'
][
0
]
in
res
:
...
...
@@ -1433,6 +1433,15 @@ def se_compare_license(license_en, ocr_res_dict, field_list):
ocr_res_str
=
ocr_res_dict
.
get
(
ocr_field
)
if
ocr_res_str
is
not
None
:
ocr_res_list
=
json
.
loads
(
ocr_res_str
)
# 3/4页去除
if
ocr_field
==
consts
.
MVC_OCR_FIELD
:
tmp_list
=
[]
for
res
in
ocr_res_list
:
if
compare_logic
[
'vinNo'
][
0
]
in
res
:
tmp_list
.
append
(
res
)
ocr_res_list
=
tmp_list
length
=
len
(
ocr_res_list
)
# 身份证、居住证 过期期限特殊处理
...
...
@@ -1571,6 +1580,7 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
is_find
=
False
result_field_list
=
[]
field_img_path_dict
=
dict
()
if
ocr_res_str
is
not
None
:
ocr_res_list
=
json
.
loads
(
ocr_res_str
)
...
...
@@ -1580,7 +1590,8 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
first_res
=
None
for
res_idx
in
range
(
length
-
1
,
-
1
,
-
1
):
if
consts
.
TRANSFER_DATE
in
ocr_res_list
[
res_idx
]:
img_path
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
IMG_PATH_KEY
,
''
)
img_path
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
IMG_PATH_KEY_2
,
''
)
section_img_path
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
SECTION_IMG_PATH_KEY_2
,
''
)
for
idx
,
transfer_date
in
enumerate
(
ocr_res_list
[
res_idx
]
.
get
(
consts
.
TRANSFER_DATE
,
[])):
try
:
transfer_name
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
TRANSFER_NAME
,
[])[
idx
]
...
...
@@ -1590,11 +1601,32 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
transfer_num
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
TRANSFER_NUM
,
[])[
idx
]
except
Exception
as
e
:
transfer_num
=
empty_str
try
:
position_info_date
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
ALL_POSITION_KEY_2
,
dict
())
.
get
(
consts
.
TRANSFER_DATE
,
[])[
idx
]
except
Exception
as
e
:
position_info_date
=
{}
try
:
position_info_name
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
ALL_POSITION_KEY_2
,
dict
())
.
get
(
consts
.
TRANSFER_NAME
,
[])[
idx
]
except
Exception
as
e
:
position_info_name
=
{}
try
:
position_info_num
=
ocr_res_list
[
res_idx
]
.
get
(
consts
.
ALL_POSITION_KEY_2
,
dict
())
.
get
(
consts
.
TRANSFER_NUM
,
[])[
idx
]
except
Exception
as
e
:
position_info_num
=
{}
core_info
=
{
consts
.
TRANSFER_NAME
:
transfer_name
,
consts
.
TRANSFER_NUM
:
transfer_num
,
consts
.
TRANSFER_DATE
:
transfer_date
,
consts
.
IMG_PATH_KEY
:
img_path
,
consts
.
IMG_PATH_KEY_2
:
img_path
,
consts
.
SECTION_IMG_PATH_KEY_2
:
section_img_path
,
consts
.
ALL_POSITION_KEY
:
{
consts
.
TRANSFER_NAME
:
position_info_name
,
consts
.
TRANSFER_NUM
:
position_info_num
,
consts
.
TRANSFER_DATE
:
position_info_date
,
},
}
page34_date_dict
.
setdefault
(
transfer_date
,
[])
.
append
(
core_info
)
if
first_res
is
None
:
...
...
@@ -1613,6 +1645,8 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
if
max_date
is
not
None
or
first_res
is
not
None
:
is_find
=
True
ocr_res
=
first_res
if
max_date
is
None
else
page34_date_dict
[
time
.
strftime
(
'
%
Y-
%
m-
%
d'
,
max_date
)][
0
]
failed_field
=
[]
base_img_path
=
ocr_res
.
get
(
consts
.
IMG_PATH_KEY_2
,
''
)
for
name
,
value
in
field_list
:
ocr_str
=
ocr_res
.
get
(
compare_logic
[
name
][
0
])
if
not
isinstance
(
ocr_str
,
str
):
...
...
@@ -1620,15 +1654,42 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
ocr_str
=
empty_str
else
:
result
=
getattr
(
cp
,
compare_logic
[
name
][
1
])(
value
,
ocr_str
,
**
compare_logic
[
name
][
2
])
img_path
=
ocr_res
.
get
(
consts
.
IMG_PATH_KEY
,
''
)
if
result
==
consts
.
RESULT_N
else
empty_str
img_path
=
base_img_path
if
result
==
consts
.
RESULT_N
else
empty_str
error_type
=
empty_error_type
if
result
==
consts
.
RESULT_Y
else
ErrorType
.
OCR
.
value
result_field_list
.
append
((
name
,
value
,
result
,
ocr_str
,
img_path
,
error_type
))
if
result
==
consts
.
RESULT_N
:
failed_field
.
append
(
name
)
section_img_path
=
ocr_res
.
get
(
consts
.
SECTION_IMG_PATH_KEY_2
,
''
)
if
len
(
failed_field
)
>
0
and
os
.
path
.
exists
(
section_img_path
):
info
=
ocr_res
.
get
(
consts
.
ALL_POSITION_KEY
,
{})
try
:
last_img
=
img_process
(
section_img_path
,
{},
0
)
except
Exception
as
e
:
for
field
in
failed_field
:
field_img_path_dict
[
field
]
=
base_img_path
else
:
pre
,
suf
=
os
.
path
.
splitext
(
section_img_path
)
for
field
in
failed_field
:
try
:
res_field
=
compare_logic
[
field
][
0
]
is_valid
,
coord_tuple
=
field_build_coordinates
(
info
.
get
(
res_field
,
{}))
if
is_valid
:
save_path
=
'{0}_{1}{2}'
.
format
(
pre
,
field
,
suf
)
field_img
=
last_img
[
coord_tuple
[
0
]:
coord_tuple
[
1
],
coord_tuple
[
2
]:
coord_tuple
[
3
],
:]
cv2
.
imwrite
(
save_path
,
field_img
)
field_img_path_dict
[
field
]
=
save_path
else
:
field_img_path_dict
[
field
]
=
base_img_path
except
Exception
as
e
:
field_img_path_dict
[
field
]
=
base_img_path
if
not
is_find
:
for
name
,
value
in
field_list
:
result_field_list
.
append
((
name
,
value
,
consts
.
RESULT_N
,
empty_str
,
empty_str
,
ErrorType
.
NF
.
value
))
return
result_field_list
,
dict
()
return
result_field_list
,
field_img_path_dict
def
se_compare_process
(
compare_info
,
ocr_res_dict
):
...
...
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