Commit 7c775af65893161a2e37937918ed5dea171474a6

Authored by Scott Klum
1 parent 45b460f7

More gradient histogram updates

openbr/plugins/representation/gradienthistogram.cpp
@@ -41,23 +41,25 @@ class GradientHistogramRepresentation : public Representation @@ -41,23 +41,25 @@ class GradientHistogramRepresentation : public Representation
41 41
42 void preprocess(const Mat &src, Mat &dst) const 42 void preprocess(const Mat &src, Mat &dst) const
43 { 43 {
  44 +
44 // Compute as is done in GradientTransform 45 // Compute as is done in GradientTransform
45 Mat dx, dy, magnitude, angle; 46 Mat dx, dy, magnitude, angle;
46 Sobel(src, dx, CV_32F, 1, 0, CV_SCHARR); 47 Sobel(src, dx, CV_32F, 1, 0, CV_SCHARR);
47 Sobel(src, dy, CV_32F, 0, 1, CV_SCHARR); 48 Sobel(src, dy, CV_32F, 0, 1, CV_SCHARR);
48 cartToPolar(dx, dy, magnitude, angle, true); 49 cartToPolar(dx, dy, magnitude, angle, true);
49 50
  51 + const double floor = ((src.depth() == CV_32F) || (src.depth() == CV_64F)) ? -0.5 : 0;
  52 +
50 Mat histogram; 53 Mat histogram;
51 - // Bin as is done in HistBin  
52 - angle.convertTo(histogram, bins > 256 ? CV_16U : CV_8U, bins/360, 0); 54 + angle.convertTo(histogram, bins > 256 ? CV_16U : CV_8U, bins/360., floor);
53 55
54 // Mask and compute integral image 56 // Mask and compute integral image
55 std::vector<Mat> outputs; 57 std::vector<Mat> outputs;
56 - for (int i=0; i<bins; i++) { 58 + for (int i=0; i<1; i++) {
57 Mat output = (histogram == i); 59 Mat output = (histogram == i);
58 - Mat integalImg;  
59 - integral(output, integalImg);  
60 - outputs.push_back(integalImg); 60 + Mat integralImg;
  61 + integral(output, integralImg);
  62 + outputs.push_back(integralImg);
61 } 63 }
62 64
63 merge(outputs,dst); 65 merge(outputs,dst);
@@ -78,7 +80,7 @@ class GradientHistogramRepresentation : public Representation @@ -78,7 +80,7 @@ class GradientHistogramRepresentation : public Representation
78 float evaluate(const Mat &image, int idx) const 80 float evaluate(const Mat &image, int idx) const
79 { 81 {
80 /* Stored in memory as (row,col,channel): (0,0,0), (0,0,1), ... , (0,0,bin-1), (0,1,0), (0,1,1), ... , (0,1,bin-1), ... , (0,cols,0), (0,cols,1), ... , (0,cols,bin-1) 82 /* Stored in memory as (row,col,channel): (0,0,0), (0,0,1), ... , (0,0,bin-1), (0,1,0), (0,1,1), ... , (0,1,bin-1), ... , (0,cols,0), (0,cols,1), ... , (0,cols,bin-1)
81 - /* (1,0,0), (1,0,1), ... , (1,0,bin-1), (1,1,0), (1,1,1), ... , (1,1,bin-1), ... , (1,cols,0), (1,cols,1), ... , (1,cols,bin-1) 83 + * (1,0,0), (1,0,1), ... , (1,0,bin-1), (1,1,0), (1,1,1), ... , (1,1,bin-1), ... , (1,cols,0), (1,cols,1), ... , (1,cols,bin-1)
82 * 84 *
83 * (row,0,0), (row,0,1), ... , (row,0,bin-1), (row,1,0), (row,1,1), ... , (row,1,bin-1), ... , (row,cols,0), (row,cols,1), ... , (row,cols,bin-1) 85 * (row,0,0), (row,0,1), ... , (row,0,bin-1), (row,1,0), (row,1,1), ... , (row,1,bin-1), ... , (row,cols,0), (row,cols,1), ... , (row,cols,bin-1)
84 */ 86 */
@@ -87,10 +89,10 @@ class GradientHistogramRepresentation : public Representation @@ -87,10 +89,10 @@ class GradientHistogramRepresentation : public Representation
87 const int index = idx % features.size(); 89 const int index = idx % features.size();
88 const int channel = idx / features.size(); 90 const int channel = idx / features.size();
89 91
90 - float four = image.ptr<float>(features[index].y+features[index].height)[(features[index].x+features[index].width)*channel];  
91 - float one = image.ptr<float>(features[index].y)[features[index].x*channel];  
92 - float two = image.ptr<float>(features[index].y)[(features[index].x+features[index].width)*channel];  
93 - float three = image.ptr<float>(features[index].y+features[index].height)[features[index].x*channel]; 92 + int four = image.ptr<int>(features[index].y+features[index].height)[(features[index].x+features[index].width)*channel];
  93 + int one = image.ptr<int>(features[index].y)[features[index].x*channel];
  94 + int two = image.ptr<int>(features[index].y)[(features[index].x+features[index].width)*channel];
  95 + int three = image.ptr<int>(features[index].y+features[index].height)[features[index].x*channel];
94 96
95 return four + one - (two + three); 97 return four + one - (two + three);
96 } 98 }
@@ -107,7 +109,7 @@ class GradientHistogramRepresentation : public Representation @@ -107,7 +109,7 @@ class GradientHistogramRepresentation : public Representation
107 109
108 int numFeatures() const 110 int numFeatures() const
109 { 111 {
110 - return features.size()*bins; 112 + return features.size();
111 } 113 }
112 114
113 Size windowSize(int *dx, int *dy) const 115 Size windowSize(int *dx, int *dy) const