CHaarFeature.cpp
Go to the documentation of this file.
00001 /*
00002  * CHaarFeature.cpp
00003  *
00004  *  Created on: Sep 22, 2011
00005  *      Author: David Fischinger
00006  */
00007 
00008 #include <iostream>
00009 #include "CHaarFeature.h"
00010 #include <vector>
00011 #include <opencv/cv.h>
00012 
00013 using namespace std;
00014 
00015 //constructor for features with 2 regions
00016 CHaarFeature::CHaarFeature(int r1x1,int r1x2,int r1y1,int r1y2,int r2x1,int r2x2,int r2y1,int r2y2,double r1weight,double r2weight ){
00017         this->nr_reg = 2;
00018         this->weights = vector<double>(2);
00019         this->weights[0] = r1weight;
00020         this->weights[1] = r2weight;
00021         this->regions = vector<int>(8);
00022         this->regions[0] = r1x1;
00023         this->regions[1] = r1x2;
00024         this->regions[2] = r1y1;
00025         this->regions[3] = r1y2;
00026         this->regions[4] = r2x1;
00027         this->regions[5] = r2x2;
00028         this->regions[6] = r2y1;
00029         this->regions[7] = r2y2;
00030 }
00031 
00032 //constructor for features with 3 regions
00033 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){
00034         this->nr_reg = 3;
00035         this->weights = vector<double>(3);
00036         this->weights[0] = r1weight;
00037         this->weights[1] = r2weight;
00038         this->weights[2] = r3weight;
00039         this->regions = vector<int>(12);
00040         this->regions[0] = r1x1;
00041         this->regions[1] = r1x2;
00042         this->regions[2] = r1y1;
00043         this->regions[3] = r1y2;
00044         this->regions[4] = r2x1;
00045         this->regions[5] = r2x2;
00046         this->regions[6] = r2y1;
00047         this->regions[7] = r2y2;
00048         this->regions[8] = r3x1;
00049         this->regions[9] = r3x2;
00050         this->regions[10] = r3y1;
00051         this->regions[11] = r3y2;
00052 }
00053 //constructor for features with 4 regions
00054 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, \
00055                          double r1weight, double r2weight, double r3weight, double r4weight){
00056         this->nr_reg = 4;
00057         this->weights = vector<double>(4);
00058         this->weights[0] = r1weight;
00059         this->weights[1] = r2weight;
00060         this->weights[2] = r3weight;
00061         this->regions = vector<int>(16);
00062         this->regions[0] = r1x1;
00063         this->regions[1] = r1x2;
00064         this->regions[2] = r1y1;
00065         this->regions[3] = r1y2;
00066         this->regions[4] = r2x1;
00067         this->regions[5] = r2x2;
00068         this->regions[6] = r2y1;
00069         this->regions[7] = r2y2;
00070         this->regions[8] = r3x1;
00071         this->regions[9] = r3x2;
00072         this->regions[10] = r3y1;
00073         this->regions[11] = r3y2;
00074         this->regions[12] = r4x1;
00075         this->regions[13] = r4x2;
00076         this->regions[14] = r4y1;
00077         this->regions[15] = r4y2;
00078 }
00079 
00080 
00081 //calculates the Feature value for the feature using the given integral image and the position posx and posy
00082 double CHaarFeature::calcFval(cv::Mat heightsIntegral, int pos_x, int pos_y)
00083 {
00084         double retval = 0;
00085         double retval_old = 0;
00086         for (int reg = 0; reg < this->nr_reg; reg++){   //for each region calculate weighted value
00087                 double weight = this->weights[reg];
00088                 int colx1 = pos_x + this->regions[4*reg];       //x1-value for integral image pixel (of moving window) in region reg
00089                 int colx2 = pos_x + this->regions[4*reg+1];     //x2-value for integral image pixel (of moving window) in region reg
00090                 int rowy1 = pos_y + this->regions[4*reg+2]; //y1-value for integral image pixel (of moving window) in region reg
00091                 int rowy2 = pos_y + this->regions[4*reg+3]; //y2-value for integral image pixel (of moving window) in region reg
00092                 retval_old = retval;
00093                 retval = retval + weight*(
00094                                 ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy2)))[colx2]                //x2y2 biggest rect. positiv
00095                         +       ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy1-1)))[colx1-1]    //x1y1 smallest rect. positiv
00096                         -       ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy2)))[colx1-1]              //x1y2  rectangle left of region (to subtract)
00097                         -       ((double*)(heightsIntegral.ptr() + heightsIntegral.step*(rowy1-1)))[colx2]              //x2y1 rectangle above region (to subtract)
00098                         );
00099                 //cout << "\n sum of region: " << reg+1 << "  " << retval - retval_old << endl;
00100         }
00101         return retval;
00102 }
00103 


haf_grasping
Author(s): David Fischinger
autogenerated on Thu Jun 6 2019 18:35:09