CIntImage_to_Featurevec.cpp
Go to the documentation of this file.
1 /*
2  * David Fischinger -TUW
3  * 18.11.2011
4  *
5  * CLASS for calculating Feature Vector from Integral Images
6  *
7  * OUTDATED!!!!
8  *
9  * USAGE:
10  * - generate ListOfIIFilenames.txt in correct folder
11  * - change all Parameters
12  * - execute
13  *
14  *
15  * input:
16  * Filenames (generated with: "ls pcd* -1 > ListOfIIFilenames.txt"
17  * executed in IntegralImages folder)
18  * with integral images and filename with features
19  *
20  * output:
21  * One file for each integral images including all feature values (1 value for each feature) is saved in the given output folder.
22  *
23  * PARAMETERS:
24  *
25  * HEIGHT 15 (14+1)
26  * WIDTH 15 (14+1)
27  * goodgps indicates if features for good or bad GPs are calculated => label +1/-1 in output .txt
28  */
29 
31 #include <CHaarFeature.h>
32 #include <iostream>
33 #include <iomanip>
34 
35 #define HEIGHT 15
36 #define WIDTH 15
37 
38 using namespace std;
39 //using namespace cv;
40 
41 
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);
44 }
45 
46 
47 void CIntImage_to_Featurevec::read_features(string featurespath)
48 {
49  //PARAMETERS
50  string path = featurespath;
51 
52  ifstream file_features;
53  file_features.open(path.c_str()); //file_features: file with all features
54  if (!file_features){
55  cout << "\n PROBLEM opening feature file: " << path.c_str() << endl;
56  }
57 
58  string line;
59  int id_x = -1;
60  getline(file_features, line);
61  while (file_features.good())
62  {
63  int start = 0, end = 0;
64  int reg_c[16]; //region_corners
65  float reg_w[4]; //region_weights
66  id_x++;
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()) ;
70  start = end+1;
71  }
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()) ;
75  start = end+1;
76  }
77 
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);
80 
81  getline(file_features, line);
82  }
83  file_features.close();
84 }
85 
86 
88 {
89 
90  for (int i = 0; i < this->allfeatures.size(); i++)
91  {
92  CHaarFeature curfeature = this->allfeatures.at(i);
93  for (int j = 0; j < 16; j++){
94  int reg_num = curfeature.regions.at(j);
95  cout << reg_num << "\t";
96  }
97  for (int j = 0; j < 4; j++){
98  float reg_w = curfeature.weights.at(j);
99  cout << reg_w << "\t";
100  }
101  cout << i << "\n" ;
102  }
103 }
104 
105 
107 {
108  //print heights matrix
109  cout << "print integral image matrix:" << endl;
110  for (int i = 0; i < HEIGHT; i++){ //rows
111  for (int j = 0; j < WIDTH; j++){ //cols
112  cout << this->intimagemat[i][j] << "\t";
113  }
114  cout << "\n";
115  }
116  cout << "\n david: ";
117  cout << this->currentfeature->nr_reg << endl;
118 }
119 
120 
121 
122 void CIntImage_to_Featurevec::write_featurevector(string outputpath, int nr_features_without_shaf)
123 {
124  //open output file
125  ofstream output_fv_file(outputpath.c_str(), fstream::app);
126  if (this->goodgps)
127  output_fv_file << "+1";
128  else
129  output_fv_file << "-1";
130  //for all features
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;
134  }
135  output_fv_file << "\n";
136  output_fv_file.close();
137 }
138 
139 
140 
141 float CIntImage_to_Featurevec::calc_featurevalue(int nr_feat, int nr_features_without_shaf)
142 {
143  float returnval = 0;
144  this->currentfeature = &this->allfeatures.at(nr_feat);
145  if (nr_feat < nr_features_without_shaf)
146  {
147  for (int nr_reg = 0; nr_reg <4; nr_reg++){
148  //corners of region
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]; //weight of region
154 
155  if (( wgt == 0.0 ) or //region not used (weight equal 0)
156  ( x2 < x1 ) or //r.x2 < r.x1
157  ( y2 < y1 ) or //r.y2 < r.y1
158  (x2 == 0 and y2 == 0)) //region corners are (0,0,0,0)
159  continue;
160 
161  returnval += wgt*(this->intimagemat[x2+1][y2+1] - this->intimagemat[x1][y2+1] -
162  this->intimagemat[x2+1][y1] + this->intimagemat[x1][y1]);
163  }
164  } else {//new (symmetry) features
165  //new features to check if top and bottom of grasp area are symmetric
166  float r[3]; //r[0]: top field, r[1] middle, r[2]: bottom/down
167  r[0] = r[1] = r[2] = 0;
168  for (int nr_reg = 0; nr_reg <3; nr_reg++){ //assuming 3 regions
169  bool grasp_ok = true;
170  //corners of region
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]; //weight of region
176 
177  if (( wgt == 0.0 ) or //region not used (weight equal 0)
178  ( x2 < x1 ) or //r.x2 < r.x1
179  ( y2 < y1 ) or //r.y2 < r.y1
180  (x2 == 0 and y2 == 0)) //region corners are (0,0,0,0)
181  continue;
182 
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]);
185  }
186 
187  if (r[1] > r[0] and r[1] > r[2]){
188  returnval = min(r[1]-r[0], r[1]-r[2]); //must be possitiv then
189  } else {
190  returnval = -1.0;
191  }
192  }
193  int cnt = 0;
194  if (false /*nr_feat == 1*/){
195  this->print_heights();
196  cout << "cnt, feature, returnval: " << cnt++ << "\t"<< nr_feat << " " << returnval << endl;
197  }
198  return returnval;
199 }
200 
201 
float calc_featurevalue(int nr_feat, int nr_features_without_shaf)
void read_features(string featurespath)
#define WIDTH
vector< int > regions
Definition: CHaarFeature.h:20
vector< double > weights
Definition: CHaarFeature.h:19
void write_featurevector(string outputpath, int nr_features_without_shaf)
char * line
Definition: svm-scale.c:21
#define HEIGHT
#define min(x, y)
Definition: libsvmread.c:18


haf_grasping
Author(s): David Fischinger
autogenerated on Mon Jun 10 2019 13:28:43