diff --git a/openbr/plugins/representation/gradienthistogram.cpp b/openbr/plugins/representation/gradienthistogram.cpp index e629fee..a1de56e 100644 --- a/openbr/plugins/representation/gradienthistogram.cpp +++ b/openbr/plugins/representation/gradienthistogram.cpp @@ -41,23 +41,25 @@ class GradientHistogramRepresentation : public Representation void preprocess(const Mat &src, Mat &dst) const { + // Compute as is done in GradientTransform Mat dx, dy, magnitude, angle; Sobel(src, dx, CV_32F, 1, 0, CV_SCHARR); Sobel(src, dy, CV_32F, 0, 1, CV_SCHARR); cartToPolar(dx, dy, magnitude, angle, true); + const double floor = ((src.depth() == CV_32F) || (src.depth() == CV_64F)) ? -0.5 : 0; + Mat histogram; - // Bin as is done in HistBin - angle.convertTo(histogram, bins > 256 ? CV_16U : CV_8U, bins/360, 0); + angle.convertTo(histogram, bins > 256 ? CV_16U : CV_8U, bins/360., floor); // Mask and compute integral image std::vector outputs; - for (int i=0; i(features[index].y+features[index].height)[(features[index].x+features[index].width)*channel]; - float one = image.ptr(features[index].y)[features[index].x*channel]; - float two = image.ptr(features[index].y)[(features[index].x+features[index].width)*channel]; - float three = image.ptr(features[index].y+features[index].height)[features[index].x*channel]; + int four = image.ptr(features[index].y+features[index].height)[(features[index].x+features[index].width)*channel]; + int one = image.ptr(features[index].y)[features[index].x*channel]; + int two = image.ptr(features[index].y)[(features[index].x+features[index].width)*channel]; + int three = image.ptr(features[index].y+features[index].height)[features[index].x*channel]; return four + one - (two + three); } @@ -107,7 +109,7 @@ class GradientHistogramRepresentation : public Representation int numFeatures() const { - return features.size()*bins; + return features.size(); } Size windowSize(int *dx, int *dy) const