Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
ae5dd1d7
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
ae5dd1d7
编写于
7月 16, 2011
作者:
A
Alexander Mordvintsev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
math.pi -> np.pi
squares.py sample added
上级
570041fe
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
45 addition
and
11 deletion
+45
-11
samples/python2/gaussian_mix.py
samples/python2/gaussian_mix.py
+1
-2
samples/python2/lk_track.py
samples/python2/lk_track.py
+2
-5
samples/python2/opt_flow.py
samples/python2/opt_flow.py
+2
-3
samples/python2/squares.py
samples/python2/squares.py
+39
-0
samples/python2/watershed.py
samples/python2/watershed.py
+1
-1
未找到文件。
samples/python2/gaussian_mix.py
浏览文件 @
ae5dd1d7
import
numpy
as
np
import
numpy
as
np
import
math
from
numpy
import
random
from
numpy
import
random
import
cv2
import
cv2
...
@@ -20,7 +19,7 @@ def make_gaussians(cluster_n, img_size):
...
@@ -20,7 +19,7 @@ def make_gaussians(cluster_n, img_size):
def
draw_gaussain
(
img
,
mean
,
cov
,
color
):
def
draw_gaussain
(
img
,
mean
,
cov
,
color
):
x
,
y
=
np
.
int32
(
mean
)
x
,
y
=
np
.
int32
(
mean
)
w
,
u
,
vt
=
cv2
.
SVDecomp
(
cov
)
w
,
u
,
vt
=
cv2
.
SVDecomp
(
cov
)
ang
=
np
.
arctan2
(
u
[
1
,
0
],
u
[
0
,
0
])
*
(
180
/
math
.
pi
)
ang
=
np
.
arctan2
(
u
[
1
,
0
],
u
[
0
,
0
])
*
(
180
/
np
.
pi
)
s1
,
s2
=
np
.
sqrt
(
w
)
*
3.0
s1
,
s2
=
np
.
sqrt
(
w
)
*
3.0
cv2
.
ellipse
(
img
,
(
x
,
y
),
(
s1
,
s2
),
ang
,
0
,
360
,
color
,
1
,
cv2
.
CV_AA
)
cv2
.
ellipse
(
img
,
(
x
,
y
),
(
s1
,
s2
),
ang
,
0
,
360
,
color
,
1
,
cv2
.
CV_AA
)
...
...
samples/python2/lk_track.py
浏览文件 @
ae5dd1d7
...
@@ -13,9 +13,6 @@ Keys:
...
@@ -13,9 +13,6 @@ Keys:
SPACE - reset features
SPACE - reset features
'''
'''
lk_params
=
dict
(
winSize
=
(
21
,
21
),
lk_params
=
dict
(
winSize
=
(
21
,
21
),
maxLevel
=
2
,
maxLevel
=
2
,
criteria
=
(
cv2
.
TERM_CRITERIA_EPS
|
cv2
.
TERM_CRITERIA_COUNT
,
10
,
0.03
),
criteria
=
(
cv2
.
TERM_CRITERIA_EPS
|
cv2
.
TERM_CRITERIA_COUNT
,
10
,
0.03
),
...
@@ -35,7 +32,7 @@ def calc_flow_old(img0, img1, p0):
...
@@ -35,7 +32,7 @@ def calc_flow_old(img0, img1, p0):
np
.
asarray
(
img1_cv
)[:]
=
img1
np
.
asarray
(
img1_cv
)[:]
=
img1
t
=
clock
()
t
=
clock
()
features
,
status
,
error
=
cv
.
CalcOpticalFlowPyrLK
(
img0_cv
,
img1_cv
,
None
,
None
,
p0
,
features
,
status
,
error
=
cv
.
CalcOpticalFlowPyrLK
(
img0_cv
,
img1_cv
,
None
,
None
,
p0
,
lk_params
[
'winSize'
],
lk_params
[
'maxLevel'
],
(
cv
.
CV_TERMCRIT_EPS
|
cv
.
CV_TERMCRIT_ITER
,
10
,
0.03
)
,
0
,
p0
)
lk_params
[
'winSize'
],
lk_params
[
'maxLevel'
],
lk_params
[
'criteria'
]
,
0
,
p0
)
return
np
.
float32
(
features
),
status
,
error
,
clock
()
-
t
return
np
.
float32
(
features
),
status
,
error
,
clock
()
-
t
def
main
():
def
main
():
...
@@ -60,7 +57,7 @@ def main():
...
@@ -60,7 +57,7 @@ def main():
p1
,
st
,
err
,
dt
=
calc_flow_old
(
img0
,
img1
,
p0
)
p1
,
st
,
err
,
dt
=
calc_flow_old
(
img0
,
img1
,
p0
)
else
:
else
:
t
=
clock
()
t
=
clock
()
p1
,
st
,
err
=
cv2
.
calcOpticalFlowPyrLK
(
img0
,
img1
,
p0
,
**
lk_params
)
p1
,
st
,
err
=
cv2
.
calcOpticalFlowPyrLK
(
img0
,
img1
,
p0
,
None
,
**
lk_params
)
dt
=
clock
()
-
t
dt
=
clock
()
-
t
for
tr
,
(
x
,
y
)
in
zip
(
tracks
,
p1
.
reshape
(
-
1
,
2
)):
for
tr
,
(
x
,
y
)
in
zip
(
tracks
,
p1
.
reshape
(
-
1
,
2
)):
tr
.
append
((
x
,
y
))
tr
.
append
((
x
,
y
))
...
...
samples/python2/opt_flow.py
浏览文件 @
ae5dd1d7
import
numpy
as
np
import
numpy
as
np
import
math
import
cv2
import
cv2
import
cv2.cv
as
cv
import
cv2.cv
as
cv
import
video
import
video
...
@@ -31,7 +30,7 @@ def draw_hsv(flow):
...
@@ -31,7 +30,7 @@ def draw_hsv(flow):
ang
=
np
.
arctan2
(
fy
,
fx
)
+
np
.
pi
ang
=
np
.
arctan2
(
fy
,
fx
)
+
np
.
pi
v
=
np
.
sqrt
(
fx
*
fx
+
fy
*
fy
)
v
=
np
.
sqrt
(
fx
*
fx
+
fy
*
fy
)
hsv
=
np
.
zeros
((
h
,
w
,
3
),
np
.
uint8
)
hsv
=
np
.
zeros
((
h
,
w
,
3
),
np
.
uint8
)
hsv
[...,
0
]
=
ang
*
(
180
/
math
.
pi
/
2
)
hsv
[...,
0
]
=
ang
*
(
180
/
np
.
pi
/
2
)
hsv
[...,
1
]
=
255
hsv
[...,
1
]
=
255
hsv
[...,
2
]
=
np
.
minimum
(
v
*
4
,
255
)
hsv
[...,
2
]
=
np
.
minimum
(
v
*
4
,
255
)
bgr
=
cv2
.
cvtColor
(
hsv
,
cv
.
CV_HSV2BGR
)
bgr
=
cv2
.
cvtColor
(
hsv
,
cv
.
CV_HSV2BGR
)
...
@@ -61,7 +60,7 @@ if __name__ == '__main__':
...
@@ -61,7 +60,7 @@ if __name__ == '__main__':
while
True
:
while
True
:
ret
,
img
=
cam
.
read
()
ret
,
img
=
cam
.
read
()
gray
=
cv2
.
cvtColor
(
img
,
cv
.
CV_BGR2GRAY
)
gray
=
cv2
.
cvtColor
(
img
,
cv
.
CV_BGR2GRAY
)
flow
=
cv2
.
calcOpticalFlowFarneback
(
prevgray
,
gray
,
0.5
,
3
,
15
,
3
,
5
,
1.2
,
0
)
flow
=
cv2
.
calcOpticalFlowFarneback
(
prevgray
,
gray
,
None
,
0.5
,
3
,
15
,
3
,
5
,
1.2
,
0
)
prevgray
=
gray
prevgray
=
gray
cv2
.
imshow
(
'flow'
,
draw_flow
(
gray
,
flow
))
cv2
.
imshow
(
'flow'
,
draw_flow
(
gray
,
flow
))
...
...
samples/python2/squares.py
0 → 100644
浏览文件 @
ae5dd1d7
import
numpy
as
np
import
cv2
def
angle_cos
(
p0
,
p1
,
p2
):
d1
,
d2
=
p0
-
p1
,
p2
-
p1
return
abs
(
np
.
dot
(
d1
,
d2
)
/
np
.
sqrt
(
np
.
dot
(
d1
,
d1
)
*
np
.
dot
(
d2
,
d2
)
)
)
def
find_squares
(
img
):
img
=
cv2
.
GaussianBlur
(
img
,
(
5
,
5
),
0
)
squares
=
[]
for
gray
in
cv2
.
split
(
img
):
for
thrs
in
xrange
(
0
,
255
,
26
):
if
thrs
==
0
:
bin
=
cv2
.
Canny
(
gray
,
0
,
50
,
apertureSize
=
5
)
bin
=
cv2
.
dilate
(
bin
,
None
)
else
:
retval
,
bin
=
cv2
.
threshold
(
gray
,
thrs
,
255
,
cv2
.
THRESH_BINARY
)
contours
,
hierarchy
=
cv2
.
findContours
(
bin
,
cv2
.
RETR_LIST
,
cv2
.
CHAIN_APPROX_SIMPLE
)
for
cnt
in
contours
:
cnt_len
=
cv2
.
arcLength
(
cnt
,
True
)
cnt
=
cv2
.
approxPolyDP
(
cnt
,
0.02
*
cnt_len
,
True
)
if
len
(
cnt
)
==
4
and
cv2
.
contourArea
(
cnt
)
>
1000
and
cv2
.
isContourConvex
(
cnt
):
cnt
=
cnt
.
reshape
(
-
1
,
2
)
max_cos
=
np
.
max
([
angle_cos
(
cnt
[
i
],
cnt
[(
i
+
1
)
%
4
],
cnt
[(
i
+
2
)
%
4
]
)
for
i
in
xrange
(
4
)])
if
max_cos
<
0.3
:
squares
.
append
(
cnt
)
return
squares
if
__name__
==
'__main__'
:
from
glob
import
glob
for
fn
in
glob
(
'../cpp/pic*.png'
):
img
=
cv2
.
imread
(
fn
)
squares
=
find_squares
(
img
)
cv2
.
drawContours
(
img
,
squares
,
-
1
,
(
0
,
255
,
0
),
3
)
cv2
.
imshow
(
'squares'
,
img
)
ch
=
cv2
.
waitKey
()
if
ch
==
27
:
break
\ No newline at end of file
samples/python2/watershed.py
浏览文件 @
ae5dd1d7
...
@@ -52,7 +52,7 @@ class App:
...
@@ -52,7 +52,7 @@ class App:
print
'auto_update if'
,
[
'off'
,
'on'
][
self
.
auto_update
]
print
'auto_update if'
,
[
'off'
,
'on'
][
self
.
auto_update
]
if
ch
in
[
ord
(
'r'
),
ord
(
'R'
)]:
if
ch
in
[
ord
(
'r'
),
ord
(
'R'
)]:
self
.
markers
[:]
=
0
self
.
markers
[:]
=
0
self
.
markers_vis
[:]
=
self
.
img
.
copy
()
self
.
markers_vis
[:]
=
self
.
img
self
.
sketch
.
show
()
self
.
sketch
.
show
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录