summaryrefslogtreecommitdiffhomepage
path: root/cv/video-widget.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-01-12 19:40:22 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-01-12 19:40:22 +0100
commit537a88e522314753149e1ea7921489e58043b40c (patch)
treea62ac59a546c8b0ee8adeee3bd2aa255d7e4570e /cv/video-widget.cpp
parent11d8e48e4370c9201f8258b418aadc7a4290dba1 (diff)
tracker/pt: isolate point extractor and image type
Issue: #718
Diffstat (limited to 'cv/video-widget.cpp')
-rw-r--r--cv/video-widget.cpp54
1 files changed, 37 insertions, 17 deletions
diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp
index bad81905..4c9a73e6 100644
--- a/cv/video-widget.cpp
+++ b/cv/video-widget.cpp
@@ -9,11 +9,13 @@
#include "video-widget.hpp"
#include "compat/check-visible.hpp"
+#include "compat/util.hpp"
+
+#include <cstring>
+
#include <opencv2/imgproc.hpp>
-cv_video_widget::cv_video_widget(QWidget* parent) : QWidget(parent),
- mtx(QMutex::Recursive),
- freshp(false)
+cv_video_widget::cv_video_widget(QWidget* parent) : QWidget(parent)
{
connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint()), Qt::DirectConnection);
timer.start(65);
@@ -25,9 +27,7 @@ void cv_video_widget::update_image(const cv::Mat& frame)
if (!freshp)
{
- const int w = preview_size.width(), h = preview_size.height();
-
- if (w < 1 || h < 1)
+ if (width < 1 || height < 1)
return;
if (_frame.cols != frame.cols || _frame.rows != frame.rows)
@@ -38,28 +38,50 @@ void cv_video_widget::update_image(const cv::Mat& frame)
if (_frame2.cols != _frame.cols || _frame2.rows != _frame.rows)
_frame2 = cv::Mat(_frame.rows, _frame.cols, CV_8UC4);
- if (_frame3.cols != w || _frame3.rows != h)
- _frame3 = cv::Mat(h, w, CV_8UC4);
+ if (_frame3.cols != width || _frame3.rows != height)
+ _frame3 = cv::Mat(height, width, CV_8UC4);
cv::cvtColor(_frame, _frame2, cv::COLOR_BGR2BGRA);
- const cv::Mat* img_;
+ const cv::Mat* img;
- if (_frame.cols != w || _frame.rows != h)
+ if (_frame.cols != width || _frame.rows != height)
{
- cv::resize(_frame2, _frame3, cv::Size(w, h), 0, 0, cv::INTER_NEAREST);
+ cv::resize(_frame2, _frame3, cv::Size(width, height), 0, 0, cv::INTER_NEAREST);
- img_ = &_frame3;
+ img = &_frame3;
}
else
- img_ = &_frame2;
+ img = &_frame2;
+
+ const unsigned nbytes = 4 * img->rows * img->cols;
+
+ vec.resize(nbytes);
- const cv::Mat& img = *img_;
+ std::memcpy(vec.data(), img->data, nbytes);
- texture = QImage((const unsigned char*) img.data, w, h, QImage::Format_ARGB32);
+ texture = QImage((const unsigned char*) vec.data(), width, height, QImage::Format_ARGB32);
}
}
+void cv_video_widget::update_image(const QImage& img)
+{
+ QMutexLocker l(&mtx);
+
+ if (freshp)
+ return;
+
+ const unsigned nbytes = img.sizeInBytes();
+
+ vec.resize(nbytes);
+
+ std::memcpy(vec.data(), img.constBits(), nbytes);
+
+ texture = QImage((const unsigned char*) vec.data(), img.width(), img.height(), img.format());
+
+ freshp = true;
+}
+
void cv_video_widget::paintEvent(QPaintEvent*)
{
QMutexLocker foo(&mtx);
@@ -74,8 +96,6 @@ void cv_video_widget::update_and_repaint()
QMutexLocker l(&mtx);
- preview_size = size();
-
if (freshp)
{
freshp = false;