Commit 14650db9510efde71178c8e6e7d2780c63d25a2a

Authored by Scott Klum
1 parent 24ca08bc

Removed GradientHistogram

openbr/plugins/representation/gradienthistogram.cpp deleted
1 -#include <opencv2/imgproc/imgproc.hpp>  
2 -#include <opencv2/highgui/highgui.hpp>  
3 -  
4 -#include <openbr/plugins/openbr_internal.h>  
5 -#include <openbr/core/opencvutils.h>  
6 -  
7 -using namespace cv;  
8 -  
9 -namespace br  
10 -{  
11 -  
12 -/*!  
13 - * \ingroup representations  
14 - * \brief Computes first order gradient histogram features using an integral image  
15 - * \author Scott Klum \cite sklum  
16 - */  
17 -class GradientHistogramRepresentation : public Representation  
18 -{  
19 - Q_OBJECT  
20 -  
21 - Q_PROPERTY(int winWidth READ get_winWidth WRITE set_winWidth RESET reset_winWidth STORED false)  
22 - Q_PROPERTY(int winHeight READ get_winHeight WRITE set_winHeight RESET reset_winHeight STORED false)  
23 - Q_PROPERTY(int bins READ get_bins WRITE set_bins RESET reset_bins STORED false)  
24 - Q_PROPERTY(bool squareOnly READ get_squareOnly WRITE set_squareOnly RESET reset_squareOnly STORED false)  
25 - BR_PROPERTY(int, winWidth, 24)  
26 - BR_PROPERTY(int, winHeight, 24)  
27 - BR_PROPERTY(int, bins, 6)  
28 - BR_PROPERTY(bool, squareOnly, false)  
29 -  
30 - void init()  
31 - {  
32 - if (features.isEmpty()) {  
33 - int dx, dy;  
34 - Size size = windowSize(&dx,&dy);  
35 -  
36 - int width = size.width+dx, height = size.height+dy;  
37 -  
38 - // Enumerate all possible rectangles  
39 - for (int x=0; x<width; x++)  
40 - for (int y=0; y<height; y++)  
41 - for (int w=1; w < width-x; w++)  
42 - for (int h=1; h < height-y; h++)  
43 - if (!squareOnly || w == h)  
44 - features.append(Rect(x,y,w,h));  
45 - }  
46 -  
47 - qDebug() << "Number of Gradient Histogram features:" << features.size();  
48 - }  
49 -  
50 - void preprocess(const Mat &src, Mat &dst) const  
51 - {  
52 - // Compute as is done in GradientTransform  
53 - Mat dx, dy, magnitude, angle;  
54 - Sobel(src, dx, CV_32F, 1, 0, CV_SCHARR);  
55 - Sobel(src, dy, CV_32F, 0, 1, CV_SCHARR);  
56 - cartToPolar(dx, dy, magnitude, angle, true);  
57 -  
58 - const double floor = ((src.depth() == CV_32F) || (src.depth() == CV_64F)) ? -0.5 : 0;  
59 -  
60 - Mat histogram;  
61 - angle.convertTo(histogram, bins > 256 ? CV_16U : CV_8U, bins/360., floor);  
62 -  
63 - // Mask and compute integral image  
64 - std::vector<Mat> outputs;  
65 - for (int i=0; i<bins; i++) {  
66 - Mat output = (histogram == i)/255;  
67 - Mat integralImg;  
68 - integral(output, integralImg);  
69 - outputs.push_back(integralImg);  
70 - }  
71 -  
72 - merge(outputs,dst);  
73 - }  
74 -  
75 - /* ___ ___  
76 - * | | |  
77 - * | A | B |  
78 - * |___|___|  
79 - * | | |  
80 - * | C | D |  
81 - * |___|___|  
82 - *  
83 - * 1, 2, 3 and 4 refer to the lower right corners of A, B, C, and D, respectively.  
84 - * Rectangle D can be computed as 4 + 1 - (2 + 3)  
85 - */  
86 -  
87 - float evaluate(const Mat &image, int idx) const  
88 - {  
89 - // To which channel does idx belong?  
90 - const int index = idx % features.size();  
91 - const int channel = idx / features.size();  
92 -  
93 - int dx, dy;  
94 - Size size = windowSize(&dx, &dy);  
95 -  
96 - const int *ptr = image.ptr<int>();  
97 -  
98 - int four = ptr[((features[index].y+features[index].height)*(size.height+dy)+(features[index].x+features[index].width))*bins+channel];  
99 - int one = ptr[(features[index].y*(size.height+dy)+features[index].x)*bins+channel];  
100 - int two = ptr[(features[index].y*(size.height+dy)+(features[index].x+features[index].width))*bins+channel];  
101 - int three = ptr[((features[index].y+features[index].height)*(size.height+dy)+features[index].x)*bins+channel];  
102 -  
103 - return four + one - (two + three);  
104 - }  
105 -  
106 - Mat evaluate(const Mat &image, const QList<int> &indices) const  
107 - {  
108 - int size = indices.empty() ? numFeatures() : indices.size();  
109 -  
110 - Mat result(1, size, CV_32FC1);  
111 - for (int i = 0; i < size; i++)  
112 - result.at<float>(i) = evaluate(image, indices.empty() ? i : indices[i]);  
113 -  
114 - return result;  
115 - }  
116 -  
117 - int numFeatures() const  
118 - {  
119 - return features.size()*bins;  
120 - }  
121 -  
122 - int numChannels() const  
123 - {  
124 - return bins;  
125 - }  
126 -  
127 - Size windowSize(int *dx, int *dy) const  
128 - {  
129 - if (dx && dy)  
130 - *dx = *dy = 1;  
131 - return Size(winWidth, winHeight);  
132 - }  
133 -  
134 - int maxCatCount() const { return 0; }  
135 -  
136 - QList<Rect> features;  
137 -};  
138 -  
139 -BR_REGISTER(Representation, GradientHistogramRepresentation)  
140 -  
141 -} // namespace br  
142 -  
143 -#include "representation/gradienthistogram.moc"  
144 -  
145 -