1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| /*
Compares the HSV histograms of two images, a and b.
Return the norm between
*/
double compare_histograms(Mat a, Mat b) {
MatND hista, histb;
Mat a_hsv, b_hsv;
//args to calculate the histogram
int channels[] = {0, 1};
//180 bins for hue and 256 bins to saturation
int histsize[] = {180, 256};
//distribution uniform by the bins
float hrange[] = {0, 180};
float srange[] = {0, 256};
const float * ranges[] = {hrange,srange};
//Convert images to HSV from BGR
cvtColor(a, a_hsv, CV_BGR2HSV);
cvtColor(b, b_hsv, CV_BGR2HSV);
//Calculates the histogram of the two images
calcHist(&a, 1, channels, Mat(), hista, 2, histsize, ranges);
calcHist(&b, 1, channels, Mat(), histb, 2, histsize, ranges);
//Return the norm
return norm(hista, histb);
}
|