-
Notifications
You must be signed in to change notification settings - Fork 0
/
equalize.cpp
65 lines (50 loc) · 1.6 KB
/
equalize.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv){
Mat image, cinza, saida, histG, histE;
VideoCapture cap;
int nbins = 64;
float range[] = {0, 256};
const float *histrange = { range };
bool uniform = true;
bool acummulate = false;
int histw = nbins, histh = nbins/2;
Mat histGimg(histh, histw, CV_BGR2GRAY, Scalar(0));
Mat histEimg(histh, histw, CV_BGR2GRAY, Scalar(0));
cap.open(0);
if(!cap.isOpened()){
cout << "Erro ao abrir camera.";
return -1;
}
while(1){
//captura a imagem
cap >> image;
//transforma para escala de cinza
cvtColor( image, cinza, CV_BGR2GRAY );
//equaliza o histograma
equalizeHist( cinza, saida );
calcHist(&cinza, 1, 0, Mat(), histG, 1, &nbins, &histrange, uniform, acummulate);
calcHist(&saida, 1, 0, Mat(), histE, 1, &nbins, &histrange, uniform, acummulate);
normalize(histG, histG, 0, histGimg.rows, NORM_MINMAX, -1, Mat());
normalize(histE, histE, 0, histEimg.rows, NORM_MINMAX, -1, Mat());
histGimg.setTo(Scalar(0));
histEimg.setTo(Scalar(0));
for(int i=0; i<nbins; i++){
line(histGimg,
Point(i, histh),
Point(i, histh-cvRound(histG.at<float>(i))),
Scalar(255), 1, 8, 0);
line(histEimg,
Point(i, histh),
Point(i, histh-cvRound(histE.at<float>(i))),
Scalar(255), 1, 8, 0);
}
histGimg.copyTo(cinza(Rect(0, 0,nbins, histh)));
histEimg.copyTo(saida(Rect(0, 0,nbins, histh)));
imshow("saida", saida);
imshow("cinza", cinza);
}
return 0;
}