CHaarFeature.cpp
Go to the documentation of this file.
1 /*
2  * CHaarFeature.cpp
3  *
4  * Created on: Sep 22, 2011
5  * Author: David Fischinger
6  */
7 
8 #include <iostream>
9 #include "CHaarFeature.h"
10 #include <vector>
11 #include <opencv/cv.h>
12 
13 using namespace std;
14 
15 //constructor for features with 2 regions
16 CHaarFeature::CHaarFeature(int r1x1,int r1x2,int r1y1,int r1y2,int r2x1,int r2x2,int r2y1,int r2y2,double r1weight,double r2weight ){
17  this->nr_reg = 2;
18  this->weights = vector<double>(2);
19  this->weights[0] = r1weight;
20  this->weights[1] = r2weight;
21  this->regions = vector<int>(8);
22  this->regions[0] = r1x1;
23  this->regions[1] = r1x2;
24  this->regions[2] = r1y1;
25  this->regions[3] = r1y2;
26  this->regions[4] = r2x1;
27  this->regions[5] = r2x2;
28  this->regions[6] = r2y1;
29  this->regions[7] = r2y2;
30 }
31 
32 //constructor for features with 3 regions
33 CHaarFeature::CHaarFeature(int r1x1, int r1x2, int r1y1, int r1y2, int r2x1, int r2x2, int r2y1, int r2y2, int r3x1, int r3x2, int r3y1, int r3y2, double r1weight, double r2weight, double r3weight){
34  this->nr_reg = 3;
35  this->weights = vector<double>(3);
36  this->weights[0] = r1weight;
37  this->weights[1] = r2weight;
38  this->weights[2] = r3weight;
39  this->regions = vector<int>(12);
40  this->regions[0] = r1x1;
41  this->regions[1] = r1x2;
42  this->regions[2] = r1y1;
43  this->regions[3] = r1y2;
44  this->regions[4] = r2x1;
45  this->regions[5] = r2x2;
46  this->regions[6] = r2y1;
47  this->regions[7] = r2y2;
48  this->regions[8] = r3x1;
49  this->regions[9] = r3x2;
50  this->regions[10] = r3y1;
51  this->regions[11] = r3y2;
52 }
53 //constructor for features with 4 regions
54 CHaarFeature::CHaarFeature(int r1x1, int r1x2, int r1y1, int r1y2, int r2x1, int r2x2, int r2y1, int r2y2, int r3x1, int r3x2, int r3y1, int r3y2, int r4x1, int r4x2, int r4y1, int r4y2, \
55  double r1weight, double r2weight, double r3weight, double r4weight){
56  this->nr_reg = 4;
57  this->weights = vector<double>(4);
58  this->weights[0] = r1weight;
59  this->weights[1] = r2weight;
60  this->weights[2] = r3weight;
61  this->regions = vector<int>(16);
62  this->regions[0] = r1x1;
63  this->regions[1] = r1x2;
64  this->regions[2] = r1y1;
65  this->regions[3] = r1y2;
66  this->regions[4] = r2x1;
67  this->regions[5] = r2x2;
68  this->regions[6] = r2y1;
69  this->regions[7] = r2y2;
70  this->regions[8] = r3x1;
71  this->regions[9] = r3x2;
72  this->regions[10] = r3y1;
73  this->regions[11] = r3y2;
74  this->regions[12] = r4x1;
75  this->regions[13] = r4x2;
76  this->regions[14] = r4y1;
77  this->regions[15] = r4y2;
78 }
79 
80 
81 //calculates the Feature value for the feature using the given integral image and the position posx and posy
82 double CHaarFeature::calcFval(cv::Mat heightsIntegral, int pos_x, int pos_y)
83 {
84  double retval = 0;
85  double retval_old = 0;
86  for (int reg = 0; reg < this->nr_reg; reg++){ //for each region calculate weighted value
87  double weight = this->weights[reg];
88  int colx1 = pos_x + this->regions[4*reg]; //x1-value for integral image pixel (of moving window) in region reg
89  int colx2 = pos_x + this->regions[4*reg+1]; //x2-value for integral image pixel (of moving window) in region reg
90  int rowy1 = pos_y + this->regions[4*reg+2]; //y1-value for integral image pixel (of moving window) in region reg
91  int rowy2 = pos_y + this->regions[4*reg+3]; //y2-value for integral image pixel (of moving window) in region reg
92  retval_old = retval;
93  retval = retval + weight*(
94  ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy2)))[colx2] //x2y2 biggest rect. positiv
95  + ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy1-1)))[colx1-1] //x1y1 smallest rect. positiv
96  - ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy2)))[colx1-1] //x1y2 rectangle left of region (to subtract)
97  - ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy1-1)))[colx2] //x2y1 rectangle above region (to subtract)
98  );
99  //cout << "\n sum of region: " << reg+1 << " " << retval - retval_old << endl;
100  }
101  return retval;
102 }
103 
CHaarFeature(int r1x1, int r1x2, int r1y1, int r1y2, int r2x1, int r2x2, int r2y1, int r2y2, double r1weight, double r2weight)
double calcFval(cv::Mat heightsIntegral, int pos_x, int pos_y)


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