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
d6134a00
Commit
d6134a00
authored
Jan 14, 2016
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5962 from BinMatrix:patch-4
parents
cda8e449
c7481c55
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
18 deletions
+11
-18
camshift.py
samples/python/camshift.py
+11
-18
No files found.
samples/python/camshift.py
View file @
d6134a00
...
...
@@ -46,28 +46,22 @@ class App(object):
self
.
selection
=
None
self
.
drag_start
=
None
self
.
tracking_state
=
0
self
.
show_backproj
=
False
self
.
track_window
=
None
def
onmouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
x
,
y
=
np
.
int16
([
x
,
y
])
# BUG
if
event
==
cv2
.
EVENT_LBUTTONDOWN
:
self
.
drag_start
=
(
x
,
y
)
self
.
tracking_state
=
0
return
self
.
track_window
=
None
if
self
.
drag_start
:
if
flags
&
cv2
.
EVENT_FLAG_LBUTTON
:
h
,
w
=
self
.
frame
.
shape
[:
2
]
xo
,
yo
=
self
.
drag_start
x0
,
y0
=
np
.
maximum
(
0
,
np
.
minimum
([
xo
,
yo
],
[
x
,
y
]))
x1
,
y1
=
np
.
minimum
([
w
,
h
],
np
.
maximum
([
xo
,
yo
],
[
x
,
y
]))
self
.
selection
=
None
if
x1
-
x0
>
0
and
y1
-
y0
>
0
:
self
.
selection
=
(
x0
,
y0
,
x1
,
y1
)
else
:
self
.
drag_start
=
None
if
self
.
selection
is
not
None
:
self
.
tracking_state
=
1
xmin
=
min
(
x
,
self
.
drag_start
[
0
])
ymin
=
min
(
y
,
self
.
drag_start
[
1
])
xmax
=
max
(
x
,
self
.
drag_start
[
0
])
ymax
=
max
(
y
,
self
.
drag_start
[
1
])
self
.
selection
=
(
xmin
,
ymin
,
xmax
,
ymax
)
if
event
==
cv2
.
EVENT_LBUTTONUP
:
self
.
drag_start
=
None
self
.
track_window
=
(
xmin
,
ymin
,
xmax
-
xmin
,
ymax
-
ymin
)
def
show_hist
(
self
):
bin_count
=
self
.
hist
.
shape
[
0
]
...
...
@@ -88,7 +82,6 @@ class App(object):
if
self
.
selection
:
x0
,
y0
,
x1
,
y1
=
self
.
selection
self
.
track_window
=
(
x0
,
y0
,
x1
-
x0
,
y1
-
y0
)
hsv_roi
=
hsv
[
y0
:
y1
,
x0
:
x1
]
mask_roi
=
mask
[
y0
:
y1
,
x0
:
x1
]
hist
=
cv2
.
calcHist
(
[
hsv_roi
],
[
0
],
mask_roi
,
[
16
],
[
0
,
180
]
)
...
...
@@ -100,7 +93,7 @@ class App(object):
cv2
.
bitwise_not
(
vis_roi
,
vis_roi
)
vis
[
mask
==
0
]
=
0
if
self
.
track
ing_state
==
1
:
if
self
.
track
_window
and
self
.
track_window
[
2
]
>
0
and
self
.
track_window
[
3
]
>
0
:
self
.
selection
=
None
prob
=
cv2
.
calcBackProject
([
hsv
],
[
0
],
self
.
hist
,
[
0
,
180
],
1
)
prob
&=
mask
...
...
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