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
d5ba7c38
Commit
d5ba7c38
authored
Jun 17, 2011
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed crashes in camshiftdemo (ticket #875)
parent
3ca31dcd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
45 deletions
+72
-45
camshift.cpp
modules/video/src/camshift.cpp
+7
-0
camshiftdemo.cpp
samples/cpp/camshiftdemo.cpp
+65
-45
No files found.
modules/video/src/camshift.cpp
View file @
d5ba7c38
...
...
@@ -90,6 +90,13 @@ cvMeanShift( const void* imgProb, CvRect windowIn,
int
dx
,
dy
,
nx
,
ny
;
double
inv_m00
;
cur_rect
=
cv
::
Rect
(
cur_rect
)
&
cv
::
Rect
(
0
,
0
,
mat
->
cols
,
mat
->
rows
);
if
(
cv
::
Rect
(
cur_rect
)
==
cv
::
Rect
()
)
{
cur_rect
.
x
=
mat
->
cols
/
2
;
cur_rect
.
y
=
mat
->
rows
/
2
;
}
cur_rect
.
width
=
MAX
(
cur_rect
.
width
,
1
);
cur_rect
.
height
=
MAX
(
cur_rect
.
height
,
1
);
cvGetSubRect
(
mat
,
&
cur_win
,
cur_rect
);
cvMoments
(
&
cur_win
,
&
moments
);
...
...
samples/cpp/camshiftdemo.cpp
View file @
d5ba7c38
...
...
@@ -22,6 +22,7 @@ void help()
"
\t
c - stop the tracking
\n
"
"
\t
b - switch to/from backprojection view
\n
"
"
\t
h - show/hide object histogram
\n
"
"
\t
p - pause video
\n
"
"To initialize tracking, select the object with mouse
\n
"
<<
endl
;
}
...
...
@@ -87,69 +88,85 @@ int main( int argc, char** argv )
help
();
namedWindow
(
"Histogram"
,
1
);
namedWindow
(
"CamShift Demo"
,
1
);
namedWindow
(
"Histogram"
,
0
);
namedWindow
(
"CamShift Demo"
,
0
);
setMouseCallback
(
"CamShift Demo"
,
onMouse
,
0
);
createTrackbar
(
"Vmin"
,
"CamShift Demo"
,
&
vmin
,
256
,
0
);
createTrackbar
(
"Vmax"
,
"CamShift Demo"
,
&
vmax
,
256
,
0
);
createTrackbar
(
"Smin"
,
"CamShift Demo"
,
&
smin
,
256
,
0
);
Mat
hsv
,
hue
,
mask
,
hist
,
histimg
=
Mat
::
zeros
(
200
,
320
,
CV_8UC3
),
backproj
;
Mat
frame
,
hsv
,
hue
,
mask
,
hist
,
histimg
=
Mat
::
zeros
(
200
,
320
,
CV_8UC3
),
backproj
;
bool
paused
=
false
;
for
(;;)
{
Mat
frame
;
cap
>>
frame
;
if
(
frame
.
empty
()
)
break
;
if
(
!
paused
)
{
cap
>>
frame
;
if
(
frame
.
empty
()
)
break
;
}
frame
.
copyTo
(
image
);
cvtColor
(
image
,
hsv
,
CV_BGR2HSV
);
if
(
trackObject
)
if
(
!
paused
)
{
int
_vmin
=
vmin
,
_vmax
=
vmax
;
cvtColor
(
image
,
hsv
,
CV_BGR2HSV
)
;
inRange
(
hsv
,
Scalar
(
0
,
smin
,
MIN
(
_vmin
,
_vmax
)),
Scalar
(
180
,
256
,
MAX
(
_vmin
,
_vmax
)),
mask
);
int
ch
[]
=
{
0
,
0
};
hue
.
create
(
hsv
.
size
(),
hsv
.
depth
());
mixChannels
(
&
hsv
,
1
,
&
hue
,
1
,
ch
,
1
);
if
(
trackObject
<
0
)
if
(
trackObject
)
{
Mat
roi
(
hue
,
selection
),
maskroi
(
mask
,
selection
);
calcHist
(
&
roi
,
1
,
0
,
maskroi
,
hist
,
1
,
&
hsize
,
&
phranges
);
normalize
(
hist
,
hist
,
0
,
255
,
CV_MINMAX
);
trackWindow
=
selection
;
trackObject
=
1
;
histimg
=
Scalar
::
all
(
0
);
int
binW
=
histimg
.
cols
/
hsize
;
Mat
buf
(
1
,
hsize
,
CV_8UC3
);
for
(
int
i
=
0
;
i
<
hsize
;
i
++
)
buf
.
at
<
Vec3b
>
(
i
)
=
Vec3b
(
saturate_cast
<
uchar
>
(
i
*
180.
/
hsize
),
255
,
255
);
cvtColor
(
buf
,
buf
,
CV_HSV2BGR
);
for
(
int
i
=
0
;
i
<
hsize
;
i
++
)
int
_vmin
=
vmin
,
_vmax
=
vmax
;
inRange
(
hsv
,
Scalar
(
0
,
smin
,
MIN
(
_vmin
,
_vmax
)),
Scalar
(
180
,
256
,
MAX
(
_vmin
,
_vmax
)),
mask
);
int
ch
[]
=
{
0
,
0
};
hue
.
create
(
hsv
.
size
(),
hsv
.
depth
());
mixChannels
(
&
hsv
,
1
,
&
hue
,
1
,
ch
,
1
);
if
(
trackObject
<
0
)
{
int
val
=
saturate_cast
<
int
>
(
hist
.
at
<
float
>
(
i
)
*
histimg
.
rows
/
255
);
rectangle
(
histimg
,
Point
(
i
*
binW
,
histimg
.
rows
),
Point
((
i
+
1
)
*
binW
,
histimg
.
rows
-
val
),
Scalar
(
buf
.
at
<
Vec3b
>
(
i
)),
-
1
,
8
);
Mat
roi
(
hue
,
selection
),
maskroi
(
mask
,
selection
);
calcHist
(
&
roi
,
1
,
0
,
maskroi
,
hist
,
1
,
&
hsize
,
&
phranges
);
normalize
(
hist
,
hist
,
0
,
255
,
CV_MINMAX
);
trackWindow
=
selection
;
trackObject
=
1
;
histimg
=
Scalar
::
all
(
0
);
int
binW
=
histimg
.
cols
/
hsize
;
Mat
buf
(
1
,
hsize
,
CV_8UC3
);
for
(
int
i
=
0
;
i
<
hsize
;
i
++
)
buf
.
at
<
Vec3b
>
(
i
)
=
Vec3b
(
saturate_cast
<
uchar
>
(
i
*
180.
/
hsize
),
255
,
255
);
cvtColor
(
buf
,
buf
,
CV_HSV2BGR
);
for
(
int
i
=
0
;
i
<
hsize
;
i
++
)
{
int
val
=
saturate_cast
<
int
>
(
hist
.
at
<
float
>
(
i
)
*
histimg
.
rows
/
255
);
rectangle
(
histimg
,
Point
(
i
*
binW
,
histimg
.
rows
),
Point
((
i
+
1
)
*
binW
,
histimg
.
rows
-
val
),
Scalar
(
buf
.
at
<
Vec3b
>
(
i
)),
-
1
,
8
);
}
}
}
calcBackProject
(
&
hue
,
1
,
0
,
hist
,
backproj
,
&
phranges
);
backproj
&=
mask
;
RotatedRect
trackBox
=
CamShift
(
backproj
,
trackWindow
,
TermCriteria
(
CV_TERMCRIT_EPS
|
CV_TERMCRIT_ITER
,
10
,
1
));
calcBackProject
(
&
hue
,
1
,
0
,
hist
,
backproj
,
&
phranges
);
backproj
&=
mask
;
RotatedRect
trackBox
=
CamShift
(
backproj
,
trackWindow
,
TermCriteria
(
CV_TERMCRIT_EPS
|
CV_TERMCRIT_ITER
,
10
,
1
));
if
(
trackWindow
.
area
()
<=
1
)
{
int
cols
=
backproj
.
cols
,
rows
=
backproj
.
rows
,
r
=
(
MIN
(
cols
,
rows
)
+
5
)
/
6
;
trackWindow
=
Rect
(
trackWindow
.
x
-
r
,
trackWindow
.
y
-
r
,
trackWindow
.
x
+
r
,
trackWindow
.
y
+
r
)
&
Rect
(
0
,
0
,
cols
,
rows
);
}
if
(
backprojMode
)
cvtColor
(
backproj
,
image
,
CV_GRAY2BGR
);
ellipse
(
image
,
trackBox
,
Scalar
(
0
,
0
,
255
),
3
,
CV_AA
);
if
(
backprojMode
)
cvtColor
(
backproj
,
image
,
CV_GRAY2BGR
);
ellipse
(
image
,
trackBox
,
Scalar
(
0
,
0
,
255
),
3
,
CV_AA
);
}
}
else
if
(
trackObject
<
0
)
paused
=
false
;
if
(
selectObject
&&
selection
.
width
>
0
&&
selection
.
height
>
0
)
{
...
...
@@ -179,6 +196,9 @@ int main( int argc, char** argv )
else
namedWindow
(
"Histogram"
,
1
);
break
;
case
'p'
:
paused
=
!
paused
;
break
;
default:
;
}
...
...
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