Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
d8dfdc92
P
PaddleOCR
项目概览
weixin_41840029
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d8dfdc92
编写于
2月 23, 2022
作者:
z37757
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use Polygon from shapely
上级
3352ddb3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
20 deletion
+18
-20
ppocr/data/imaug/fce_aug.py
ppocr/data/imaug/fce_aug.py
+5
-5
ppocr/utils/poly_nms.py
ppocr/utils/poly_nms.py
+13
-15
未找到文件。
ppocr/data/imaug/fce_aug.py
浏览文件 @
d8dfdc92
...
...
@@ -18,7 +18,7 @@ https://github.com/open-mmlab/mmocr/blob/main/mmocr/datasets/pipelines/transform
import
numpy
as
np
from
PIL
import
Image
,
ImageDraw
import
cv2
import
Polygon
as
plg
from
shapely.geometry
import
Polygon
import
math
from
ppocr.utils.poly_nms
import
poly_intersection
...
...
@@ -129,16 +129,16 @@ class RandomCropFlip:
pts
=
np
.
stack
([[
xmin
,
xmax
,
xmax
,
xmin
],
[
ymin
,
ymin
,
ymax
,
ymax
]]).
T
.
astype
(
np
.
int32
)
pp
=
plg
.
Polygon
(
pts
)
pp
=
Polygon
(
pts
)
fail_flag
=
False
for
polygon
,
ignore_tag
in
zip
(
polygons
,
ignore_tags
):
ppi
=
plg
.
Polygon
(
polygon
.
reshape
(
-
1
,
2
))
ppi
=
Polygon
(
polygon
.
reshape
(
-
1
,
2
))
ppiou
,
_
=
poly_intersection
(
ppi
,
pp
)
if
np
.
abs
(
ppiou
-
float
(
ppi
.
area
()
))
>
self
.
epsilon
and
\
if
np
.
abs
(
ppiou
-
float
(
ppi
.
area
))
>
self
.
epsilon
and
\
np
.
abs
(
ppiou
)
>
self
.
epsilon
:
fail_flag
=
True
break
elif
np
.
abs
(
ppiou
-
float
(
ppi
.
area
()
))
<
self
.
epsilon
:
elif
np
.
abs
(
ppiou
-
float
(
ppi
.
area
))
<
self
.
epsilon
:
polys_new
.
append
(
polygon
)
ignore_tags_new
.
append
(
ignore_tag
)
else
:
...
...
ppocr/utils/poly_nms.py
浏览文件 @
d8dfdc92
...
...
@@ -13,7 +13,7 @@
# limitations under the License.
import
numpy
as
np
import
Polygon
as
plg
from
shapely.geometry
import
Polygon
def
points2polygon
(
points
):
...
...
@@ -33,7 +33,7 @@ def points2polygon(points):
assert
(
points
.
size
%
2
==
0
)
and
(
points
.
size
>=
8
)
point_mat
=
points
.
reshape
([
-
1
,
2
])
return
plg
.
Polygon
(
point_mat
)
return
Polygon
(
point_mat
)
def
poly_intersection
(
poly_det
,
poly_gt
):
...
...
@@ -46,13 +46,11 @@ def poly_intersection(poly_det, poly_gt):
Returns:
intersection_area (float): The intersection area between two polygons.
"""
assert
isinstance
(
poly_det
,
plg
.
Polygon
)
assert
isinstance
(
poly_gt
,
plg
.
Polygon
)
assert
isinstance
(
poly_det
,
Polygon
)
assert
isinstance
(
poly_gt
,
Polygon
)
poly_inter
=
poly_det
&
poly_gt
if
len
(
poly_inter
)
==
0
:
return
0
,
poly_inter
return
poly_inter
.
area
(),
poly_inter
poly_inter
=
poly_det
.
buffer
(
0.001
)
&
poly_gt
.
buffer
(
0.001
)
return
poly_inter
.
area
,
poly_inter
def
poly_union
(
poly_det
,
poly_gt
):
...
...
@@ -65,11 +63,11 @@ def poly_union(poly_det, poly_gt):
Returns:
union_area (float): The union area between two polygons.
"""
assert
isinstance
(
poly_det
,
plg
.
Polygon
)
assert
isinstance
(
poly_gt
,
plg
.
Polygon
)
assert
isinstance
(
poly_det
,
Polygon
)
assert
isinstance
(
poly_gt
,
Polygon
)
area_det
=
poly_det
.
area
()
area_gt
=
poly_gt
.
area
()
area_det
=
poly_det
.
area
area_gt
=
poly_gt
.
area
area_inters
,
_
=
poly_intersection
(
poly_det
,
poly_gt
)
return
area_det
+
area_gt
-
area_inters
...
...
@@ -114,8 +112,8 @@ def poly_iou(poly_det, poly_gt):
Returns:
iou (float): The IOU between two polygons.
"""
assert
isinstance
(
poly_det
,
plg
.
Polygon
)
assert
isinstance
(
poly_gt
,
plg
.
Polygon
)
assert
isinstance
(
poly_det
,
Polygon
)
assert
isinstance
(
poly_gt
,
Polygon
)
area_inters
,
_
=
poly_intersection
(
poly_det
,
poly_gt
)
area_union
=
poly_union
(
poly_det
,
poly_gt
)
if
area_union
==
0
:
...
...
@@ -142,4 +140,4 @@ def poly_nms(polygons, threshold):
remove_index
=
np
.
where
(
iou_list
>
threshold
)
index
=
np
.
delete
(
index
,
remove_index
)
return
keep_poly
\ No newline at end of file
return
keep_poly
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录