1 #ifndef _IMAGE_PREVIEW_HEADER_
2 #define _IMAGE_PREVIEW_HEADER_
6 #pragma warning(disable:4996 4251 4244 4275 4800)
8 #include <QGraphicsView>
9 #include <QResizeEvent>
21 #include <QPainterPath>
22 #include <QBasicTimer>
24 #include <opencv2/core.hpp>
25 #include <opencv2/imgproc.hpp>
28 #include "Convertor.h"
40 static void matDeleter(
void* mat) {
delete static_cast<cv::Mat*
>(mat); }
41 void queue(
const cv::Mat & frame) {
43 if (!_timer.isActive()) _timer.start(0,
this);
45 void process(cv::Mat frame) {
50 frame = MatrixConvertor::convert(frame, CV_8UC3);
52 cv::cvtColor(frame, frame, cv::COLOR_BGR2RGB);
53 const QImage image(frame.data, frame.cols, frame.rows, frame.step,
54 QImage::Format_RGB888, &matDeleter,
new cv::Mat(frame));
55 emit imageReady(image);
59 void timerEvent(QTimerEvent * ev) {
60 if (ev->timerId() == _timer.timerId())
68 explicit Converter(QObject * parent = 0) : QObject(parent), _processAll(
false) {}
69 void setProcessAll(
bool all) { _processAll = all; }
70 Q_SIGNAL
void imageReady(
const QImage &);
71 void processFrame(
const cv::Mat & frame) {
72 if (_processAll) process(frame);
else queue(frame);
80 void paintEvent(QPaintEvent *) {
82 p.drawImage(QRect(0, 0, width(), height()), _img, QRect(0, 0, _img.width(), _img.height()));
85 ImageViewer(QWidget * parent = 0) : QWidget(parent) {
86 setAttribute(Qt::WA_OpaquePaintEvent);
88 connect(_converter, SIGNAL(imageReady(QImage)), SLOT(setImage(QImage)));
91 void setImage(cv::Mat img)
93 _converter->processFrame(img);
96 Q_SLOT
void setImage(
const QImage & img) {
100 Q_SIGNAL
void matReady(cv::Mat);
103 virtual void mouseMoveEvent(QMouseEvent *event);
105 virtual void enterEvent(QEvent *event);
106 virtual void leaveEvent(QEvent *event);
Definition: ImagePreview.h:76
Definition: ImagePreview.h:35