Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
84568cb1
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
84568cb1
编写于
7月 01, 2011
作者:
A
Alexander Mordvintsev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
python Sketcher utility class
上级
ee10a388
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
26 deletion
+37
-26
samples/python2/common.py
samples/python2/common.py
+27
-1
samples/python2/watershed.py
samples/python2/watershed.py
+10
-25
未找到文件。
samples/python2/common.py
浏览文件 @
84568cb1
import
numpy
as
np
import
cv2
import
cv2
,
cv
import
os
image_extensions
=
[
'.bmp'
,
'.jpg'
,
'.jpeg'
,
'.png'
,
'.tif'
,
'.tiff'
,
'.pbm'
,
'.pgm'
,
'.ppm'
]
...
...
@@ -57,3 +57,29 @@ def mtx2rvec(R):
def
draw_str
(
dst
,
(
x
,
y
),
s
):
cv2
.
putText
(
dst
,
s
,
(
x
+
1
,
y
+
1
),
cv2
.
FONT_HERSHEY_PLAIN
,
1.0
,
(
0
,
0
,
0
),
thickness
=
2
,
linetype
=
cv2
.
CV_AA
)
cv2
.
putText
(
dst
,
s
,
(
x
,
y
),
cv2
.
FONT_HERSHEY_PLAIN
,
1.0
,
(
255
,
255
,
255
),
linetype
=
cv2
.
CV_AA
)
class
Sketcher
:
def
__init__
(
self
,
windowname
,
dests
,
colors_func
):
self
.
prev_pt
=
None
self
.
windowname
=
windowname
self
.
dests
=
dests
self
.
colors_func
=
colors_func
self
.
dirty
=
False
self
.
show
()
cv2
.
setMouseCallback
(
self
.
windowname
,
self
.
on_mouse
)
def
show
(
self
):
cv2
.
imshow
(
self
.
windowname
,
self
.
dests
[
0
])
def
on_mouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
pt
=
(
x
,
y
)
if
event
==
cv
.
CV_EVENT_LBUTTONDOWN
:
self
.
prev_pt
=
pt
if
self
.
prev_pt
and
flags
&
cv
.
CV_EVENT_FLAG_LBUTTON
:
for
dst
,
color
in
zip
(
self
.
dests
,
self
.
colors_func
()):
cv
.
Line
(
dst
,
self
.
prev_pt
,
pt
,
color
,
5
)
self
.
dirty
=
True
self
.
prev_pt
=
pt
self
.
show
()
else
:
self
.
prev_pt
=
None
samples/python2/watershed.py
浏览文件 @
84568cb1
import
numpy
as
np
import
cv2
,
cv
from
common
import
Sketcher
help_message
=
'''
USAGE: watershed.py [<image>]
...
...
@@ -21,34 +22,17 @@ class App:
self
.
cur_marker
=
1
self
.
colors
=
np
.
int32
(
list
(
np
.
ndindex
(
2
,
2
,
2
))
)
*
255
cv2
.
imshow
(
'img'
,
self
.
markers_vis
)
self
.
prev_pt
=
None
self
.
need_update
=
False
self
.
auto_update
=
True
cv2
.
setMouseCallback
(
'img'
,
self
.
onmouse
)
def
onmouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
pt
=
(
x
,
y
)
if
event
==
cv
.
CV_EVENT_LBUTTONDOWN
:
self
.
prev_pt
=
pt
if
self
.
prev_pt
and
flags
&
cv
.
CV_EVENT_FLAG_LBUTTON
:
color
=
map
(
int
,
self
.
colors
[
self
.
cur_marker
])
cv
.
Line
(
self
.
markers
,
self
.
prev_pt
,
pt
,
self
.
cur_marker
,
5
)
cv
.
Line
(
self
.
markers_vis
,
self
.
prev_pt
,
pt
,
color
,
5
)
self
.
need_update
=
True
self
.
prev_pt
=
pt
cv2
.
imshow
(
'img'
,
self
.
markers_vis
)
else
:
self
.
prev_pt
=
None
self
.
sketch
=
Sketcher
(
'img'
,
[
self
.
markers_vis
,
self
.
markers
],
self
.
get_colors
)
def
get_colors
(
self
):
return
map
(
int
,
self
.
colors
[
self
.
cur_marker
]),
self
.
cur_marker
def
watershed
(
self
):
m
=
self
.
markers
.
copy
()
cv2
.
watershed
(
self
.
img
,
m
)
vis
=
np
.
uint8
(
(
self
.
img
+
self
.
colors
[
np
.
maximum
(
m
,
0
)])
/
2
)
cv2
.
imshow
(
'watershed'
,
vis
)
self
.
need_update
=
False
def
run
(
self
):
while
True
:
...
...
@@ -58,15 +42,16 @@ class App:
if
ch
>=
ord
(
'1'
)
and
ch
<=
ord
(
'7'
):
self
.
cur_marker
=
ch
-
ord
(
'0'
)
print
'marker: '
,
self
.
cur_marker
if
ch
==
ord
(
' '
)
or
(
self
.
need_update
and
self
.
auto_update
):
if
ch
==
ord
(
' '
)
or
(
self
.
sketch
.
dirty
and
self
.
auto_update
):
self
.
watershed
()
self
.
sketch
.
dirty
=
False
if
ch
in
[
ord
(
'a'
),
ord
(
'A'
)]:
self
.
auto_update
=
not
self
.
auto_update
print
'auto_update if'
,
[
'off'
,
'on'
][
self
.
auto_update
]
if
ch
in
[
ord
(
'r'
),
ord
(
'R'
)]:
self
.
markers
=
np
.
zeros
(
self
.
img
.
shape
[:
2
],
np
.
int32
)
self
.
markers_vis
=
self
.
img
.
copy
()
cv2
.
imshow
(
'img'
,
self
.
markers_vis
)
self
.
markers
[:]
=
0
self
.
markers_vis
[:]
=
self
.
img
self
.
sketch
.
show
(
)
cv2
.
destroyWindow
(
'watershed'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录