Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不会修仙的道士
labelme
提交
9a980af0
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,发现更多精彩内容 >>
提交
9a980af0
编写于
4月 23, 2018
作者:
K
Kentaro Wada
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Validate label with types 'none', 'exact', 'instance'
上级
8f2be66c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
4 deletion
+39
-4
labelme/app.py
labelme/app.py
+39
-4
未找到文件。
labelme/app.py
浏览文件 @
9a980af0
import
argparse
import
functools
import
os.path
import
re
import
sys
import
warnings
import
webbrowser
...
...
@@ -126,7 +127,8 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
FIT_WINDOW
,
FIT_WIDTH
,
MANUAL_ZOOM
=
0
,
1
,
2
def
__init__
(
self
,
filename
=
None
,
output
=
None
,
store_data
=
True
,
labels
=
None
,
sort_labels
=
True
,
auto_save
=
False
):
labels
=
None
,
sort_labels
=
True
,
auto_save
=
False
,
validate_label
=
None
):
super
(
MainWindow
,
self
).
__init__
()
self
.
setWindowTitle
(
__appname__
)
...
...
@@ -407,6 +409,10 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
self
.
output
=
output
self
.
_auto_save
=
auto_save
self
.
_store_data
=
store_data
if
validate_label
not
in
[
None
,
'exact'
,
'instance'
]:
raise
ValueError
(
'Unexpected `validate_label`: {}'
.
format
(
validate_label
))
self
.
_validate_label
=
validate_label
self
.
recentFiles
=
[]
self
.
maxRecent
=
7
self
.
lineColor
=
None
...
...
@@ -600,11 +606,32 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
def
popLabelListMenu
(
self
,
point
):
self
.
menus
.
labelList
.
exec_
(
self
.
labelList
.
mapToGlobal
(
point
))
def
validateLabel
(
self
,
label
):
# no validation
if
self
.
_validate_label
is
None
:
return
True
for
i
in
range
(
self
.
uniqLabelList
.
count
()):
l
=
self
.
uniqLabelList
.
item
(
i
).
text
()
if
self
.
_validate_label
in
[
'exact'
,
'instance'
]:
if
l
==
label
:
return
True
if
self
.
_validate_label
==
'instance'
:
m
=
re
.
match
(
r
'^{}-[0-9]*$'
.
format
(
l
),
label
)
if
m
:
return
True
return
False
def
editLabel
(
self
,
item
=
None
):
if
not
self
.
canvas
.
editing
():
return
item
=
item
if
item
else
self
.
currentItem
()
text
=
self
.
labelDialog
.
popUp
(
item
.
text
())
if
not
self
.
validateLabel
(
text
):
self
.
errorMessage
(
'Invalid label'
,
"Invalid label '{}' with validation type '{}'"
.
format
(
text
,
self
.
_validate_label
))
text
=
None
if
text
is
None
:
return
item
.
setText
(
text
)
...
...
@@ -736,12 +763,17 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
if
items
:
text
=
items
[
0
].
text
()
text
=
self
.
labelDialog
.
popUp
(
text
)
if
text
is
not
None
:
if
not
self
.
validateLabel
(
text
):
self
.
errorMessage
(
'Invalid label'
,
"Invalid label '{}' with validation type '{}'"
.
format
(
text
,
self
.
_validate_label
))
text
=
None
if
text
is
None
:
self
.
canvas
.
undoLastLine
()
else
:
self
.
addLabel
(
self
.
canvas
.
setLastLabel
(
text
))
self
.
actions
.
editMode
.
setEnabled
(
True
)
self
.
setDirty
()
else
:
self
.
canvas
.
undoLastLine
()
def
scrollRequest
(
self
,
delta
,
orientation
):
units
=
-
delta
*
0.1
# natural scroll
...
...
@@ -1186,6 +1218,8 @@ def main():
'containing one label per line'
)
parser
.
add_argument
(
'--nosortlabels'
,
dest
=
'sort_labels'
,
action
=
'store_false'
,
help
=
'stop sorting labels'
)
parser
.
add_argument
(
'--validatelabel'
,
choices
=
[
'exact'
,
'instance'
],
help
=
'label validation types'
)
args
=
parser
.
parse_args
()
if
args
.
labels
is
not
None
:
...
...
@@ -1205,6 +1239,7 @@ def main():
labels
=
args
.
labels
,
sort_labels
=
args
.
sort_labels
,
auto_save
=
args
.
autosave
,
validate_label
=
args
.
validatelabel
,
)
win
.
show
()
win
.
raise_
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录