Commit 318415f2 authored by Kurnianggoro's avatar Kurnianggoro

Added doxygen documentations

parent e4cacfc4
......@@ -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 splitCoeff; //!< split the training coefficients into two matrices
bool wrapKernel; //!< wrap around the kernel values
bool compressFeature; //!< 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_feature; //!< 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);
};
......
/*----------------------------------------------
* 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
}
......@@ -226,7 +226,7 @@ namespace cv{
// detection part
if(frame>0){
//compute the gaussian kernel
if(params.compressFeature){
if(params.compress_feature){
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.splitCoeff)
if(params.split_coeff)
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.compressFeature){
if(params.compress_feature){
// 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.splitCoeff){
if(params.split_coeff){
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.splitCoeff)alphaf_den=new_alphaf_den.clone();
if(params.split_coeff)alphaf_den=new_alphaf_den.clone();
}else{
alphaf=(1.0-params.interp_factor)*alphaf+params.interp_factor*new_alphaf;
if(params.splitCoeff)alphaf_den=(1.0-params.interp_factor)*alphaf_den+params.interp_factor*new_alphaf_den;
if(params.split_coeff)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.wrapKernel){
if(params.wrap_kernel){
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;
splitCoeff=true;
wrapKernel=false;
split_coeff=true;
wrap_kernel=false;
//feature compression
compressFeature=true;
compress_feature=true;
compressed_size=2;
pca_learning_rate=0.15;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment