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
c7481c55
Commit
c7481c55
authored
Jan 13, 2016
by
BinMatrix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the mouse bug and the problem of collapse
parent
e3690db4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
17 deletions
+10
-17
camshift.py
samples/python/camshift.py
+10
-17
No files found.
samples/python/camshift.py
View file @
c7481c55
...
@@ -46,28 +46,22 @@ class App(object):
...
@@ -46,28 +46,22 @@ class App(object):
self
.
selection
=
None
self
.
selection
=
None
self
.
drag_start
=
None
self
.
drag_start
=
None
self
.
tracking_state
=
0
self
.
show_backproj
=
False
self
.
show_backproj
=
False
self
.
track_window
=
None
def
onmouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
def
onmouse
(
self
,
event
,
x
,
y
,
flags
,
param
):
x
,
y
=
np
.
int16
([
x
,
y
])
# BUG
if
event
==
cv2
.
EVENT_LBUTTONDOWN
:
if
event
==
cv2
.
EVENT_LBUTTONDOWN
:
self
.
drag_start
=
(
x
,
y
)
self
.
drag_start
=
(
x
,
y
)
self
.
tracking_state
=
0
self
.
track_window
=
None
return
if
self
.
drag_start
:
if
self
.
drag_start
:
if
flags
&
cv2
.
EVENT_FLAG_LBUTTON
:
xmin
=
min
(
x
,
self
.
drag_start
[
0
])
h
,
w
=
self
.
frame
.
shape
[:
2
]
ymin
=
min
(
y
,
self
.
drag_start
[
1
])
xo
,
yo
=
self
.
drag_start
xmax
=
max
(
x
,
self
.
drag_start
[
0
])
x0
,
y0
=
np
.
maximum
(
0
,
np
.
minimum
([
xo
,
yo
],
[
x
,
y
]))
ymax
=
max
(
y
,
self
.
drag_start
[
1
])
x1
,
y1
=
np
.
minimum
([
w
,
h
],
np
.
maximum
([
xo
,
yo
],
[
x
,
y
]))
self
.
selection
=
(
xmin
,
ymin
,
xmax
,
ymax
)
self
.
selection
=
None
if
event
==
cv2
.
EVENT_LBUTTONUP
:
if
x1
-
x0
>
0
and
y1
-
y0
>
0
:
self
.
selection
=
(
x0
,
y0
,
x1
,
y1
)
else
:
self
.
drag_start
=
None
self
.
drag_start
=
None
if
self
.
selection
is
not
None
:
self
.
track_window
=
(
xmin
,
ymin
,
xmax
-
xmin
,
ymax
-
ymin
)
self
.
tracking_state
=
1
def
show_hist
(
self
):
def
show_hist
(
self
):
bin_count
=
self
.
hist
.
shape
[
0
]
bin_count
=
self
.
hist
.
shape
[
0
]
...
@@ -88,7 +82,6 @@ class App(object):
...
@@ -88,7 +82,6 @@ class App(object):
if
self
.
selection
:
if
self
.
selection
:
x0
,
y0
,
x1
,
y1
=
self
.
selection
x0
,
y0
,
x1
,
y1
=
self
.
selection
self
.
track_window
=
(
x0
,
y0
,
x1
-
x0
,
y1
-
y0
)
hsv_roi
=
hsv
[
y0
:
y1
,
x0
:
x1
]
hsv_roi
=
hsv
[
y0
:
y1
,
x0
:
x1
]
mask_roi
=
mask
[
y0
:
y1
,
x0
:
x1
]
mask_roi
=
mask
[
y0
:
y1
,
x0
:
x1
]
hist
=
cv2
.
calcHist
(
[
hsv_roi
],
[
0
],
mask_roi
,
[
16
],
[
0
,
180
]
)
hist
=
cv2
.
calcHist
(
[
hsv_roi
],
[
0
],
mask_roi
,
[
16
],
[
0
,
180
]
)
...
@@ -100,7 +93,7 @@ class App(object):
...
@@ -100,7 +93,7 @@ class App(object):
cv2
.
bitwise_not
(
vis_roi
,
vis_roi
)
cv2
.
bitwise_not
(
vis_roi
,
vis_roi
)
vis
[
mask
==
0
]
=
0
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
self
.
selection
=
None
prob
=
cv2
.
calcBackProject
([
hsv
],
[
0
],
self
.
hist
,
[
0
,
180
],
1
)
prob
=
cv2
.
calcBackProject
([
hsv
],
[
0
],
self
.
hist
,
[
0
,
180
],
1
)
prob
&=
mask
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