Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
318415f2
Commit
318415f2
authored
Jun 30, 2015
by
Kurnianggoro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added doxygen documentations
parent
e4cacfc4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
25 deletions
+79
-25
tracker.hpp
modules/tracking/include/opencv2/tracking/tracker.hpp
+26
-3
kcf.cpp
modules/tracking/samples/kcf.cpp
+43
-12
trackerKCF.cpp
modules/tracking/src/trackerKCF.cpp
+10
-10
No files found.
modules/tracking/include/opencv2/tracking/tracker.hpp
View file @
318415f2
...
@@ -1198,9 +1198,32 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
...
@@ -1198,9 +1198,32 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
class
CV_EXPORTS_W
TrackerKCF
:
public
Tracker
class
CV_EXPORTS_W
TrackerKCF
:
public
Tracker
{
{
public
:
public
:
/**
* \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names
*/
enum
MODE
{
GRAY
,
CN
,
CN2
};
enum
MODE
{
GRAY
,
CN
,
CN2
};
struct
CV_EXPORTS
Params
struct
CV_EXPORTS
Params
{
{
/**
* \brief Constructor
* \param sigma bandwidth of the gaussian kernel
* \param lambda regularization coefficient
* \param interp_factor inear interpolation factor for model updating
* \param output_sigma_factor spatial bandwidth (proportional to target)
* \param pca_learning_rate learning rate of the compression method
* \param resize activate the resize feature to improve the processing speed
* \param split_coeff split the training coefficients into two matrices
* \param wrap_kernel wrap around the kernel values
* \param compressFeature activate pca method to compress the features
* \param max_patch_size threshold for the ROI size
* \param compressed_size feature size after compression
* \param descriptor descriptor type
* The modes available now:
- "GRAY" -- Use grayscale values as the feature
- "CN" -- Color-names feature
- "CN2" -- Compressed color-names feature
*/
Params
();
Params
();
/**
/**
...
@@ -1219,9 +1242,9 @@ class CV_EXPORTS_W TrackerKCF : public Tracker
...
@@ -1219,9 +1242,9 @@ class CV_EXPORTS_W TrackerKCF : public Tracker
double
output_sigma_factor
;
//!< spatial bandwidth (proportional to target)
double
output_sigma_factor
;
//!< spatial bandwidth (proportional to target)
double
pca_learning_rate
;
//!< compression learning rate
double
pca_learning_rate
;
//!< compression learning rate
bool
resize
;
//!< activate the resize feature to improve the processing speed
bool
resize
;
//!< activate the resize feature to improve the processing speed
bool
split
Coeff
;
//!< split the training coefficients into two matrices
bool
split
_coeff
;
//!< split the training coefficients into two matrices
bool
wrap
Kernel
;
//!< wrap around the kernel values
bool
wrap
_kernel
;
//!< wrap around the kernel values
bool
compress
F
eature
;
//!< activate pca method to compress the features
bool
compress
_f
eature
;
//!< activate pca method to compress the features
int
max_patch_size
;
//!< threshold for the ROI size
int
max_patch_size
;
//!< threshold for the ROI size
int
compressed_size
;
//!< feature size after compression
int
compressed_size
;
//!< feature size after compression
MODE
descriptor
;
//!< descriptor type
MODE
descriptor
;
//!< descriptor type
...
...
modules/tracking/samples/kcf.cpp
View file @
318415f2
/*----------------------------------------------
/*----------------------------------------------
* Usage:
* Usage:
* example_tracking_kcf <video
path
>
* example_tracking_kcf <video
_name
>
*
*
* example:
* example:
* example_tracking_kcf Bolt/img/%04.jpg
* example_tracking_kcf Bolt/img/%04.jpg
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
#include <opencv2/highgui.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <iostream>
#include <cstring>
#include <cstring>
#include <algorithm>
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
...
@@ -21,7 +20,7 @@ using namespace cv;
...
@@ -21,7 +20,7 @@ using namespace cv;
class
BoxExtractor
{
class
BoxExtractor
{
public
:
public
:
Rect2d
extract
(
Mat
img
);
Rect2d
extract
(
Mat
img
);
Rect2d
extract
(
const
std
::
string
&
windowName
,
Mat
img
);
Rect2d
extract
(
const
std
::
string
&
windowName
,
Mat
img
,
bool
showCrossair
=
true
);
struct
handlerT
{
struct
handlerT
{
bool
isDrawing
;
bool
isDrawing
;
...
@@ -37,25 +36,37 @@ private:
...
@@ -37,25 +36,37 @@ private:
void
opencv_mouse_callback
(
int
event
,
int
x
,
int
y
,
int
,
void
*
param
);
void
opencv_mouse_callback
(
int
event
,
int
x
,
int
y
,
int
,
void
*
param
);
};
};
int
main
(
int
,
char
**
argv
){
int
main
(
int
argc
,
char
**
argv
){
// show help
if
(
argc
<
2
){
cout
<<
" Usage: example_tracking_kcf <video_name>
\n
"
" examples:
\n
"
" example_tracking_kcf Bolt/img/%04.jpg
\n
"
" example_tracking_kcf faceocc2.webm
\n
"
<<
endl
;
return
0
;
}
// ROI selector
BoxExtractor
box
;
BoxExtractor
box
;
// create the tracker
// create the tracker
Ptr
<
Tracker
>
tracker
=
Tracker
::
create
(
"KCF"
);
Ptr
<
Tracker
>
tracker
=
Tracker
::
create
(
"KCF"
);
Rect2d
roi
;
// set input video
int
start_frame
=
0
;
std
::
string
video
=
argv
[
1
];
std
::
string
video
=
argv
[
1
];
VideoCapture
cap
(
video
);
VideoCapture
cap
;
cap
.
open
(
video
);
cap
.
set
(
CAP_PROP_POS_FRAMES
,
start_frame
);
Mat
frame
;
Mat
frame
;
// get bounding box
// get bounding box
cap
>>
frame
;
cap
>>
frame
;
roi
=
box
.
extract
(
"tracker"
,
frame
);
Rect2d
roi
=
box
.
extract
(
"tracker"
,
frame
);
//quit if ROI was not selected
if
(
roi
.
width
==
0
||
roi
.
height
==
0
)
return
0
;
// initialize the tracker
// initialize the tracker
tracker
->
init
(
frame
,
roi
);
tracker
->
init
(
frame
,
roi
);
...
@@ -126,7 +137,7 @@ Rect2d BoxExtractor::extract(Mat img){
...
@@ -126,7 +137,7 @@ Rect2d BoxExtractor::extract(Mat img){
return
extract
(
"Bounding Box Extractor"
,
img
);
return
extract
(
"Bounding Box Extractor"
,
img
);
}
}
Rect2d
BoxExtractor
::
extract
(
const
std
::
string
&
windowName
,
Mat
img
){
Rect2d
BoxExtractor
::
extract
(
const
std
::
string
&
windowName
,
Mat
img
,
bool
showCrossair
){
int
key
=
0
;
int
key
=
0
;
...
@@ -140,6 +151,7 @@ Rect2d BoxExtractor::extract(const std::string& windowName, Mat img){
...
@@ -140,6 +151,7 @@ Rect2d BoxExtractor::extract(const std::string& windowName, Mat img){
// select the object
// select the object
setMouseCallback
(
windowName
,
mouseHandler
,
(
void
*
)
&
params
);
setMouseCallback
(
windowName
,
mouseHandler
,
(
void
*
)
&
params
);
// end selection process on SPACE (32) BACKSPACE (27) or ENTER (13)
while
(
!
(
key
==
32
||
key
==
27
||
key
==
13
)){
while
(
!
(
key
==
32
||
key
==
27
||
key
==
13
)){
// draw the selected object
// draw the selected object
rectangle
(
rectangle
(
...
@@ -148,6 +160,25 @@ Rect2d BoxExtractor::extract(const std::string& windowName, Mat img){
...
@@ -148,6 +160,25 @@ Rect2d BoxExtractor::extract(const std::string& windowName, Mat img){
Scalar
(
255
,
0
,
0
),
2
,
1
Scalar
(
255
,
0
,
0
),
2
,
1
);
);
// draw cross air in the middle of bounding box
if
(
showCrossair
){
// horizontal line
line
(
params
.
image
,
Point
(
params
.
box
.
x
,
params
.
box
.
y
+
0.5
*
params
.
box
.
height
),
Point
(
params
.
box
.
x
+
params
.
box
.
width
,
params
.
box
.
y
+
0.5
*
params
.
box
.
height
),
Scalar
(
255
,
0
,
0
),
2
,
1
);
// vertical line
line
(
params
.
image
,
Point
(
params
.
box
.
x
+
0.5
*
params
.
box
.
width
,
params
.
box
.
y
),
Point
(
params
.
box
.
x
+
0.5
*
params
.
box
.
width
,
params
.
box
.
y
+
params
.
box
.
height
),
Scalar
(
255
,
0
,
0
),
2
,
1
);
}
// show the image bouding box
// show the image bouding box
imshow
(
windowName
,
params
.
image
);
imshow
(
windowName
,
params
.
image
);
...
...
modules/tracking/src/trackerKCF.cpp
View file @
318415f2
...
@@ -226,7 +226,7 @@ namespace cv{
...
@@ -226,7 +226,7 @@ namespace cv{
// detection part
// detection part
if
(
frame
>
0
){
if
(
frame
>
0
){
//compute the gaussian kernel
//compute the gaussian kernel
if
(
params
.
compress
F
eature
){
if
(
params
.
compress
_f
eature
){
compress
(
proj_mtx
,
x
,
x
);
compress
(
proj_mtx
,
x
,
x
);
compress
(
proj_mtx
,
z
,
zc
);
compress
(
proj_mtx
,
z
,
zc
);
denseGaussKernel
(
params
.
sigma
,
x
,
zc
,
k
);
denseGaussKernel
(
params
.
sigma
,
x
,
zc
,
k
);
...
@@ -234,7 +234,7 @@ namespace cv{
...
@@ -234,7 +234,7 @@ namespace cv{
denseGaussKernel
(
params
.
sigma
,
x
,
z
,
k
);
denseGaussKernel
(
params
.
sigma
,
x
,
z
,
k
);
// calculate filter response
// calculate filter response
if
(
params
.
split
C
oeff
)
if
(
params
.
split
_c
oeff
)
calcResponse
(
alphaf
,
alphaf_den
,
k
,
response
);
calcResponse
(
alphaf
,
alphaf_den
,
k
,
response
);
else
else
calcResponse
(
alphaf
,
k
,
response
);
calcResponse
(
alphaf
,
k
,
response
);
...
@@ -259,7 +259,7 @@ namespace cv{
...
@@ -259,7 +259,7 @@ namespace cv{
else
else
z
=
(
1.0
-
params
.
interp_factor
)
*
z
+
params
.
interp_factor
*
new_z
;
z
=
(
1.0
-
params
.
interp_factor
)
*
z
+
params
.
interp_factor
*
new_z
;
if
(
params
.
compress
F
eature
){
if
(
params
.
compress
_f
eature
){
// feature compression
// feature compression
updateProjectionMatrix
(
z
,
old_cov_mtx
,
proj_mtx
,
params
.
pca_learning_rate
,
params
.
compressed_size
);
updateProjectionMatrix
(
z
,
old_cov_mtx
,
proj_mtx
,
params
.
pca_learning_rate
,
params
.
compressed_size
);
compress
(
proj_mtx
,
x
,
x
);
compress
(
proj_mtx
,
x
,
x
);
...
@@ -278,7 +278,7 @@ namespace cv{
...
@@ -278,7 +278,7 @@ namespace cv{
new_alphaf
=
Mat_
<
Vec2d
>
(
yf
.
rows
,
yf
.
cols
);
new_alphaf
=
Mat_
<
Vec2d
>
(
yf
.
rows
,
yf
.
cols
);
std
::
complex
<
double
>
temp
;
std
::
complex
<
double
>
temp
;
if
(
params
.
split
C
oeff
){
if
(
params
.
split
_c
oeff
){
mulSpectrums
(
yf
,
kf
,
new_alphaf
,
0
);
mulSpectrums
(
yf
,
kf
,
new_alphaf
,
0
);
mulSpectrums
(
kf
,
kf_lambda
,
new_alphaf_den
,
0
);
mulSpectrums
(
kf
,
kf_lambda
,
new_alphaf_den
,
0
);
}
else
{
}
else
{
...
@@ -294,10 +294,10 @@ namespace cv{
...
@@ -294,10 +294,10 @@ namespace cv{
// update the RLS model
// update the RLS model
if
(
frame
==
0
){
if
(
frame
==
0
){
alphaf
=
new_alphaf
.
clone
();
alphaf
=
new_alphaf
.
clone
();
if
(
params
.
split
C
oeff
)
alphaf_den
=
new_alphaf_den
.
clone
();
if
(
params
.
split
_c
oeff
)
alphaf_den
=
new_alphaf_den
.
clone
();
}
else
{
}
else
{
alphaf
=
(
1.0
-
params
.
interp_factor
)
*
alphaf
+
params
.
interp_factor
*
new_alphaf
;
alphaf
=
(
1.0
-
params
.
interp_factor
)
*
alphaf
+
params
.
interp_factor
*
new_alphaf
;
if
(
params
.
split
C
oeff
)
alphaf_den
=
(
1.0
-
params
.
interp_factor
)
*
alphaf_den
+
params
.
interp_factor
*
new_alphaf_den
;
if
(
params
.
split
_c
oeff
)
alphaf_den
=
(
1.0
-
params
.
interp_factor
)
*
alphaf_den
+
params
.
interp_factor
*
new_alphaf_den
;
}
}
frame
++
;
frame
++
;
...
@@ -551,7 +551,7 @@ namespace cv{
...
@@ -551,7 +551,7 @@ namespace cv{
sumChannels
(
xyf_v
,
xyf
);
sumChannels
(
xyf_v
,
xyf
);
ifft2
(
xyf
,
xyf
);
ifft2
(
xyf
,
xyf
);
if
(
params
.
wrap
K
ernel
){
if
(
params
.
wrap
_k
ernel
){
shiftRows
(
xyf
,
_x
.
rows
/
2
);
shiftRows
(
xyf
,
_x
.
rows
/
2
);
shiftCols
(
xyf
,
_x
.
cols
/
2
);
shiftCols
(
xyf
,
_x
.
cols
/
2
);
}
}
...
@@ -671,11 +671,11 @@ namespace cv{
...
@@ -671,11 +671,11 @@ namespace cv{
resize
=
true
;
resize
=
true
;
max_patch_size
=
80
*
80
;
max_patch_size
=
80
*
80
;
descriptor
=
CN
;
descriptor
=
CN
;
split
C
oeff
=
true
;
split
_c
oeff
=
true
;
wrap
K
ernel
=
false
;
wrap
_k
ernel
=
false
;
//feature compression
//feature compression
compress
F
eature
=
true
;
compress
_f
eature
=
true
;
compressed_size
=
2
;
compressed_size
=
2
;
pca_learning_rate
=
0.15
;
pca_learning_rate
=
0.15
;
}
}
...
...
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