-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
112 lines (87 loc) · 2.63 KB
/
mainwindow.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "mainwindow.h"
#include "ui_mainwindow.h"
using namespace cv;
static VideoCapture camera(0);
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui -> setupUi(this);
if (!camera.isOpened())
{
qDebug() << "Cannot access the camera.\nProgram will not close down.";
exit(EXIT_FAILURE);
}
// User defined functionality //
projectSettings.loadSettings();
Algorithms::sayHello();
// End
if (FPS == 60)
{
camera.set(cv::CAP_PROP_FRAME_WIDTH, 640);
camera.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
}
else if (FPS == 30)
{
camera.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
camera.set(cv::CAP_PROP_FRAME_HEIGHT, 720);
}
camera.set(cv::CAP_PROP_AUTOFOCUS, 1);
camera.set(cv::CAP_PROP_FOURCC, CV_FOURCC('M','J','P','G'));
camera.set(cv::CAP_PROP_FPS, FPS);
// Setting up the C922 to 1080p @ 30FPS.
// camera.open(CV_CAP_DSHOW);
// camera.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
// camera.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
// camera.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
// End
connect(&videoFPSTimer, SIGNAL(timeout()), this, SLOT(captureImage()));
videoFPSTimer.start(1000 / FPS);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::captureImage()
{
camera >> currentFrameMat;
currentFramePixmap = MatToQPixmap( currentFrameMat );
ui -> videoFeed -> setPixmap(currentFramePixmap);
int getFPS = (int)camera.get(CAP_PROP_FPS);
ui -> fpsLabel -> setText( QString::number(getFPS) );
}
void MainWindow::on_contrastSpinBox_valueChanged(int arg1)
{
camera.set(cv::CAP_PROP_CONTRAST, arg1);
}
void MainWindow::on_brightnesspinBox_valueChanged(int arg1)
{
camera.set(cv::CAP_PROP_BRIGHTNESS, arg1);
}
void MainWindow::on_saturationSpinBox_valueChanged(int arg1)
{
camera.set(cv::CAP_PROP_SATURATION, arg1);
}
void MainWindow::on_focusButton_pressed()
{
if (ui -> focusButton -> text() == "Focus: Auto")
{
camera.set(cv::CAP_PROP_AUTOFOCUS, 0);
ui -> focusButton -> setText("Focus: Manual");
ui -> focusLabel -> setEnabled(true);
ui -> focusSpinBox -> setEnabled(true);
}
else
{
camera.set(cv::CAP_PROP_AUTOFOCUS, 1);
ui -> focusButton -> setText("Focus: Auto");
ui -> focusLabel -> setEnabled(false);
ui -> focusSpinBox -> setEnabled(false);
}
}
void MainWindow::on_focusSpinBox_valueChanged(int arg1)
{
camera.set(cv::CAP_PROP_FOCUS, arg1);
}
void MainWindow::on_zoomSpinBox_valueChanged(int arg1)
{
camera.set(cv::CAP_PROP_ZOOM, arg1 + 100);
}