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
514711af
Commit
514711af
authored
Jul 10, 2011
by
Alexander Mordvintsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
work on motempl.py sample
parent
8a3d1937
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
2 deletions
+68
-2
common.py
samples/python2/common.py
+7
-0
lk_track.py
samples/python2/lk_track.py
+4
-2
motempl.py
samples/python2/motempl.py
+57
-0
No files found.
samples/python2/common.py
View file @
514711af
...
...
@@ -109,3 +109,9 @@ def make_cmap(name, n=256):
ch
=
np
.
interp
(
xs
,
xp
,
yp
)
channels
.
append
(
ch
)
return
np
.
uint8
(
np
.
array
(
channels
)
.
T
*
255
)
def
nothing
(
*
arg
,
**
kw
):
pass
def
clock
():
return
cv2
.
getTickCount
()
/
cv2
.
getTickFrequency
()
\ No newline at end of file
samples/python2/lk_track.py
View file @
514711af
...
...
@@ -20,7 +20,7 @@ lk_params = dict( winSize = (3, 3),
criteria
=
(
cv2
.
TERM_CRITERIA_EPS
|
cv2
.
TERM_CRITERIA_COUNT
,
10
,
0.03
),
derivLambda
=
0.0
)
feature_params
=
dict
(
maxCorners
=
5
00
,
feature_params
=
dict
(
maxCorners
=
10
00
,
qualityLevel
=
0.1
,
minDistance
=
5
,
blockSize
=
5
)
...
...
@@ -42,6 +42,8 @@ def main():
try
:
video_src
=
sys
.
argv
[
1
]
except
:
video_src
=
video
.
presets
[
'chess'
]
cv2
.
namedWindow
(
'img'
,
0
)
track_len
=
4
tracks
=
[]
cam
=
video
.
create_capture
(
video_src
)
...
...
@@ -63,7 +65,7 @@ def main():
tr
.
append
((
x
,
y
))
if
len
(
tr
)
>
10
:
del
tr
[
0
]
cv2
.
circle
(
vis
,
(
x
,
y
),
2
,
(
0
,
255
,
0
),
-
2
)
cv2
.
circle
(
vis
,
(
x
,
y
),
2
,
(
0
,
255
,
0
),
-
1
)
cv2
.
polylines
(
vis
,
[
np
.
int32
(
tr
)
for
tr
in
tracks
],
False
,
(
0
,
255
,
0
))
draw_str
(
vis
,
(
20
,
20
),
[
'new'
,
'old'
][
old_mode
]
+
' mode'
)
draw_str
(
vis
,
(
20
,
40
),
'time:
%.02
f ms'
%
(
dt
*
1000
))
...
...
samples/python2/motempl.py
0 → 100644
View file @
514711af
import
numpy
as
np
import
cv2
,
cv
import
video
from
common
import
nothing
,
clock
,
draw_str
MHI_DURATION
=
1.0
DEFAULT_THRESHOLD
=
16
MAX_TIME_DELTA
=
0.5
MIN_TIME_DELTA
=
0.05
if
__name__
==
'__main__'
:
import
sys
try
:
video_src
=
sys
.
argv
[
1
]
except
:
video_src
=
'synth:class=chess:bg=../cpp/lena.jpg:noise=0.01'
cv2
.
namedWindow
(
'motempl'
)
visuals
=
[
'input'
,
'frame_diff'
,
'motion_hist'
,
'grad_orient'
]
cv2
.
createTrackbar
(
'visual'
,
'motempl'
,
2
,
len
(
visuals
)
-
1
,
nothing
)
cv2
.
createTrackbar
(
'threshold'
,
'motempl'
,
DEFAULT_THRESHOLD
,
255
,
nothing
)
cam
=
video
.
create_capture
(
video_src
)
ret
,
frame
=
cam
.
read
()
h
,
w
=
frame
.
shape
[:
2
]
prev_frame
=
frame
.
copy
()
motion_history
=
np
.
zeros
((
h
,
w
),
np
.
float32
)
hsv
=
np
.
zeros
((
h
,
w
,
3
),
np
.
uint8
)
hsv
[:,:,
1
]
=
255
while
True
:
ret
,
frame
=
cam
.
read
()
frame_diff
=
cv2
.
absdiff
(
frame
,
prev_frame
)
gray_diff
=
cv2
.
cvtColor
(
frame_diff
,
cv
.
CV_BGR2GRAY
)
thrs
=
cv2
.
getTrackbarPos
(
'threshold'
,
'motempl'
)
ret
,
motion_mask
=
cv2
.
threshold
(
gray_diff
,
thrs
,
255
,
cv2
.
THRESH_BINARY
)
timestamp
=
clock
()
cv2
.
updateMotionHistory
(
motion_mask
,
motion_history
,
timestamp
,
MHI_DURATION
)
mg_mask
,
mg_orient
=
cv2
.
calcMotionGradient
(
motion_history
,
MAX_TIME_DELTA
,
MIN_TIME_DELTA
,
apertureSize
=
5
);
visual_name
=
visuals
[
cv2
.
getTrackbarPos
(
'visual'
,
'motempl'
)]
if
visual_name
==
'input'
:
vis
=
frame
.
copy
()
elif
visual_name
==
'frame_diff'
:
vis
=
frame_diff
.
copy
()
elif
visual_name
==
'motion_hist'
:
vis
=
np
.
uint8
(
np
.
clip
((
motion_history
-
(
timestamp
-
MHI_DURATION
))
/
MHI_DURATION
,
0
,
1
)
*
255
)
vis
=
cv2
.
cvtColor
(
vis
,
cv
.
CV_GRAY2BGR
)
elif
visual_name
==
'grad_orient'
:
hsv
[:,:,
0
]
=
mg_orient
/
2
hsv
[:,:,
2
]
=
mg_mask
*
255
vis
=
cv2
.
cvtColor
(
hsv
,
cv
.
CV_HSV2BGR
)
draw_str
(
vis
,
(
20
,
20
),
visual_name
)
cv2
.
imshow
(
'motempl'
,
vis
)
prev_frame
=
frame
.
copy
()
if
cv2
.
waitKey
(
5
)
==
27
:
break
\ No newline at end of file
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