summaryrefslogtreecommitdiffhomepage
path: root/cv
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-02-21 20:39:43 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-02-21 20:39:43 +0100
commit946252efabf79792aac655914276aab3fad36ef2 (patch)
tree1471b4a48f9f4f15eded8b20f71b965cac5bce78 /cv
parentd90d57a85d81bc16e14310e41c820f47e110e484 (diff)
cv/video-widget: fix logic error
Also try not to poke size() outside UI thread.
Diffstat (limited to 'cv')
-rw-r--r--cv/video-widget.cpp25
-rw-r--r--cv/video-widget.hpp2
2 files changed, 22 insertions, 5 deletions
diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp
index f45830b8..ce3f3b47 100644
--- a/cv/video-widget.cpp
+++ b/cv/video-widget.cpp
@@ -31,14 +31,27 @@ 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_8UC3);
- if (_frame3.cols != width() || _frame3.rows != height())
- _frame3 = cv::Mat(height(), width(), CV_8UC3);
+ const int w = preview_size.width(), h = preview_size.height();
+
+ if (_frame3.cols != w || _frame3.rows != h)
+ _frame3 = cv::Mat(h, w, CV_8UC3);
cv::cvtColor(_frame, _frame2, cv::COLOR_RGB2BGR);
- if (_frame.cols != width() || _frame.rows || height())
- cv::resize(_frame2, _frame3, cv::Size(width(), height()), 0, 0, cv::INTER_NEAREST);
- texture = QImage((const unsigned char*) _frame3.data, _frame3.cols, _frame3.rows, QImage::Format_RGB888);
+ const cv::Mat* img_;
+
+ if (_frame.cols != w || _frame.rows != h)
+ {
+ cv::resize(_frame2, _frame3, cv::Size(w, h), 0, 0, cv::INTER_NEAREST);
+
+ img_ = &_frame3;
+ }
+ else
+ img_ = &_frame2;
+
+ const cv::Mat& img = *img_;
+
+ texture = QImage((const unsigned char*) img.data, img.cols, img.rows, QImage::Format_RGB888);
}
}
@@ -53,6 +66,8 @@ void cv_video_widget::update_and_repaint()
{
QMutexLocker l(&mtx);
+ preview_size = size();
+
if (freshp)
{
freshp = false;
diff --git a/cv/video-widget.hpp b/cv/video-widget.hpp
index 3e328977..3b29ffc6 100644
--- a/cv/video-widget.hpp
+++ b/cv/video-widget.hpp
@@ -17,6 +17,7 @@
#include <QTimer>
#include <QMutex>
#include <QMutexLocker>
+#include <QSize>
#include <QDebug>
class cv_video_widget final : public QWidget
@@ -32,6 +33,7 @@ private:
QMutex mtx;
QImage texture;
QTimer timer;
+ QSize preview_size;
cv::Mat _frame, _frame2, _frame3;
bool freshp;
};