Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不会修仙的道士
labelme
提交
c978e80f
L
labelme
项目概览
不会修仙的道士
/
labelme
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
labelme
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
GitCode(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c978e80f
编写于
6月 13, 2018
作者:
A
AlexMarshall011
提交者:
Kentaro Wada
6月 14, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add feature of adding vertex
上级
3930b90d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
1 deletion
+52
-1
labelme/canvas.py
labelme/canvas.py
+23
-1
labelme/lib.py
labelme/lib.py
+14
-0
labelme/shape.py
labelme/shape.py
+15
-0
未找到文件。
labelme/canvas.py
浏览文件 @
c978e80f
...
...
@@ -52,6 +52,7 @@ class Canvas(QtWidgets.QWidget):
self
.
hideBackround
=
False
self
.
hShape
=
None
self
.
hVertex
=
None
self
.
addVertex
=
None
self
.
movingShape
=
False
self
.
_painter
=
QtGui
.
QPainter
()
self
.
_cursor
=
CURSOR_DEFAULT
...
...
@@ -116,6 +117,9 @@ class Canvas(QtWidgets.QWidget):
def
selectedVertex
(
self
):
return
self
.
hVertex
is
not
None
def
addedVertex
(
self
):
return
self
.
addVertex
is
not
None
def
mouseMoveEvent
(
self
,
ev
):
"""Update line with last point and current coordinates."""
if
QT5
:
...
...
@@ -183,6 +187,7 @@ class Canvas(QtWidgets.QWidget):
# Look for a nearby vertex to highlight. If that fails,
# check if we happen to be inside a shape.
index
=
shape
.
nearestVertex
(
pos
,
self
.
epsilon
)
index2
=
shape
.
nearestEdge
(
pos
,
self
.
epsilon
)
if
index
is
not
None
:
if
self
.
selectedVertex
():
self
.
hShape
.
highlightClear
()
...
...
@@ -193,10 +198,20 @@ class Canvas(QtWidgets.QWidget):
self
.
setStatusTip
(
self
.
toolTip
())
self
.
update
()
break
elif
index2
is
not
None
:
if
self
.
selectedVertex
():
self
.
hShape
.
highlightClear
()
self
.
addVertex
,
self
.
hShape
=
index2
,
shape
self
.
hVertex
=
None
self
.
overrideCursor
(
CURSOR_DRAW
)
self
.
setToolTip
(
"Click & drag to add point"
)
self
.
setStatusTip
(
self
.
toolTip
())
self
.
update
()
break
elif
shape
.
containsPoint
(
pos
):
if
self
.
selectedVertex
():
self
.
hShape
.
highlightClear
()
self
.
hVertex
,
self
.
hShape
=
None
,
shape
self
.
hVertex
,
self
.
addVertex
,
self
.
hShape
=
None
,
None
,
shape
self
.
setToolTip
(
"Click & drag to move shape '%s'"
%
shape
.
label
)
self
.
setStatusTip
(
self
.
toolTip
())
...
...
@@ -305,6 +320,13 @@ class Canvas(QtWidgets.QWidget):
index
,
shape
=
self
.
hVertex
,
self
.
hShape
shape
.
highlightVertex
(
index
,
shape
.
MOVE_VERTEX
)
return
if
self
.
addedVertex
()
and
self
.
hShape
is
not
None
:
index2
,
shape
=
self
.
addVertex
,
self
.
hShape
shape
.
insertPoint
(
index2
,
point
)
shape
.
highlightVertex
(
index2
,
shape
.
MOVE_VERTEX
)
self
.
addVertex
=
None
self
.
hVertex
=
index2
return
for
shape
in
reversed
(
self
.
shapes
):
if
self
.
isVisible
(
shape
)
and
shape
.
containsPoint
(
point
):
shape
.
selected
=
True
...
...
labelme/lib.py
浏览文件 @
c978e80f
from
math
import
sqrt
import
os.path
as
osp
from
numpy.linalg
import
norm
import
numpy
as
np
from
qtpy
import
QtCore
from
qtpy
import
QtGui
...
...
@@ -68,6 +70,18 @@ def distance(p):
return
sqrt
(
p
.
x
()
*
p
.
x
()
+
p
.
y
()
*
p
.
y
())
def
distancetoline
(
point
,
line
):
p1
,
p2
=
line
p1
=
np
.
array
([
p1
.
x
(),
p1
.
y
()])
p2
=
np
.
array
([
p2
.
x
(),
p2
.
y
()])
p3
=
np
.
array
([
point
.
x
(),
point
.
y
()])
if
np
.
dot
((
p3
-
p1
),
(
p2
-
p1
))
<
0
:
return
norm
(
p3
-
p1
)
if
np
.
dot
((
p3
-
p2
),
(
p1
-
p2
))
<
0
:
return
norm
(
p3
-
p2
)
return
norm
(
np
.
cross
(
p2
-
p1
,
p1
-
p3
))
/
norm
(
p2
-
p1
)
def
fmtShortcut
(
text
):
mod
,
key
=
text
.
split
(
'+'
,
1
)
return
'<b>%s</b>+<b>%s</b>'
%
(
mod
,
key
)
labelme/shape.py
浏览文件 @
c978e80f
from
qtpy
import
QtGui
from
labelme.lib
import
distance
from
labelme.lib
import
distancetoline
from
labelme
import
logger
...
...
@@ -71,6 +72,9 @@ class Shape(object):
return
self
.
points
.
pop
()
return
None
def
insertPoint
(
self
,
i
,
point
):
self
.
points
.
insert
(
i
,
point
)
def
isClosed
(
self
):
return
self
.
_closed
...
...
@@ -137,6 +141,17 @@ class Shape(object):
min_i
=
i
return
min_i
def
nearestEdge
(
self
,
point
,
epsilon
):
min_distance
=
float
(
'inf'
)
post_i
=
None
for
i
in
range
(
len
(
self
.
points
)):
line
=
[
self
.
points
[
i
-
1
],
self
.
points
[
i
]]
dist
=
distancetoline
(
point
,
line
)
if
dist
<=
epsilon
and
dist
<
min_distance
:
min_distance
=
dist
post_i
=
i
return
post_i
def
containsPoint
(
self
,
point
):
return
self
.
makePath
().
contains
(
point
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录