-
Notifications
You must be signed in to change notification settings - Fork 9
/
mainwindow.cpp
62 lines (45 loc) · 1.4 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
timer = new QTimer(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_open_webcam_clicked()
{
cap.open(0);
if(!cap.isOpened()) // Check if we succeeded
{
cout << "camera is not open" << endl;
}
else
{
cout << "camera is open" << endl;
connect(timer, SIGNAL(timeout()), this, SLOT(update_window()));
timer->start(20);
}
}
void MainWindow::on_pushButton_close_webcam_clicked()
{
disconnect(timer, SIGNAL(timeout()), this, SLOT(update_window()));
cap.release();
Mat image = Mat::zeros(frame.size(),CV_8UC3);
qt_image = QImage((const unsigned char*) (image.data), image.cols, image.rows, QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(qt_image));
ui->label->resize(ui->label->pixmap()->size());
cout << "camera is closed" << endl;
}
void MainWindow::update_window()
{
cap >> frame;
cvtColor(frame, frame, CV_BGR2RGB);
qt_image = QImage((const unsigned char*) (frame.data), frame.cols, frame.rows, QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(qt_image));
ui->label->resize(ui->label->pixmap()->size());
}