Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
16ba62dc
Commit
16ba62dc
authored
Jul 18, 2011
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added COLOR_... enumeration to imgproc.hpp and EVENT_... enumeration to highgui.hpp
parent
86105b87
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
187 additions
and
35 deletions
+187
-35
highgui.hpp
modules/highgui/include/opencv2/highgui/highgui.hpp
+24
-0
imgproc.hpp
modules/imgproc/include/opencv2/imgproc/imgproc.hpp
+142
-0
calibrate.py
samples/python2/calibrate.py
+1
-2
coherence.py
samples/python2/coherence.py
+1
-3
color_histogram.py
samples/python2/color_histogram.py
+2
-3
common.py
samples/python2/common.py
+2
-3
distrans.py
samples/python2/distrans.py
+0
-1
edge.py
samples/python2/edge.py
+1
-2
find_obj.py
samples/python2/find_obj.py
+1
-2
floodfill.py
samples/python2/floodfill.py
+1
-2
lk_track.py
samples/python2/lk_track.py
+3
-3
motempl.py
samples/python2/motempl.py
+3
-4
obj_detect.py
samples/python2/obj_detect.py
+1
-2
opt_flow.py
samples/python2/opt_flow.py
+4
-5
stereo_match.py
samples/python2/stereo_match.py
+1
-2
watershed.py
samples/python2/watershed.py
+0
-1
No files found.
modules/highgui/include/opencv2/highgui/highgui.hpp
View file @
16ba62dc
...
@@ -101,6 +101,30 @@ CV_EXPORTS int createTrackbar( const string& trackbarname, const string& winname
...
@@ -101,6 +101,30 @@ CV_EXPORTS int createTrackbar( const string& trackbarname, const string& winname
CV_EXPORTS_W
int
getTrackbarPos
(
const
string
&
trackbarname
,
const
string
&
winname
);
CV_EXPORTS_W
int
getTrackbarPos
(
const
string
&
trackbarname
,
const
string
&
winname
);
CV_EXPORTS_W
void
setTrackbarPos
(
const
string
&
trackbarname
,
const
string
&
winname
,
int
pos
);
CV_EXPORTS_W
void
setTrackbarPos
(
const
string
&
trackbarname
,
const
string
&
winname
,
int
pos
);
enum
{
EVENT_MOUSEMOVE
=
0
,
EVENT_LBUTTONDOWN
=
1
,
EVENT_RBUTTONDOWN
=
2
,
EVENT_MBUTTONDOWN
=
3
,
EVENT_LBUTTONUP
=
4
,
EVENT_RBUTTONUP
=
5
,
EVENT_MBUTTONUP
=
6
,
EVENT_LBUTTONDBLCLK
=
7
,
EVENT_RBUTTONDBLCLK
=
8
,
EVENT_MBUTTONDBLCLK
=
9
};
enum
{
EVENT_FLAG_LBUTTON
=
1
,
EVENT_FLAG_RBUTTON
=
2
,
EVENT_FLAG_MBUTTON
=
4
,
EVENT_FLAG_CTRLKEY
=
8
,
EVENT_FLAG_SHIFTKEY
=
16
,
EVENT_FLAG_ALTKEY
=
32
};
typedef
void
(
*
MouseCallback
)(
int
event
,
int
x
,
int
y
,
int
flags
,
void
*
param
);
typedef
void
(
*
MouseCallback
)(
int
event
,
int
x
,
int
y
,
int
flags
,
void
*
param
);
//! assigns callback for mouse events
//! assigns callback for mouse events
...
...
modules/imgproc/include/opencv2/imgproc/imgproc.hpp
View file @
16ba62dc
...
@@ -750,6 +750,148 @@ CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,
...
@@ -750,6 +750,148 @@ CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,
Scalar
loDiff
=
Scalar
(),
Scalar
upDiff
=
Scalar
(),
Scalar
loDiff
=
Scalar
(),
Scalar
upDiff
=
Scalar
(),
int
flags
=
4
);
int
flags
=
4
);
enum
{
COLOR_BGR2BGRA
=
0
,
COLOR_RGB2RGBA
=
COLOR_BGR2BGRA
,
COLOR_BGRA2BGR
=
1
,
COLOR_RGBA2RGB
=
COLOR_BGRA2BGR
,
COLOR_BGR2RGBA
=
2
,
COLOR_RGB2BGRA
=
COLOR_BGR2RGBA
,
COLOR_RGBA2BGR
=
3
,
COLOR_BGRA2RGB
=
COLOR_RGBA2BGR
,
COLOR_BGR2RGB
=
4
,
COLOR_RGB2BGR
=
COLOR_BGR2RGB
,
COLOR_BGRA2RGBA
=
5
,
COLOR_RGBA2BGRA
=
COLOR_BGRA2RGBA
,
COLOR_BGR2GRAY
=
6
,
COLOR_RGB2GRAY
=
7
,
COLOR_GRAY2BGR
=
8
,
COLOR_GRAY2RGB
=
COLOR_GRAY2BGR
,
COLOR_GRAY2BGRA
=
9
,
COLOR_GRAY2RGBA
=
COLOR_GRAY2BGRA
,
COLOR_BGRA2GRAY
=
10
,
COLOR_RGBA2GRAY
=
11
,
COLOR_BGR2BGR565
=
12
,
COLOR_RGB2BGR565
=
13
,
COLOR_BGR5652BGR
=
14
,
COLOR_BGR5652RGB
=
15
,
COLOR_BGRA2BGR565
=
16
,
COLOR_RGBA2BGR565
=
17
,
COLOR_BGR5652BGRA
=
18
,
COLOR_BGR5652RGBA
=
19
,
COLOR_GRAY2BGR565
=
20
,
COLOR_BGR5652GRAY
=
21
,
COLOR_BGR2BGR555
=
22
,
COLOR_RGB2BGR555
=
23
,
COLOR_BGR5552BGR
=
24
,
COLOR_BGR5552RGB
=
25
,
COLOR_BGRA2BGR555
=
26
,
COLOR_RGBA2BGR555
=
27
,
COLOR_BGR5552BGRA
=
28
,
COLOR_BGR5552RGBA
=
29
,
COLOR_GRAY2BGR555
=
30
,
COLOR_BGR5552GRAY
=
31
,
COLOR_BGR2XYZ
=
32
,
COLOR_RGB2XYZ
=
33
,
COLOR_XYZ2BGR
=
34
,
COLOR_XYZ2RGB
=
35
,
COLOR_BGR2YCrCb
=
36
,
COLOR_RGB2YCrCb
=
37
,
COLOR_YCrCb2BGR
=
38
,
COLOR_YCrCb2RGB
=
39
,
COLOR_BGR2HSV
=
40
,
COLOR_RGB2HSV
=
41
,
COLOR_BGR2Lab
=
44
,
COLOR_RGB2Lab
=
45
,
COLOR_BayerBG2BGR
=
46
,
COLOR_BayerGB2BGR
=
47
,
COLOR_BayerRG2BGR
=
48
,
COLOR_BayerGR2BGR
=
49
,
COLOR_BayerBG2RGB
=
COLOR_BayerRG2BGR
,
COLOR_BayerGB2RGB
=
COLOR_BayerGR2BGR
,
COLOR_BayerRG2RGB
=
COLOR_BayerBG2BGR
,
COLOR_BayerGR2RGB
=
COLOR_BayerGB2BGR
,
COLOR_BGR2Luv
=
50
,
COLOR_RGB2Luv
=
51
,
COLOR_BGR2HLS
=
52
,
COLOR_RGB2HLS
=
53
,
COLOR_HSV2BGR
=
54
,
COLOR_HSV2RGB
=
55
,
COLOR_Lab2BGR
=
56
,
COLOR_Lab2RGB
=
57
,
COLOR_Luv2BGR
=
58
,
COLOR_Luv2RGB
=
59
,
COLOR_HLS2BGR
=
60
,
COLOR_HLS2RGB
=
61
,
COLOR_BayerBG2BGR_VNG
=
62
,
COLOR_BayerGB2BGR_VNG
=
63
,
COLOR_BayerRG2BGR_VNG
=
64
,
COLOR_BayerGR2BGR_VNG
=
65
,
COLOR_BayerBG2RGB_VNG
=
COLOR_BayerRG2BGR_VNG
,
COLOR_BayerGB2RGB_VNG
=
COLOR_BayerGR2BGR_VNG
,
COLOR_BayerRG2RGB_VNG
=
COLOR_BayerBG2BGR_VNG
,
COLOR_BayerGR2RGB_VNG
=
COLOR_BayerGB2BGR_VNG
,
COLOR_BGR2HSV_FULL
=
66
,
COLOR_RGB2HSV_FULL
=
67
,
COLOR_BGR2HLS_FULL
=
68
,
COLOR_RGB2HLS_FULL
=
69
,
COLOR_HSV2BGR_FULL
=
70
,
COLOR_HSV2RGB_FULL
=
71
,
COLOR_HLS2BGR_FULL
=
72
,
COLOR_HLS2RGB_FULL
=
73
,
COLOR_LBGR2Lab
=
74
,
COLOR_LRGB2Lab
=
75
,
COLOR_LBGR2Luv
=
76
,
COLOR_LRGB2Luv
=
77
,
COLOR_Lab2LBGR
=
78
,
COLOR_Lab2LRGB
=
79
,
COLOR_Luv2LBGR
=
80
,
COLOR_Luv2LRGB
=
81
,
COLOR_BGR2YUV
=
82
,
COLOR_RGB2YUV
=
83
,
COLOR_YUV2BGR
=
84
,
COLOR_YUV2RGB
=
85
,
COLOR_BayerBG2GRAY
=
86
,
COLOR_BayerGB2GRAY
=
87
,
COLOR_BayerRG2GRAY
=
88
,
COLOR_BayerGR2GRAY
=
89
,
COLOR_YUV420i2RGB
=
90
,
COLOR_YUV420i2BGR
=
91
,
COLOR_COLORCVT_MAX
=
100
};
//! converts image from one color space to another
//! converts image from one color space to another
CV_EXPORTS_W
void
cvtColor
(
InputArray
src
,
OutputArray
dst
,
int
code
,
int
dstCn
=
0
);
CV_EXPORTS_W
void
cvtColor
(
InputArray
src
,
OutputArray
dst
,
int
code
,
int
dstCn
=
0
);
...
...
samples/python2/calibrate.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
import
os
import
os
from
common
import
splitfn
from
common
import
splitfn
...
@@ -39,7 +38,7 @@ if __name__ == '__main__':
...
@@ -39,7 +38,7 @@ if __name__ == '__main__':
term
=
(
cv2
.
TERM_CRITERIA_EPS
+
cv2
.
TERM_CRITERIA_COUNT
,
30
,
0.1
)
term
=
(
cv2
.
TERM_CRITERIA_EPS
+
cv2
.
TERM_CRITERIA_COUNT
,
30
,
0.1
)
cv2
.
cornerSubPix
(
img
,
corners
,
(
5
,
5
),
(
-
1
,
-
1
),
term
)
cv2
.
cornerSubPix
(
img
,
corners
,
(
5
,
5
),
(
-
1
,
-
1
),
term
)
if
debug_dir
:
if
debug_dir
:
vis
=
cv2
.
cvtColor
(
img
,
cv
.
CV
_GRAY2BGR
)
vis
=
cv2
.
cvtColor
(
img
,
cv
2
.
COLOR
_GRAY2BGR
)
cv2
.
drawChessboardCorners
(
vis
,
pattern_size
,
corners
,
found
)
cv2
.
drawChessboardCorners
(
vis
,
pattern_size
,
corners
,
found
)
path
,
name
,
ext
=
splitfn
(
fn
)
path
,
name
,
ext
=
splitfn
(
fn
)
cv2
.
imwrite
(
'
%
s/
%
s_chess.bmp'
%
(
debug_dir
,
name
),
vis
)
cv2
.
imwrite
(
'
%
s/
%
s_chess.bmp'
%
(
debug_dir
,
name
),
vis
)
...
...
samples/python2/coherence.py
View file @
16ba62dc
...
@@ -8,8 +8,6 @@
...
@@ -8,8 +8,6 @@
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
def
coherence_filter
(
img
,
sigma
=
11
,
str_sigma
=
11
,
blend
=
0.5
,
iter_n
=
4
):
def
coherence_filter
(
img
,
sigma
=
11
,
str_sigma
=
11
,
blend
=
0.5
,
iter_n
=
4
):
h
,
w
=
img
.
shape
[:
2
]
h
,
w
=
img
.
shape
[:
2
]
...
@@ -17,7 +15,7 @@ def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
...
@@ -17,7 +15,7 @@ def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
for
i
in
xrange
(
iter_n
):
for
i
in
xrange
(
iter_n
):
print
i
,
print
i
,
gray
=
cv2
.
cvtColor
(
img
,
cv
.
CV
_BGR2GRAY
)
gray
=
cv2
.
cvtColor
(
img
,
cv
2
.
COLOR
_BGR2GRAY
)
eigen
=
cv2
.
cornerEigenValsAndVecs
(
gray
,
str_sigma
,
3
)
eigen
=
cv2
.
cornerEigenValsAndVecs
(
gray
,
str_sigma
,
3
)
eigen
=
eigen
.
reshape
(
h
,
w
,
3
,
2
)
# [[e1, e2], v1, v2]
eigen
=
eigen
.
reshape
(
h
,
w
,
3
,
2
)
# [[e1, e2], v1, v2]
x
,
y
=
eigen
[:,:,
1
,
0
],
eigen
[:,:,
1
,
1
]
x
,
y
=
eigen
[:,:,
1
,
0
],
eigen
[:,:,
1
,
1
]
...
...
samples/python2/color_histogram.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
from
time
import
clock
from
time
import
clock
import
sys
import
sys
...
@@ -11,7 +10,7 @@ h, s = np.indices(hsv_map.shape[:2])
...
@@ -11,7 +10,7 @@ h, s = np.indices(hsv_map.shape[:2])
hsv_map
[:,:,
0
]
=
h
hsv_map
[:,:,
0
]
=
h
hsv_map
[:,:,
1
]
=
s
hsv_map
[:,:,
1
]
=
s
hsv_map
[:,:,
2
]
=
255
hsv_map
[:,:,
2
]
=
255
hsv_map
=
cv2
.
cvtColor
(
hsv_map
,
cv
.
CV
_HSV2BGR
)
hsv_map
=
cv2
.
cvtColor
(
hsv_map
,
cv
2
.
COLOR
_HSV2BGR
)
cv2
.
imshow
(
'hsv_map'
,
hsv_map
)
cv2
.
imshow
(
'hsv_map'
,
hsv_map
)
cv2
.
namedWindow
(
'hist'
,
0
)
cv2
.
namedWindow
(
'hist'
,
0
)
...
@@ -32,7 +31,7 @@ while True:
...
@@ -32,7 +31,7 @@ while True:
small
=
cv2
.
pyrDown
(
frame
)
small
=
cv2
.
pyrDown
(
frame
)
hsv
=
cv2
.
cvtColor
(
small
,
cv
.
CV
_BGR2HSV
)
hsv
=
cv2
.
cvtColor
(
small
,
cv
2
.
COLOR
_BGR2HSV
)
dark
=
hsv
[
...
,
2
]
<
32
dark
=
hsv
[
...
,
2
]
<
32
hsv
[
dark
]
=
0
hsv
[
dark
]
=
0
h
=
cv2
.
calcHist
(
[
hsv
],
[
0
,
1
],
None
,
[
180
,
256
],
[
0
,
180
,
0
,
256
]
)
h
=
cv2
.
calcHist
(
[
hsv
],
[
0
,
1
],
None
,
[
180
,
256
],
[
0
,
180
,
0
,
256
]
)
...
...
samples/python2/common.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
import
os
import
os
image_extensions
=
[
'.bmp'
,
'.jpg'
,
'.jpeg'
,
'.png'
,
'.tif'
,
'.tiff'
,
'.pbm'
,
'.pgm'
,
'.ppm'
]
image_extensions
=
[
'.bmp'
,
'.jpg'
,
'.jpeg'
,
'.png'
,
'.tif'
,
'.tiff'
,
'.pbm'
,
'.pgm'
,
'.ppm'
]
...
@@ -74,9 +73,9 @@ class Sketcher:
...
@@ -74,9 +73,9 @@ class Sketcher:
def
on_mouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
def
on_mouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
pt
=
(
x
,
y
)
pt
=
(
x
,
y
)
if
event
==
cv
.
CV_
EVENT_LBUTTONDOWN
:
if
event
==
cv
2
.
EVENT_LBUTTONDOWN
:
self
.
prev_pt
=
pt
self
.
prev_pt
=
pt
if
self
.
prev_pt
and
flags
&
cv
.
CV_
EVENT_FLAG_LBUTTON
:
if
self
.
prev_pt
and
flags
&
cv
2
.
EVENT_FLAG_LBUTTON
:
for
dst
,
color
in
zip
(
self
.
dests
,
self
.
colors_func
()):
for
dst
,
color
in
zip
(
self
.
dests
,
self
.
colors_func
()):
cv2
.
line
(
dst
,
self
.
prev_pt
,
pt
,
color
,
5
)
cv2
.
line
(
dst
,
self
.
prev_pt
,
pt
,
color
,
5
)
self
.
dirty
=
True
self
.
dirty
=
True
...
...
samples/python2/distrans.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
from
common
import
make_cmap
from
common
import
make_cmap
help_message
=
'''USAGE: distrans.py [<image>]
help_message
=
'''USAGE: distrans.py [<image>]
...
...
samples/python2/edge.py
View file @
16ba62dc
import
cv2
import
cv2
import
cv2.cv
as
cv
import
video
import
video
import
sys
import
sys
...
@@ -16,7 +15,7 @@ cv2.createTrackbar('thrs2', 'edge', 4000, 5000, nothing)
...
@@ -16,7 +15,7 @@ cv2.createTrackbar('thrs2', 'edge', 4000, 5000, nothing)
cap
=
video
.
create_capture
(
fn
)
cap
=
video
.
create_capture
(
fn
)
while
True
:
while
True
:
flag
,
img
=
cap
.
read
()
flag
,
img
=
cap
.
read
()
gray
=
cv2
.
cvtColor
(
img
,
cv
.
CV
_BGR2GRAY
)
gray
=
cv2
.
cvtColor
(
img
,
cv
2
.
COLOR
_BGR2GRAY
)
thrs1
=
cv2
.
getTrackbarPos
(
'thrs1'
,
'edge'
)
thrs1
=
cv2
.
getTrackbarPos
(
'thrs1'
,
'edge'
)
thrs2
=
cv2
.
getTrackbarPos
(
'thrs2'
,
'edge'
)
thrs2
=
cv2
.
getTrackbarPos
(
'thrs2'
,
'edge'
)
edge
=
cv2
.
Canny
(
gray
,
thrs1
,
thrs2
,
apertureSize
=
5
)
edge
=
cv2
.
Canny
(
gray
,
thrs1
,
thrs2
,
apertureSize
=
5
)
...
...
samples/python2/find_obj.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
from
common
import
anorm
from
common
import
anorm
help_message
=
'''SURF image match
help_message
=
'''SURF image match
...
@@ -25,7 +24,7 @@ def draw_match(img1, img2, p1, p2, status = None, H = None):
...
@@ -25,7 +24,7 @@ def draw_match(img1, img2, p1, p2, status = None, H = None):
vis
=
np
.
zeros
((
max
(
h1
,
h2
),
w1
+
w2
),
np
.
uint8
)
vis
=
np
.
zeros
((
max
(
h1
,
h2
),
w1
+
w2
),
np
.
uint8
)
vis
[:
h1
,
:
w1
]
=
img1
vis
[:
h1
,
:
w1
]
=
img1
vis
[:
h2
,
w1
:
w1
+
w2
]
=
img2
vis
[:
h2
,
w1
:
w1
+
w2
]
=
img2
vis
=
cv2
.
cvtColor
(
vis
,
cv
.
CV
_GRAY2BGR
)
vis
=
cv2
.
cvtColor
(
vis
,
cv
2
.
COLOR
_GRAY2BGR
)
if
H
is
not
None
:
if
H
is
not
None
:
corners
=
np
.
float32
([[
0
,
0
],
[
w1
,
0
],
[
w1
,
h1
],
[
0
,
h1
]])
corners
=
np
.
float32
([[
0
,
0
],
[
w1
,
0
],
[
w1
,
h1
],
[
0
,
h1
]])
...
...
samples/python2/floodfill.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
help_message
=
'''USAGE: floodfill.py [<image>]
help_message
=
'''USAGE: floodfill.py [<image>]
...
@@ -42,7 +41,7 @@ if __name__ == '__main__':
...
@@ -42,7 +41,7 @@ if __name__ == '__main__':
def
onmouse
(
event
,
x
,
y
,
flags
,
param
):
def
onmouse
(
event
,
x
,
y
,
flags
,
param
):
global
seed_pt
global
seed_pt
if
flags
&
cv
.
CV_
EVENT_FLAG_LBUTTON
:
if
flags
&
cv
2
.
EVENT_FLAG_LBUTTON
:
seed_pt
=
x
,
y
seed_pt
=
x
,
y
update
()
update
()
...
...
samples/python2/lk_track.py
View file @
16ba62dc
...
@@ -51,8 +51,8 @@ def main():
...
@@ -51,8 +51,8 @@ def main():
vis
=
frame
.
copy
()
vis
=
frame
.
copy
()
if
len
(
tracks
)
>
0
:
if
len
(
tracks
)
>
0
:
p0
=
np
.
float32
([
tr
[
-
1
]
for
tr
in
tracks
])
.
reshape
(
-
1
,
1
,
2
)
p0
=
np
.
float32
([
tr
[
-
1
]
for
tr
in
tracks
])
.
reshape
(
-
1
,
1
,
2
)
img0
=
cv2
.
cvtColor
(
prev_frame
,
cv
.
CV
_BGR2GRAY
)
img0
=
cv2
.
cvtColor
(
prev_frame
,
cv
2
.
COLOR
_BGR2GRAY
)
img1
=
cv2
.
cvtColor
(
frame
,
cv
.
CV
_BGR2GRAY
)
img1
=
cv2
.
cvtColor
(
frame
,
cv
2
.
COLOR
_BGR2GRAY
)
if
old_mode
:
if
old_mode
:
p1
,
st
,
err
,
dt
=
calc_flow_old
(
img0
,
img1
,
p0
)
p1
,
st
,
err
,
dt
=
calc_flow_old
(
img0
,
img1
,
p0
)
else
:
else
:
...
@@ -74,7 +74,7 @@ def main():
...
@@ -74,7 +74,7 @@ def main():
if
ch
==
27
:
if
ch
==
27
:
break
break
if
ch
==
ord
(
' '
)
or
len
(
tracks
)
==
0
:
if
ch
==
ord
(
' '
)
or
len
(
tracks
)
==
0
:
gray
=
cv2
.
cvtColor
(
frame
,
cv
.
CV
_BGR2GRAY
)
gray
=
cv2
.
cvtColor
(
frame
,
cv
2
.
COLOR
_BGR2GRAY
)
p
=
cv2
.
goodFeaturesToTrack
(
gray
,
**
feature_params
)
p
=
cv2
.
goodFeaturesToTrack
(
gray
,
**
feature_params
)
p
=
[]
if
p
is
None
else
p
.
reshape
(
-
1
,
2
)
p
=
[]
if
p
is
None
else
p
.
reshape
(
-
1
,
2
)
tracks
=
[]
tracks
=
[]
...
...
samples/python2/motempl.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
import
video
import
video
from
common
import
nothing
,
clock
,
draw_str
from
common
import
nothing
,
clock
,
draw_str
...
@@ -37,7 +36,7 @@ if __name__ == '__main__':
...
@@ -37,7 +36,7 @@ if __name__ == '__main__':
while
True
:
while
True
:
ret
,
frame
=
cam
.
read
()
ret
,
frame
=
cam
.
read
()
frame_diff
=
cv2
.
absdiff
(
frame
,
prev_frame
)
frame_diff
=
cv2
.
absdiff
(
frame
,
prev_frame
)
gray_diff
=
cv2
.
cvtColor
(
frame_diff
,
cv
.
CV
_BGR2GRAY
)
gray_diff
=
cv2
.
cvtColor
(
frame_diff
,
cv
2
.
COLOR
_BGR2GRAY
)
thrs
=
cv2
.
getTrackbarPos
(
'threshold'
,
'motempl'
)
thrs
=
cv2
.
getTrackbarPos
(
'threshold'
,
'motempl'
)
ret
,
motion_mask
=
cv2
.
threshold
(
gray_diff
,
thrs
,
1
,
cv2
.
THRESH_BINARY
)
ret
,
motion_mask
=
cv2
.
threshold
(
gray_diff
,
thrs
,
1
,
cv2
.
THRESH_BINARY
)
timestamp
=
clock
()
timestamp
=
clock
()
...
@@ -52,11 +51,11 @@ if __name__ == '__main__':
...
@@ -52,11 +51,11 @@ if __name__ == '__main__':
vis
=
frame_diff
.
copy
()
vis
=
frame_diff
.
copy
()
elif
visual_name
==
'motion_hist'
:
elif
visual_name
==
'motion_hist'
:
vis
=
np
.
uint8
(
np
.
clip
((
motion_history
-
(
timestamp
-
MHI_DURATION
))
/
MHI_DURATION
,
0
,
1
)
*
255
)
vis
=
np
.
uint8
(
np
.
clip
((
motion_history
-
(
timestamp
-
MHI_DURATION
))
/
MHI_DURATION
,
0
,
1
)
*
255
)
vis
=
cv2
.
cvtColor
(
vis
,
cv
.
CV
_GRAY2BGR
)
vis
=
cv2
.
cvtColor
(
vis
,
cv
2
.
COLOR
_GRAY2BGR
)
elif
visual_name
==
'grad_orient'
:
elif
visual_name
==
'grad_orient'
:
hsv
[:,:,
0
]
=
mg_orient
/
2
hsv
[:,:,
0
]
=
mg_orient
/
2
hsv
[:,:,
2
]
=
mg_mask
*
255
hsv
[:,:,
2
]
=
mg_mask
*
255
vis
=
cv2
.
cvtColor
(
hsv
,
cv
.
CV
_HSV2BGR
)
vis
=
cv2
.
cvtColor
(
hsv
,
cv
2
.
COLOR
_HSV2BGR
)
for
i
,
rect
in
enumerate
([(
0
,
0
,
w
,
h
)]
+
list
(
seg_bounds
)):
for
i
,
rect
in
enumerate
([(
0
,
0
,
w
,
h
)]
+
list
(
seg_bounds
)):
x
,
y
,
rw
,
rh
=
rect
x
,
y
,
rw
,
rh
=
rect
...
...
samples/python2/obj_detect.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
def
detect
(
img
,
cascade
):
def
detect
(
img
,
cascade
):
rects
=
cascade
.
detectMultiScale
(
img
,
scaleFactor
=
1.1
,
minNeighbors
=
5
,
minSize
=
(
30
,
30
))
rects
=
cascade
.
detectMultiScale
(
img
,
scaleFactor
=
1.1
,
minNeighbors
=
5
,
minSize
=
(
30
,
30
))
...
@@ -10,7 +9,7 @@ def detect(img, cascade):
...
@@ -10,7 +9,7 @@ def detect(img, cascade):
return
rects
return
rects
def
detect_turned
(
img
,
cascade
):
def
detect_turned
(
img
,
cascade
):
img
=
cv2
.
cvtColor
(
img
,
cv
.
CV
_BGR2GRAY
)
img
=
cv2
.
cvtColor
(
img
,
cv
2
.
COLOR
_BGR2GRAY
)
img
=
cv2
.
equalizeHist
(
img
)
img
=
cv2
.
equalizeHist
(
img
)
img_t
=
cv2
.
transpose
(
img
)
img_t
=
cv2
.
transpose
(
img
)
...
...
samples/python2/opt_flow.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
import
video
import
video
help_message
=
'''
help_message
=
'''
...
@@ -18,7 +17,7 @@ def draw_flow(img, flow, step=16):
...
@@ -18,7 +17,7 @@ def draw_flow(img, flow, step=16):
fx
,
fy
=
flow
[
y
,
x
]
.
T
fx
,
fy
=
flow
[
y
,
x
]
.
T
lines
=
np
.
vstack
([
x
,
y
,
x
+
fx
,
y
+
fy
])
.
T
.
reshape
(
-
1
,
2
,
2
)
lines
=
np
.
vstack
([
x
,
y
,
x
+
fx
,
y
+
fy
])
.
T
.
reshape
(
-
1
,
2
,
2
)
lines
=
np
.
int32
(
lines
+
0.5
)
lines
=
np
.
int32
(
lines
+
0.5
)
vis
=
cv2
.
cvtColor
(
img
,
cv
.
CV
_GRAY2BGR
)
vis
=
cv2
.
cvtColor
(
img
,
cv
2
.
COLOR
_GRAY2BGR
)
cv2
.
polylines
(
vis
,
lines
,
0
,
(
0
,
255
,
0
))
cv2
.
polylines
(
vis
,
lines
,
0
,
(
0
,
255
,
0
))
for
(
x1
,
y1
),
(
x2
,
y2
)
in
lines
:
for
(
x1
,
y1
),
(
x2
,
y2
)
in
lines
:
cv2
.
circle
(
vis
,
(
x1
,
y1
),
1
,
(
0
,
255
,
0
),
-
1
)
cv2
.
circle
(
vis
,
(
x1
,
y1
),
1
,
(
0
,
255
,
0
),
-
1
)
...
@@ -33,7 +32,7 @@ def draw_hsv(flow):
...
@@ -33,7 +32,7 @@ def draw_hsv(flow):
hsv
[
...
,
0
]
=
ang
*
(
180
/
np
.
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
2
.
COLOR
_HSV2BGR
)
return
bgr
return
bgr
def
warp_flow
(
img
,
flow
):
def
warp_flow
(
img
,
flow
):
...
@@ -52,14 +51,14 @@ if __name__ == '__main__':
...
@@ -52,14 +51,14 @@ if __name__ == '__main__':
cam
=
video
.
create_capture
(
fn
)
cam
=
video
.
create_capture
(
fn
)
ret
,
prev
=
cam
.
read
()
ret
,
prev
=
cam
.
read
()
prevgray
=
cv2
.
cvtColor
(
prev
,
cv
.
CV
_BGR2GRAY
)
prevgray
=
cv2
.
cvtColor
(
prev
,
cv
2
.
COLOR
_BGR2GRAY
)
show_hsv
=
False
show_hsv
=
False
show_glitch
=
False
show_glitch
=
False
cur_glitch
=
prev
.
copy
()
cur_glitch
=
prev
.
copy
()
while
True
:
while
True
:
ret
,
img
=
cam
.
read
()
ret
,
img
=
cam
.
read
()
gray
=
cv2
.
cvtColor
(
img
,
cv
.
CV
_BGR2GRAY
)
gray
=
cv2
.
cvtColor
(
img
,
cv
2
.
COLOR
_BGR2GRAY
)
flow
=
cv2
.
calcOpticalFlowFarneback
(
prevgray
,
gray
,
None
,
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
...
...
samples/python2/stereo_match.py
View file @
16ba62dc
...
@@ -6,7 +6,6 @@ Resulting .ply file cam be easily viewed using MeshLab (http://meshlab.sourcefor
...
@@ -6,7 +6,6 @@ Resulting .ply file cam be easily viewed using MeshLab (http://meshlab.sourcefor
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
ply_header
=
'''ply
ply_header
=
'''ply
format ascii 1.0
format ascii 1.0
...
@@ -61,7 +60,7 @@ if __name__ == '__main__':
...
@@ -61,7 +60,7 @@ if __name__ == '__main__':
[
0
,
0
,
0
,
-
f
],
# so that y-axis looks up
[
0
,
0
,
0
,
-
f
],
# so that y-axis looks up
[
0
,
0
,
1
,
0
]])
[
0
,
0
,
1
,
0
]])
points
=
cv2
.
reprojectImageTo3D
(
disp
,
Q
)
points
=
cv2
.
reprojectImageTo3D
(
disp
,
Q
)
colors
=
cv2
.
cvtColor
(
imgL
,
cv
.
CV
_BGR2RGB
)
colors
=
cv2
.
cvtColor
(
imgL
,
cv
2
.
COLOR
_BGR2RGB
)
mask
=
disp
>
disp
.
min
()
mask
=
disp
>
disp
.
min
()
out_points
=
points
[
mask
]
out_points
=
points
[
mask
]
out_colors
=
colors
[
mask
]
out_colors
=
colors
[
mask
]
...
...
samples/python2/watershed.py
View file @
16ba62dc
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
cv2.cv
as
cv
from
common
import
Sketcher
from
common
import
Sketcher
help_message
=
'''
help_message
=
'''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment