Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Commits
96de1ffb
Commit
96de1ffb
authored
2 years ago
by
Solene Tarride
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue when no contour is found
parent
e5776db4
No related branches found
No related tags found
1 merge request
!76
Add predicted objects to predict command
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dan/predict/attention.py
+10
-3
10 additions, 3 deletions
dan/predict/attention.py
with
10 additions
and
3 deletions
dan/predict/attention.py
+
10
−
3
View file @
96de1ffb
...
@@ -190,7 +190,7 @@ def polygon_to_bbx(polygon):
...
@@ -190,7 +190,7 @@ def polygon_to_bbx(polygon):
return
[[
x
,
y
],
[
x
+
w
,
y
],
[
x
+
w
,
y
+
h
],
[
x
,
y
+
h
]]
return
[[
x
,
y
],
[
x
+
w
,
y
],
[
x
+
w
,
y
+
h
],
[
x
,
y
+
h
]]
def
threshold
(
mask
,
method
=
"
threshold
"
,
thresh
=
0
):
def
threshold
(
mask
,
method
=
"
otsu
"
,
thresh
=
0
):
"""
"""
Threshold a grayscale mask.
Threshold a grayscale mask.
:param mask: a grayscale image (np.array)
:param mask: a grayscale image (np.array)
...
@@ -208,7 +208,7 @@ def threshold(mask, method="threshold", thresh=0):
...
@@ -208,7 +208,7 @@ def threshold(mask, method="threshold", thresh=0):
# Blur and apply Otsu thresholding
# Blur and apply Otsu thresholding
blur
=
cv2
.
GaussianBlur
(
mask
,
(
15
,
15
),
0
)
blur
=
cv2
.
GaussianBlur
(
mask
,
(
15
,
15
),
0
)
_
,
bin_mask
=
cv2
.
threshold
(
blur
,
0
,
255
,
cv2
.
THRESH_BINARY
+
cv2
.
THRESH_OTSU
)
_
,
bin_mask
=
cv2
.
threshold
(
blur
,
0
,
255
,
cv2
.
THRESH_BINARY
+
cv2
.
THRESH_OTSU
)
# Apply dilation
with
# Apply dilation
kernel_width
=
cv2
.
getStructuringElement
(
kernel_width
=
cv2
.
getStructuringElement
(
cv2
.
MORPH_CROSS
,
(
max_kernel
,
min_kernel
)
cv2
.
MORPH_CROSS
,
(
max_kernel
,
min_kernel
)
)
)
...
@@ -239,6 +239,11 @@ def get_polygon(text, max_value, offset, weights, size=None, return_contours=Fal
...
@@ -239,6 +239,11 @@ def get_polygon(text, max_value, offset, weights, size=None, return_contours=Fal
# Detect the objects contours
# Detect the objects contours
contours
,
_
=
cv2
.
findContours
(
bin_mask
,
cv2
.
RETR_EXTERNAL
,
cv2
.
CHAIN_APPROX_SIMPLE
)
contours
,
_
=
cv2
.
findContours
(
bin_mask
,
cv2
.
RETR_EXTERNAL
,
cv2
.
CHAIN_APPROX_SIMPLE
)
if
not
contours
:
if
return_contours
:
return
{},
None
return
{}
# Select best contour
# Select best contour
metrics
=
[
compute_contour_metrics
(
coverage_vector
,
cnt
)
for
cnt
in
contours
]
metrics
=
[
compute_contour_metrics
(
coverage_vector
,
cnt
)
for
cnt
in
contours
]
confidences
,
scores
=
map
(
list
,
zip
(
*
metrics
))
confidences
,
scores
=
map
(
list
,
zip
(
*
metrics
))
...
@@ -314,7 +319,9 @@ def plot_attention(
...
@@ -314,7 +319,9 @@ def plot_attention(
(
width
,
height
),
(
width
,
height
),
return_contours
=
True
,
return_contours
=
True
,
)
)
cv2
.
drawContours
(
coverage_vector
,
[
contour
],
0
,
(
255
),
3
)
if
contour
is
not
None
:
cv2
.
drawContours
(
coverage_vector
,
[
contour
],
0
,
(
255
),
5
)
# Keep track of text length
# Keep track of text length
tot_len
+=
len
(
text_piece
)
+
offset
tot_len
+=
len
(
text_piece
)
+
offset
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment