Commit f55f1045e454c5cbb3b5f73ddb387fd9c609b189

Authored by Scott Klum
1 parent 7c775af6

More gradienthistogram fixes

openbr/plugins/representation/gradienthistogram.cpp
@@ -41,7 +41,6 @@ class GradientHistogramRepresentation : public Representation @@ -41,7 +41,6 @@ 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 -  
45 // Compute as is done in GradientTransform 44 // Compute as is done in GradientTransform
46 Mat dx, dy, magnitude, angle; 45 Mat dx, dy, magnitude, angle;
47 Sobel(src, dx, CV_32F, 1, 0, CV_SCHARR); 46 Sobel(src, dx, CV_32F, 1, 0, CV_SCHARR);
@@ -55,14 +54,17 @@ class GradientHistogramRepresentation : public Representation @@ -55,14 +54,17 @@ class GradientHistogramRepresentation : public Representation
55 54
56 // Mask and compute integral image 55 // Mask and compute integral image
57 std::vector<Mat> outputs; 56 std::vector<Mat> outputs;
58 - for (int i=0; i<1; i++) { 57 + for (int i=0; i<bins; i++) {
59 Mat output = (histogram == i); 58 Mat output = (histogram == i);
60 Mat integralImg; 59 Mat integralImg;
61 integral(output, integralImg); 60 integral(output, integralImg);
62 outputs.push_back(integralImg); 61 outputs.push_back(integralImg);
63 } 62 }
64 63
  64 + // Concatenate images into row
65 merge(outputs,dst); 65 merge(outputs,dst);
  66 +
  67 + // TODO: Output first image and gradient histogram
66 } 68 }
67 69
68 /* ___ ___ 70 /* ___ ___
@@ -79,20 +81,16 @@ class GradientHistogramRepresentation : public Representation @@ -79,20 +81,16 @@ class GradientHistogramRepresentation : public Representation
79 81
80 float evaluate(const Mat &image, int idx) const 82 float evaluate(const Mat &image, int idx) const
81 { 83 {
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)  
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)  
84 - *  
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)  
86 - */ 84 + // TODO: Check that values are at expected locations
87 85
88 // To which channel does an index belong? 86 // To which channel does an index belong?
89 const int index = idx % features.size(); 87 const int index = idx % features.size();
90 const int channel = idx / features.size(); 88 const int channel = idx / features.size();
91 89
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]; 90 + int four = image.ptr<int>(0)[(features[index].y+features[index].height)*(features[index].x+features[index].width)*bins+channel];
  91 + int one = image.ptr<int>(0)[features[index].y*features[index].x*bins+channel];
  92 + int two = image.ptr<int>(0)[features[index].y*(features[index].x+features[index].width)*bins+channel];
  93 + int three = image.ptr<int>(0)[(features[index].y+features[index].height)*features[index].x*bins+channel];
96 94
97 return four + one - (two + three); 95 return four + one - (two + three);
98 } 96 }
@@ -109,7 +107,7 @@ class GradientHistogramRepresentation : public Representation @@ -109,7 +107,7 @@ class GradientHistogramRepresentation : public Representation
109 107
110 int numFeatures() const 108 int numFeatures() const
111 { 109 {
112 - return features.size(); 110 + return features.size()*bins;
113 } 111 }
114 112
115 Size windowSize(int *dx, int *dy) const 113 Size windowSize(int *dx, int *dy) const