11 TrackerKCF::Params param;
12 param.desc_pca = TrackerKCF::GRAY | TrackerKCF::CN;
14 param.compress_feature =
true;
15 param.compressed_size = 2;
17 tracker = TrackerKCF::create(param);
21 tracker->init(srcImage, armourBlock);
28 if(
tracker->update(srcImage, armourBlock) ==
false)
34 rectangle(srcImage, armourBlock, Scalar(255, 0, 0), 2, 1);
47 if(roi.x<0){region.x=0;region.width+=roi.x;}
48 if(roi.y<0){region.y=0;region.height+=roi.y;}
49 if(roi.x+roi.width>img.cols)region.width=img.cols-roi.x;
50 if(roi.y+roi.height>img.rows)region.height=img.rows-roi.y;
51 if(region.width>img.cols)region.width=img.cols;
52 if(region.height>img.rows)region.height=img.rows;
55 patch=img(region).clone();
56 cvtColor(patch,patch, CV_BGR2GRAY);
60 int addTop,addBottom, addLeft, addRight;
61 addTop=region.y-roi.y;
62 addBottom=(roi.height+roi.y>img.rows?roi.height+roi.y-img.rows:0);
63 addLeft=region.x-roi.x;
64 addRight=(roi.width+roi.x>img.cols?roi.width+roi.x-img.cols:0);
66 copyMakeBorder(patch,patch,addTop,addBottom,addLeft,addRight,BORDER_REPLICATE);
70 Sobel(patch, sobel[0], CV_32F,1,0,1);
71 Sobel(patch, sobel[1], CV_32F,0,1,1);
77 feat.convertTo(feat,CV_64F);
HLL Computer Vision Code namepace.
static void sobelExtractor(const Mat img, const Rect roi, Mat &feat)
sobel特征提取器
void init(const Mat &srcImage, Rect2d armourBlock)
创建图像追踪器并设定参数
bool track(Mat srcImage)
追踪目标区域
Ptr< TrackerKCF > tracker
kcf匹配算法图像追踪器