forked from donghoonpark/ISIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoFrame.cpp
executable file
·56 lines (45 loc) · 1.41 KB
/
videoFrame.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
#include "videoFrame.h"
#include <QApplication>
#include <QPainter>
#include <QMessageBox>
#include "misc.h"
const int CAMERA_INDEX = 0;
const int VIDEO_PERIOD = 33;
const int VIDEO_START_DELAY = 1000;
VideoFrame::VideoFrame(QWidget *parent) : QFrame(parent),
mVideoTimer(this),
mVideo(CAMERA_INDEX),
mUpdate(true) {
mVideo.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
mVideo.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
connect(&mVideoTimer, SIGNAL(timeout()), this, SLOT(update()));
connect(&mVideoTimer, SIGNAL(timeout()), this, SLOT(loadFrame()));
QTimer::singleShot(VIDEO_START_DELAY, this, SLOT(startVieo()));
}
VideoFrame::~VideoFrame() {
mVideoTimer.stop();
}
const cv::Mat& VideoFrame::curFrame() {
return this->mCurFrame;
}
void VideoFrame::setResult(const cv::Mat& input) {
this->mResult = input.clone();
}
void VideoFrame::setUpdate(bool input) {
this->mUpdate = input;
}
void VideoFrame::startVieo() {
mVideoTimer.start(VIDEO_PERIOD);
}
void VideoFrame::loadFrame() {
if (this->mUpdate && !mVideo.read(this->mCurFrame)) {
QMessageBox::critical(this, "Video error", "Failed to load image from camera!");
QApplication::quit();
}
}
void VideoFrame::paintEvent(QPaintEvent* event) {
QPainter painter(this);
QImage imgQt = Mat2QImage(mResult);
painter.drawImage(QRect(0, 0, this->width(), this->height()), imgQt);
painter.end();
}