-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
63 lines (55 loc) · 1.53 KB
/
mainwindow.cpp
File metadata and controls
63 lines (55 loc) · 1.53 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cap = new cv::VideoCapture(CV_CAP_ANY);
if(!cap->isOpened())
{
QMessageBox msgbox;
msgbox.setWindowTitle(tr("error"));
msgbox.setText(tr("can't open camera device"));
msgbox.exec();
}
timer = new QTimer();
timer->setInterval(30);
timer->start();
imgprocQt = new ImgProcQt(this);
connect(timer, SIGNAL(timeout()), this, SLOT(VideoUpdate()));
}
void MainWindow::resizeEvent(QResizeEvent *resizeEvent)
{
QMainWindow::resizeEvent(resizeEvent);
}
void MainWindow::VideoUpdate()
{
if(cap->isOpened())
{
cv::Mat capImg;
cap->retrieve(capImg);
if(ui->ModeNormal->isChecked())
imgprocQt->detectCard(capImg);
else if(ui->ModeGray->isChecked())
imgprocQt->cvCvtRGB2GRAY(capImg);
else if(ui->ModeCanny->isChecked())
imgprocQt->cvCanny(capImg,100,200);//FIX
PreviewUpdate(capImg);
}
}
void MainWindow::PreviewUpdate(cv::Mat& bgrImg) const
{
cv::Mat rgbImg;
cv::cvtColor(bgrImg, rgbImg, CV_BGR2RGB);
QImage qimg(rgbImg.data, rgbImg.cols, rgbImg.rows, QImage::Format_RGB888);
QPixmap pixmap = QPixmap::fromImage(qimg);
ui->Preview->setPixmap(pixmap);
// preview—Ěć‚ĚŠTCY
ui->Preview->setGeometry(0,0,pixmap.width(),pixmap.height());
}
MainWindow::~MainWindow()
{
cap->release();
delete ui;
}