forked from Slifers/MS-TLD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tld_utils.cpp
38 lines (32 loc) · 1013 Bytes
/
tld_utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "tld_utils.h"
using namespace cv;
using namespace std;
void drawBox(Mat& image, CvRect box, Scalar color, int thick){
rectangle( image, cvPoint(box.x, box.y), cvPoint(box.x+box.width,box.y+box.height),color, thick);
}
void drawPoints(Mat& image, vector<Point2f> points,Scalar color){
for( vector<Point2f>::const_iterator i = points.begin(), ie = points.end(); i != ie; ++i )
{
Point center( cvRound(i->x ), cvRound(i->y));
circle(image,*i,2,color,1);
}
}
Mat createMask(const Mat& image, CvRect box){
Mat mask = Mat::zeros(image.rows,image.cols,CV_8U);
drawBox(mask,box,Scalar::all(255),CV_FILLED);
return mask;
}
float median(vector<float> v)
{
int n = (int)floor((double)v.size() / 2);
nth_element(v.begin(), v.begin()+n, v.end());
return v[n];
}
vector<int> index_shuffle(int begin,int end){
vector<int> indexes(end-begin);
for (int i=begin;i<end;i++){
indexes[i]=i;
}
random_shuffle(indexes.begin(),indexes.end());
return indexes;
}