forked from spmallick/learnopencv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
64 lines (48 loc) · 1.06 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QDebug>
#define CAM_ID 0
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer* timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateView()));
timer->start(30);
ui->camViewer->setScene(&scene);
}
MainWindow::~MainWindow()
{
delete ui;
if(video.isOpened())
{
video.release();
}
}
void MainWindow::on_pushButton_clicked()
{
if(video.isOpened())
{
video.release();
ui->pushButton->setText("Start");
}
else
{
video.open(CAM_ID);
ui->pushButton->setText("Stop");
}
}
void MainWindow::updateView()
{
if(!video.isOpened()) return;
cv::Mat frame;
while(1)
{
video >> frame;
if(!frame.empty()) break;
}
if(frame.empty()) return;
ui->camViewer->setImage(QImage((const unsigned char*)(frame.data), frame.cols,frame.rows,QImage::Format_RGB888).rgbSwapped());
}