43 currentfeature =
new CHaarFeature(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.1,1.0,1.0,2.0);
50 string path = featurespath;
52 ifstream file_features;
53 file_features.open(path.c_str());
55 cout <<
"\n PROBLEM opening feature file: " << path.c_str() << endl;
60 getline(file_features, line);
61 while (file_features.good())
63 int start = 0, end = 0;
67 for (
int i = 0; i < 16; i++){
68 end = line.find(
"\t", start);
69 reg_c[i] = atoi(line.substr(start,end-start).c_str()) ;
72 for (
int j = 0; j < 4; j++){
73 end = line.find(
"\t", start);
74 reg_w[j] = atof(line.substr(start,end-start).c_str()) ;
78 CHaarFeature * tmp_feature =
new CHaarFeature(reg_c[0],reg_c[1],reg_c[2],reg_c[3], reg_c[4],reg_c[5],reg_c[6],reg_c[7],reg_c[8],reg_c[9],reg_c[10],reg_c[11],reg_c[12],reg_c[13],reg_c[14],reg_c[15],reg_w[0],reg_w[1],reg_w[2],reg_w[3]);
79 this->allfeatures.push_back(*tmp_feature);
81 getline(file_features, line);
83 file_features.close();
90 for (
int i = 0; i < this->allfeatures.size(); i++)
93 for (
int j = 0; j < 16; j++){
94 int reg_num = curfeature.
regions.at(j);
95 cout << reg_num <<
"\t";
97 for (
int j = 0; j < 4; j++){
98 float reg_w = curfeature.
weights.at(j);
99 cout << reg_w <<
"\t";
109 cout <<
"print integral image matrix:" << endl;
110 for (
int i = 0; i <
HEIGHT; i++){
111 for (
int j = 0; j <
WIDTH; j++){
112 cout << this->intimagemat[i][j] <<
"\t";
116 cout <<
"\n david: ";
117 cout << this->currentfeature->nr_reg << endl;
125 ofstream output_fv_file(outputpath.c_str(), fstream::app);
127 output_fv_file <<
"+1";
129 output_fv_file <<
"-1";
131 for (
int nr_feat = 0; nr_feat < this->allfeatures.size(); nr_feat++){
132 float featureval = calc_featurevalue(nr_feat, nr_features_without_shaf);
133 output_fv_file <<
" " << nr_feat+1 <<
":" << setprecision(4) << featureval;
135 output_fv_file <<
"\n";
136 output_fv_file.close();
144 this->currentfeature = &this->allfeatures.at(nr_feat);
145 if (nr_feat < nr_features_without_shaf)
147 for (
int nr_reg = 0; nr_reg <4; nr_reg++){
149 int x1 = currentfeature->regions[nr_reg*4];
150 int x2 = currentfeature->regions[nr_reg*4+1];
151 int y1 = currentfeature->regions[nr_reg*4+2];
152 int y2 = currentfeature->regions[nr_reg*4+3];
153 float wgt = currentfeature->weights[nr_reg];
155 if (( wgt == 0.0 ) or
158 (x2 == 0 and y2 == 0))
161 returnval += wgt*(this->intimagemat[x2+1][y2+1] - this->intimagemat[x1][y2+1] -
162 this->intimagemat[x2+1][y1] + this->intimagemat[x1][y1]);
167 r[0] = r[1] = r[2] = 0;
168 for (
int nr_reg = 0; nr_reg <3; nr_reg++){
169 bool grasp_ok =
true;
171 int x1 = currentfeature->regions[nr_reg*4];
172 int x2 = currentfeature->regions[nr_reg*4+1];
173 int y1 = currentfeature->regions[nr_reg*4+2];
174 int y2 = currentfeature->regions[nr_reg*4+3];
175 float wgt = currentfeature->weights[nr_reg];
177 if (( wgt == 0.0 ) or
180 (x2 == 0 and y2 == 0))
183 r[nr_reg] = wgt*(this->intimagemat[x2+1][y2+1] - this->intimagemat[x1][y2+1] -
184 this->intimagemat[x2+1][y1] + this->intimagemat[x1][y1]);
187 if (r[1] > r[0] and r[1] > r[2]){
188 returnval =
min(r[1]-r[0], r[1]-r[2]);
195 this->print_heights();
196 cout <<
"cnt, feature, returnval: " << cnt++ <<
"\t"<< nr_feat <<
" " << returnval << endl;
float calc_featurevalue(int nr_feat, int nr_features_without_shaf)
void read_features(string featurespath)
CIntImage_to_Featurevec()
void write_featurevector(string outputpath, int nr_features_without_shaf)