-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcameracapture.cpp
More file actions
82 lines (61 loc) · 1.7 KB
/
cameracapture.cpp
File metadata and controls
82 lines (61 loc) · 1.7 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
#include "cameracapture.h"
CameraCapture::CameraCapture(QObject *parent)
: QObject(parent)
{
connect(&timer, &QTimer::timeout, this, &CameraCapture::processFrame);
timer.setInterval(30);
openCamera();
}
CameraCapture::~CameraCapture()
{
closeCamera();
}
bool CameraCapture::openCamera()
{
cameraId = 0;
frameWidth = 1280;
frameHeight = 720;
capture.open(cameraId, cv::CAP_V4L2);
if (!capture.isOpened())
{
return false;
}
capture.set(cv::CAP_PROP_FRAME_WIDTH, frameWidth);
capture.set(cv::CAP_PROP_FRAME_HEIGHT, frameHeight);
timer.start();
return true;
}
void CameraCapture::closeCamera()
{
capture.release();
timer.stop();
}
void CameraCapture::processFrame()
{
cv::Mat frame;
capture.read(frame);
cv::Mat resizedImage;
cv::resize(frame, resizedImage, cv::Size(), 1, 1);
cv::cvtColor(resizedImage, frame, cv::COLOR_BGR2RGB);
//frame = resizedImage;
if (frame.empty()) {
std::cerr << "Aucune image capturée" << std::endl;
}
else
{
QImage image(frame.data,
frame.cols,
frame.rows,
frame.step,
QImage::Format_RGB888);
QImage logo = QImage("/usr/bin/matrixresources/icons/MatrixLogo.png");
QImage resizedLogo = logo.scaled(image.width(), image.height(), Qt::KeepAspectRatio);
QPainter painter(&image);
int x = (image.width() - resizedLogo.width()) / 2;
int y = 0;
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(x, y, resizedLogo);
painter.end();
emit frameCaptured(image);
}
}