tracking:fix rounding and grayscale for KCF

pull/1474/head
berak 8 years ago
parent a30fb44d61
commit 94c09fe8c8
  1. 13
      modules/tracking/src/trackerKCF.cpp
  2. 8
      modules/tracking/tutorials/tutorial_introduction_to_tracker.markdown

@ -212,7 +212,10 @@ namespace cv{
*/ */
bool TrackerKCFImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){ bool TrackerKCFImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){
frame=0; frame=0;
roi = boundingBox; roi.x = cvRound(boundingBox.x);
roi.y = cvRound(boundingBox.y);
roi.width = cvRound(boundingBox.width);
roi.height = cvRound(boundingBox.height);
//calclulate output sigma //calclulate output sigma
output_sigma=std::sqrt(static_cast<float>(roi.width*roi.height))*params.output_sigma_factor; output_sigma=std::sqrt(static_cast<float>(roi.width*roi.height))*params.output_sigma_factor;
@ -242,8 +245,8 @@ namespace cv{
// create gaussian response // create gaussian response
y=Mat::zeros((int)roi.height,(int)roi.width,CV_32F); y=Mat::zeros((int)roi.height,(int)roi.width,CV_32F);
for(int i=0;i<roi.height;i++){ for(int i=0;i<int(roi.height);i++){
for(int j=0;j<roi.width;j++){ for(int j=0;j<int(roi.width);j++){
y.at<float>(i,j) = y.at<float>(i,j) =
static_cast<float>((i-roi.height/2+1)*(i-roi.height/2+1)+(j-roi.width/2+1)*(j-roi.width/2+1)); static_cast<float>((i-roi.height/2+1)*(i-roi.height/2+1)+(j-roi.width/2+1)*(j-roi.width/2+1));
} }
@ -255,6 +258,10 @@ namespace cv{
// perform fourier transfor to the gaussian response // perform fourier transfor to the gaussian response
fft2(y,yf); fft2(y,yf);
if (image.channels() == 1) { // disable CN for grayscale images
params.desc_pca &= ~(CN);
params.desc_npca &= ~(CN);
}
model=Ptr<TrackerKCFModel>(new TrackerKCFModel(params)); model=Ptr<TrackerKCFModel>(new TrackerKCFModel(params));
// record the non-compressed descriptors // record the non-compressed descriptors

@ -44,12 +44,14 @@ Explanation
@snippet tracking/samples/tutorial_introduction_to_tracker.cpp create @snippet tracking/samples/tutorial_introduction_to_tracker.cpp create
There are at least 5 types of tracker algorithms that can be used: There are at least 7 types of tracker algorithms that can be used:
+ MIL + MIL
+ BOOSTING + BOOSTING
+ MEDIANFLOW + MEDIANFLOW
+ TLD + TLD
+ KCF + KCF
+ GOTURN
+ MOSSE
Each tracker algorithm has their own advantages and disadvantages, please refer the documentation of @ref cv::Tracker for more detailed information. Each tracker algorithm has their own advantages and disadvantages, please refer the documentation of @ref cv::Tracker for more detailed information.
@ -64,8 +66,8 @@ Explanation
@snippet tracking/samples/tutorial_introduction_to_tracker.cpp init @snippet tracking/samples/tutorial_introduction_to_tracker.cpp init
Tracker algorithm should be initialized with the provided image data as well as the bounding box of the tracked object. Any tracker algorithm should be initialized with the provided image data, and an initial bounding box of the tracked object.
Make sure that the bounding box is not valid (size more than zero) to avoid the initialization process failed. Make sure that the bounding box is valid (size more than zero) to avoid failure of the initialization process.
-# **Update** -# **Update**

Loading…
Cancel
Save