-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCameraController.h
More file actions
83 lines (66 loc) · 1.82 KB
/
CameraController.h
File metadata and controls
83 lines (66 loc) · 1.82 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include <stdint.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include "Logging.h"
#include "MathUtils.h"
#include "TrapezoidSampler.h"
#include "HardwareConfig.h"
#include <boost/timer/timer.hpp>
using boost::timer::cpu_timer;
// todo: ability to disconnect and reconnect camera
class CameraController
{
public:
static CameraController* Instance;
CameraController()
: m_capture(0), m_frame(0)
{
m_capture = cvCaptureFromCAM(CV_CAP_ANY);
cvSetCaptureProperty(m_capture, CV_CAP_PROP_FPS, CAM_CAPTURE_FPS);
cvSetCaptureProperty(m_capture, CV_CAP_PROP_FRAME_WIDTH, CAM_CAPTURE_SIZE_WIDTH);
cvSetCaptureProperty(m_capture, CV_CAP_PROP_FRAME_HEIGHT, CAM_CAPTURE_SIZE_HEIGHT);
Instance = this;
}
~CameraController()
{
cvReleaseCapture(&m_capture);
}
void CaptureFrame()
{
if (m_capture == 0)
return;
m_frame = cvQueryFrame(m_capture);
if (!m_frame)
return;
}
const IplImage* Frame()
{
return m_frame;
}
void UpdateSettings(uint8_t saturation, uint8_t brightness, uint8_t contrast, uint8_t gain)
{
if (m_capture == 0)
return;
double cvSaturation = (double)saturation;
double cvBrightness = (double)brightness;
double cvContrast = (double)contrast;
double cvGain = (double)gain;
// Gotcha! Raspberry pi expects values between 0 and 1
#if RASPBERRY_PI
cvSaturation /= 255;
cvBrightness /= 255;
cvContrast /= 255;
cvGain /= 255;
#endif
cvSetCaptureProperty(m_capture, CV_CAP_PROP_SATURATION, cvSaturation);
cvSetCaptureProperty(m_capture, CV_CAP_PROP_BRIGHTNESS, cvBrightness);
cvSetCaptureProperty(m_capture, CV_CAP_PROP_CONTRAST, cvContrast);
cvSetCaptureProperty(m_capture, CV_CAP_PROP_GAIN, cvGain);
// exposure doesn't work for me
//cvSetCaptureProperty(m_capture, CV_CAP_PROP_EXPOSURE, -4);
}
private:
CvCapture* m_capture;
IplImage* m_frame;
};