Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
part_of_F3_OCR
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a379fac9
authored
2022-09-06 16:26:19 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix key search
1 parent
c0cf9254
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
14 deletions
README.md
authorization_from/retriever.py
README.md
View file @
a379fac
...
...
@@ -23,6 +23,7 @@ print(res)
# {'words_result':
# {'姓名': {'words': 'xx', 'score': 1, 'location': {'left': 105, 'top': 277, 'width': 60, 'height': 28}},
# '个人身份证件号码': {'words': 'xx', 'score': 1, 'location': {'left': 320, 'top': 278, 'widtght': 24}},
# '经销商名称': {'words': 'xx', 'score': 1, 'location': {'left': 320, 'top': 278, 'widtght': 24}},
# '签字': {'words': '有', 'score': 1, 'location': {'left': 540, 'top': 1293, 'width': 143, 'height': 91}}}
# }
...
...
authorization_from/retriever.py
View file @
a379fac
...
...
@@ -31,11 +31,15 @@ class Retriever:
coordinates_list
.
sort
(
key
=
lambda
x
:
x
[
1
])
return
coordinates_list
[
0
]
@staticmethod
def
key_right
(
coordinates_list
,
key_coordinates
,
top_padding
,
bottom_padding
,
scope
):
def
key_right
(
self
,
coordinates_list
,
key_coordinates
,
top_padding
,
bottom_padding
,
scope
):
# 关键词查找方向:右侧
if
len
(
coordinates_list
)
==
1
:
return
coordinates_list
[
0
]
# 没有上一层关键词的坐标时,返回最上面的坐标
if
key_coordinates
is
None
:
return
self
.
key_top1
(
coordinates_list
,
key_coordinates
)
height
=
key_coordinates
[
-
1
]
-
key_coordinates
[
1
]
y_min
=
key_coordinates
[
1
]
-
(
top_padding
*
height
)
y_max
=
key_coordinates
[
-
1
]
+
(
bottom_padding
*
height
)
...
...
@@ -45,15 +49,19 @@ class Retriever:
x_max
=
key_coordinates
[
2
]
+
(
width
*
scope
)
x_min_find
=
None
key_coordinates
=
None
find_
key_coordinates
=
None
for
x0
,
y0
,
x1
,
y1
in
coordinates_list
:
cent_x
=
x0
+
((
x1
-
x0
)
/
2
)
cent_y
=
y0
+
((
y1
-
y0
)
/
2
)
if
x_min
<
cent_x
<
x_max
and
y_min
<
cent_y
<
y_max
:
if
x_min_find
is
None
or
x0
<
x_min_find
:
x_min_find
=
x0
key_coordinates
=
(
x0
,
y0
,
x1
,
y1
)
return
key_coordinates
find_key_coordinates
=
(
x0
,
y0
,
x1
,
y1
)
if
find_key_coordinates
is
None
:
return
self
.
key_top1
(
coordinates_list
,
key_coordinates
)
else
:
return
find_key_coordinates
def
value_right
(
self
,
go_res
,
key_coordinates
,
top_padding
,
bottom_padding
,
scope
,
value_type
=
None
):
# 字段值查找方向:右侧
...
...
@@ -147,19 +155,17 @@ class Retriever:
# 搜索关键词
key_coordinates_info
=
dict
()
for
field
,
key_text_list
in
self
.
target_fields
[
self
.
keys_str
]
.
items
():
pre
_key_coordinates
=
None
last
_key_coordinates
=
None
for
key_text
,
_
,
direction
,
kwargs
in
key_text_list
:
if
key_text
not
in
key_text_info
:
break
key_coordinates
=
getattr
(
self
,
'key_{0}'
.
format
(
direction
))(
last_key_coordinates
=
None
continue
last_key_coordinates
=
getattr
(
self
,
'key_{0}'
.
format
(
direction
))(
key_text_info
[
key_text
],
pre
_key_coordinates
,
last
_key_coordinates
,
**
kwargs
)
if
not
isinstance
(
key_coordinates
,
tuple
):
break
pre_key_coordinates
=
key_coordinates
else
:
key_coordinates_info
[
field
]
=
pre_key_coordinates
key_coordinates_info
[
field
]
=
last_key_coordinates
# 搜索字段值
value_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