-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
68 lines (52 loc) · 1.44 KB
/
main.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
66
67
/*
* File: main.cpp
* Author: spork
*/
#include "main.h"
#include "BrightnessControl.h"
#include <cstdlib>
int width, height;
cv::VideoCapture imgcapture;
cv::Mat srcimg;
BrightnessControl bc;
int setupWebcam() {
width = 320;
height = 240;
imgcapture.open(-1);
if (!imgcapture.isOpened()) {
std::cerr << "No imaging device!" << std::endl;
return -1;
}
imgcapture.set(CV_CAP_PROP_FRAME_WIDTH, width);
imgcapture.set(CV_CAP_PROP_FRAME_HEIGHT, height);
}
/*
*
*/
int main(int argc, char** argv) {
cvInitSystem(argc, argv);
setupWebcam();
if(!bc.setupBrightnessControl()) return 1;
cv::namedWindow("Output", CV_WINDOW_AUTOSIZE); // debug
while(true) {
// get image from webcam
imgcapture.grab();
imgcapture.retrieve(srcimg);
if (srcimg.empty()) {
std::cerr << "Problem getting an image from source" << std::endl;
return -1;
}
// convert to grayscale; that's all we really need
cv::Mat gray;
cv::cvtColor(srcimg, gray, CV_BGR2GRAY);
int level = bc.getBrightnessFromImage(gray);
bc.setBrightness(level);
// debug: display image
cv::imshow("Output", gray);
if(cvWaitKey(100) >= 0) break;
// only need to run once every two seconds
sleep(2);
}
cvDestroyWindow("Output");
return 0;
}