-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
81 lines (65 loc) · 1.88 KB
/
test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <linux/videodev2.h>
#include <sys/ioctl.h>
#include "detect_methods.h"
#include "v4l2_con.h"
using namespace cv;
using namespace std;
int fd;
int xioctl(int fd, int request, void *arg){
int r;
do r = ioctl (fd, request, arg);
while (-1 == r && EINTR == errno);
return r;
}
bool setExposureTime(bool auto_exp, int t){
if (auto_exp){
struct v4l2_control control_s;
control_s.id = V4L2_CID_EXPOSURE_AUTO;
control_s.value = V4L2_EXPOSURE_AUTO;
if( xioctl(fd, VIDIOC_S_CTRL, &control_s) < 0){
cout << "Set Auto Exposure error\n" << endl;
return false;
}
}
else {
struct v4l2_control control_s;
control_s.id = V4L2_CID_EXPOSURE_AUTO;
control_s.value = V4L2_EXPOSURE_MANUAL;
if( xioctl(fd, VIDIOC_S_CTRL, &control_s) < 0){
cout << "Close MANUAL Exposure error\n" << endl;
return false;
}
control_s.id = V4L2_CID_EXPOSURE_ABSOLUTE;
control_s.value = t;
if( xioctl(fd, VIDIOC_S_CTRL, &control_s) < 0){
cout << "Set Exposure Time error\n" << endl;
return false;
}
}
return true;
}
int main1()
{
V4L2_con mycam;
mycam.v4l2_set_exposure("/dev/ch_video1", 30);
mycam.v4l2_set_saturation("/dev/ch_video1",60);
mycam.v4l2_set_brightness("/dev/ch_video1", 40);
VideoCapture capture("/dev/ch_video1");
capture.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,720);
methods cam;
while (true)
{
Mat frame;
capture >> frame;
cam.set_img(frame);
// dst = cam.draw(dst);
imshow("src", frame);
if(char(waitKey(30)) == 'q') break;
}
capture.release();
}