-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera_feed.cpp
136 lines (107 loc) · 3.62 KB
/
camera_feed.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//#include "camera_feed.h"
//#include "ui_camera_feed.h"
//camera_feed::camera_feed(QWidget *parent) :
// QMainWindow(parent),
// ui(new Ui::camera_feed)
//{
// ui->setupUi(this);
// for (const QCameraInfo &info : QCameraInfo::availableCameras())
// {
// qDebug() << "Camera description: " << info.description();
// }
// M_camera.reset(new QCamera(QCameraInfo::defaultCamera()));
// if (!M_camera->isAvailable())
// {
// qDebug() << "Camera is not available!";
// }
// //M_camera.reset(new QCamera(QCameraInfo::defaultCamera()));
// M_camera->setViewfinder(ui->camera_feed_2);
//}
//camera_feed::~camera_feed()
//{
// delete ui;
//}
//void camera_feed::startcam()
//{
// M_camera->start();
//}
//void camera_feed::on_start_clicked()
//{
// startcam();
//}
#include "camera_feed.h"
#include "ui_camera_feed.h"
camera_feed::camera_feed(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::camera_feed)
{
ui->setupUi(this);
for (const QCameraInfo &info : QCameraInfo::availableCameras())
{
qDebug() << "Camera description: " << info.description();
}
M_camera.reset(new QCamera(QCameraInfo::defaultCamera()));
if (!M_camera->isAvailable())
{
qDebug() << "Camera is not available!";
}
//M_camera.reset(new QCamera(QCameraInfo::defaultCamera()));
M_camera->setViewfinder(ui->camera_feed_2);
// Create a new instance of QCameraImageCapture
M_imageCapture.reset(new QCameraImageCapture(M_camera.get()));
// Connect the imageCaptured signal to the slot that will handle the captured image
connect(M_imageCapture.get(), &QCameraImageCapture::imageCaptured, this, &camera_feed::handleImageCapture);
// Connect the error signal to the slot that will handle errors
connect(M_imageCapture.get(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error), this, &camera_feed::handleError);
// Connect the imageAvailable signal to the slot that will handle the available image
connect(M_imageCapture.get(), &QCameraImageCapture::imageAvailable, this, &camera_feed::handleImageAvailable);
// Connect the readyForCaptureChanged signal to the slot that will handle the change in readiness
connect(M_imageCapture.get(), &QCameraImageCapture::readyForCaptureChanged, this, &camera_feed::handleReadyForCaptureChanged);
// Connect the imageExposed signal to the slot that will handle the exposed image
connect(M_imageCapture.get(), &QCameraImageCapture::imageExposed, this, &camera_feed::handleImageExposed);
// Connect the capture destination to the image capture buffer
M_imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
// Start the camera
M_camera->start();
}
camera_feed::~camera_feed()
{
delete ui;
}
void camera_feed::startcam()
{
M_camera->start();
}
void camera_feed::on_start_clicked()
{
startcam();
}
void camera_feed::handleImageCapture(int id, const QImage &preview)
{
Q_UNUSED(id);
Q_UNUSED(preview);
qDebug() << "Image captured";
}
void camera_feed::handleError(int id, QCameraImageCapture::Error error, const QString &errorString)
{
Q_UNUSED(id);
Q_UNUSED(error);
Q_UNUSED(errorString);
qDebug() << "Error occurred";
}
void camera_feed::handleImageAvailable(int id, const QVideoFrame &frame)
{
Q_UNUSED(id);
Q_UNUSED(frame);
qDebug() << "Image available";
}
void camera_feed::handleReadyForCaptureChanged(bool ready)
{
Q_UNUSED(ready);
qDebug() << "Ready for capture changed";
}
void camera_feed::handleImageExposed(int id)
{
Q_UNUSED(id);
qDebug() << "Image exposed";
}