-
Notifications
You must be signed in to change notification settings - Fork 1
/
CaptureDevice.cpp
75 lines (57 loc) · 2.22 KB
/
CaptureDevice.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
#include <QMessageBox>
#include <QString>
#include <QDebug>
#include <QDateTime>
#include "CaptureDevice.h"
CaptureDevice::CaptureDevice()
{
deviceFileName="default";
brigthnessThreshold=50;
}
// Инициализация устройства видеозахвата
void CaptureDevice::init(const QString iDeviceFileName)
{
qDebug() << "Start capture device init time: "<< QDateTime::currentDateTime();
deviceFileName=iDeviceFileName;
if(iDeviceFileName=="default") {
videoCaptureFlow.open(0); // Default камера
if(!videoCaptureFlow.isOpened()) {
QMessageBox msgBox;
msgBox.setText("Can't open default camera");
msgBox.exec();
return;
}
} else {
videoCaptureFlow.open( iDeviceFileName.toLocal8Bit().constData() ); // Камера на указанном файле устройства
if(!videoCaptureFlow.isOpened()) {
QMessageBox msgBox;
msgBox.setText("Can't open camera device file: "+deviceFileName);
msgBox.exec();
return;
}
}
qDebug() << "Finish capture device init time: "<< QDateTime::currentDateTime();
}
void CaptureDevice::setBrigthnessThreshold(const int iBrigthnessThreshold)
{
brigthnessThreshold=iBrigthnessThreshold;
}
QSize CaptureDevice::getFrameSize(void)
{
return QSize(videoCaptureFlow.get(CV_CAP_PROP_FRAME_WIDTH), videoCaptureFlow.get(CV_CAP_PROP_FRAME_HEIGHT));
}
cv::Mat* CaptureDevice::getBwFrame(void)
{
// Из потока берется один кадр
videoCaptureFlow >> currentFrame;
if (currentFrame.empty())
return nullptr;
double thresholdLevel=(double) brigthnessThreshold;
// Преобразование в Ч/Б и превращение в контрастное изображение с порогом brigthnessThreshold
cv::cvtColor(currentFrame, currentBwFrame, CV_BGR2GRAY);
cv::GaussianBlur(currentBwFrame, currentBwFrame, cv::Size(7,7), 1.5, 1.5);
cv::threshold(currentBwFrame, currentBwFrame, thresholdLevel, 254.0, cv::THRESH_BINARY);
cv::flip(currentBwFrame, currentBwFrame, 1);
// cv::imshow("Source frame", currentBwFrame);
return ¤tBwFrame;
}