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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
29 deletions
+82
-29
tracker.hpp
modules/tracking/include/opencv2/tracking/tracker.hpp
+28
-5
kcf.cpp
modules/tracking/samples/kcf.cpp
+44
-14
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
class
CV_EXPORTS_W
TrackerKCF
:
public
Tracker
{
public
:
/**
* \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names
*/
enum
MODE
{
GRAY
,
CN
,
CN2
};
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
();
/**
...
...
@@ -1219,17 +1242,17 @@ class CV_EXPORTS_W TrackerKCF : public Tracker
double
output_sigma_factor
;
//!< spatial bandwidth (proportional to target)
double
pca_learning_rate
;
//!< compression learning rate
bool
resize
;
//!< activate the resize feature to improve the processing speed
bool
split
Coeff
;
//!< split the training coefficients into two matrices
bool
wrap
Kernel
;
//!< wrap around the kernel values
bool
compress
F
eature
;
//!< activate pca method to compress the features
bool
split
_coeff
;
//!< split the training coefficients into two matrices
bool
wrap
_kernel
;
//!< wrap around the kernel values
bool
compress
_f
eature
;
//!< activate pca method to compress the features
int
max_patch_size
;
//!< threshold for the ROI size
int
compressed_size
;
//!< feature size after compression
MODE
descriptor
;
//!< descriptor type
};
/** @brief Constructor
@param parameters KCF parameters TrackerKCF::Params
*/
@param parameters KCF parameters TrackerKCF::Params
*/
BOILERPLATE_CODE
(
"KCF"
,
TrackerKCF
);
};
...
...
modules/tracking/samples/kcf.cpp
View file @
318415f2
/*----------------------------------------------
* Usage:
* example_tracking_kcf <video
path
>
* example_tracking_kcf <video
_name
>
*
* example:
* example_tracking_kcf Bolt/img/%04.jpg
...
...
@@ -13,7 +13,6 @@
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
#include <algorithm>
using
namespace
std
;
using
namespace
cv
;
...
...
@@ -21,7 +20,7 @@ using namespace cv;
class
BoxExtractor
{
public
:
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
{
bool
isDrawing
;
...
...
@@ -37,25 +36,37 @@ private:
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
;
// create the tracker
Ptr
<
Tracker
>
tracker
=
Tracker
::
create
(
"KCF"
);
Rect2d
roi
;
int
start_frame
=
0
;
// set input video
std
::
string
video
=
argv
[
1
];
VideoCapture
cap
;
cap
.
open
(
video
);
cap
.
set
(
CAP_PROP_POS_FRAMES
,
start_frame
);
VideoCapture
cap
(
video
);
Mat
frame
;
// get bounding box
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
tracker
->
init
(
frame
,
roi
);
...
...
@@ -126,7 +137,7 @@ Rect2d BoxExtractor::extract(Mat 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
;
...
...
@@ -140,6 +151,7 @@ Rect2d BoxExtractor::extract(const std::string& windowName, Mat img){
// select the object
setMouseCallback
(
windowName
,
mouseHandler
,
(
void
*
)
&
params
);
// end selection process on SPACE (32) BACKSPACE (27) or ENTER (13)
while
(
!
(
key
==
32
||
key
==
27
||
key
==
13
)){
// draw the selected object
rectangle
(
...
...
@@ -148,6 +160,25 @@ Rect2d BoxExtractor::extract(const std::string& windowName, Mat img){
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
imshow
(
windowName
,
params
.
image
);
...
...
@@ -160,4 +191,4 @@ Rect2d BoxExtractor::extract(const std::string& windowName, Mat img){
return
params
.
box
;
}
\ No newline at end of file
}
modules/tracking/src/trackerKCF.cpp
View file @
318415f2
...
...
@@ -226,7 +226,7 @@ namespace cv{
// detection part
if
(
frame
>
0
){
//compute the gaussian kernel
if
(
params
.
compress
F
eature
){
if
(
params
.
compress
_f
eature
){
compress
(
proj_mtx
,
x
,
x
);
compress
(
proj_mtx
,
z
,
zc
);
denseGaussKernel
(
params
.
sigma
,
x
,
zc
,
k
);
...
...
@@ -234,7 +234,7 @@ namespace cv{
denseGaussKernel
(
params
.
sigma
,
x
,
z
,
k
);
// calculate filter response
if
(
params
.
split
C
oeff
)
if
(
params
.
split
_c
oeff
)
calcResponse
(
alphaf
,
alphaf_den
,
k
,
response
);
else
calcResponse
(
alphaf
,
k
,
response
);
...
...
@@ -259,7 +259,7 @@ namespace cv{
else
z
=
(
1.0
-
params
.
interp_factor
)
*
z
+
params
.
interp_factor
*
new_z
;
if
(
params
.
compress
F
eature
){
if
(
params
.
compress
_f
eature
){
// feature compression
updateProjectionMatrix
(
z
,
old_cov_mtx
,
proj_mtx
,
params
.
pca_learning_rate
,
params
.
compressed_size
);
compress
(
proj_mtx
,
x
,
x
);
...
...
@@ -278,7 +278,7 @@ namespace cv{
new_alphaf
=
Mat_
<
Vec2d
>
(
yf
.
rows
,
yf
.
cols
);
std
::
complex
<
double
>
temp
;
if
(
params
.
split
C
oeff
){
if
(
params
.
split
_c
oeff
){
mulSpectrums
(
yf
,
kf
,
new_alphaf
,
0
);
mulSpectrums
(
kf
,
kf_lambda
,
new_alphaf_den
,
0
);
}
else
{
...
...
@@ -294,10 +294,10 @@ namespace cv{
// update the RLS model
if
(
frame
==
0
){
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
{
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
++
;
...
...
@@ -551,7 +551,7 @@ namespace cv{
sumChannels
(
xyf_v
,
xyf
);
ifft2
(
xyf
,
xyf
);
if
(
params
.
wrap
K
ernel
){
if
(
params
.
wrap
_k
ernel
){
shiftRows
(
xyf
,
_x
.
rows
/
2
);
shiftCols
(
xyf
,
_x
.
cols
/
2
);
}
...
...
@@ -671,11 +671,11 @@ namespace cv{
resize
=
true
;
max_patch_size
=
80
*
80
;
descriptor
=
CN
;
split
C
oeff
=
true
;
wrap
K
ernel
=
false
;
split
_c
oeff
=
true
;
wrap
_k
ernel
=
false
;
//feature compression
compress
F
eature
=
true
;
compress
_f
eature
=
true
;
compressed_size
=
2
;
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