-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvideostreamer.cpp
More file actions
52 lines (42 loc) · 1.01 KB
/
videostreamer.cpp
File metadata and controls
52 lines (42 loc) · 1.01 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
#include "videostreamer.h"
#include <QDebug>
VideoStreamer::VideoStreamer()
{
connect(&tUpdate, &QTimer::timeout, this, &VideoStreamer::streamVideo);
}
VideoStreamer::~VideoStreamer()
{
cap.release();
tUpdate.stop();
}
void VideoStreamer::streamVideo()
{
cap >> frame;
if (frame.empty()) {
qWarning() << "Empty frame!";
return;
}
QImage img(frame.data, frame.cols, frame.rows, QImage::Format_RGB888);
img = img.rgbSwapped();
emit newImage(img);
}
void VideoStreamer::openVideoCamera(QString path)
{
if (path.isEmpty()) {
cap.open(0, cv::CAP_V4L2);
}
else if (path.length() == 1) {
cap.open(path.toInt(), cv::CAP_V4L2);
}
else {
cap.open(path.toStdString());
}
if (!cap.isOpened()) {
qWarning() << "Gagal membuka kamera/video!";
return;
}
double fps = cap.get(cv::CAP_PROP_FPS);
if (fps <= 0) fps = 30;
tUpdate.start(1000 / fps);
qDebug() << "Video camera opened with FPS:" << fps;
}