-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
118 lines (109 loc) · 3.28 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "projectHeader.h"
#include "projectFunctions.h"
void getallconfig(vector<string> &configurations)
{
//configurations.push_back("hof");
// configurations.push_back("hog");
configurations.push_back("mbh");
// configurations.push_back("baseline");
/*configurations.push_back("hog hof");
configurations.push_back("hof mbh");
configurations.push_back("mbh baseline");
configurations.push_back("hof baseline");
*/
/* configurations.push_back("hog mbh");
configurations.push_back("hog baseline");
/* configurations.push_back("hog hof mbh baseline");
configurations.push_back("hof mbh");
configurations.push_back("hof mbh baseline");
configurations.push_back("hog mbh baseline");
configurations.push_back("hog hof mbh");*/
}
void getparts(string fullname,vector<string> &elements)
{
stringstream ss(fullname);
string buf;
while(ss >> buf)
{
elements.push_back(buf);
}
for(int i=0; i<elements.size(); i++)
{
cout<<elements[i]<<endl;
}
}
cv::Mat reduceFeatures(cv::Mat& Feat, int maxFeatures)
{
if(Feat.rows < maxFeatures)
{
return Feat;
}
cv::Mat retFeat = cvCreateMat(0,Feat.cols,Feat.type());
// get a random number.. put that row in the new matrix.. return the new matrix
vector<int> randomnumbers;
srand((unsigned)time(0));
int rd;
do
{
rd = (rand() % Feat.rows);
if(find(randomnumbers.begin(),randomnumbers.end(),rd) == randomnumbers.end())
{
// new random number !
retFeat.push_back(Feat.row(rd));
randomnumbers.push_back(rd);
}
}while(randomnumbers.size() < maxFeatures);
if(retFeat.rows != maxFeatures)
{
cout<<"Was not able to fill the matrix with maxFetures ! The number of rows are "<<retFeat.rows<<endl;
}
return retFeat;
}
cv::Mat concatenateFeatures_reduce(cv::Mat &hog, cv::Mat& hof, cv::Mat &mbh,int maxFeatures)
{
int combinedfeatdim = hog.cols + hof.cols + mbh.cols;
if(hog.rows != hof.rows)
{
cout<<"rows mismatch "<<endl;
exit(0);
}
if(hog.rows != mbh.rows)
{
cout<<"rows mismatch "<<endl;
exit(0);
}
int total_rows = hog.rows;
cout<<"Total features are "<<total_rows<<endl;
cv::Mat combinedFeat = cvCreateMat(total_rows,combinedfeatdim,CV_32FC1);
int col_count ;
for(int i=0; i<total_rows; i++)
{
col_count = 0;
for(int j=0; j<hog.cols; j++)
{
combinedFeat.at<float>(i,col_count++) =hog.at<float>(i,j);
}
// cout<<"col_count after hog is "<<col_count<<endl;
for(int j=0; j<hof.cols; j++)
{
combinedFeat.at<float>(i,col_count++) =hof.at<float>(i,j);
}
// cout<<"col_count after hof is "<<col_count<<endl;
for(int j=0; j<mbh.cols; j++)
{
combinedFeat.at<float>(i,col_count++) =mbh.at<float>(i,j);
}
// cout<<"col_count after mbh is "<<col_count<<endl;
}
// reduce features to max
if(maxFeatures == -1) // do not reduce !
{
return combinedFeat;
}
else
{
cv::Mat combineReduce = reduceFeatures(combinedFeat,maxFeatures);
cout<<"Reduced features to "<<combineReduce.rows<<endl;
return combineReduce;
}
}