diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-02-21 20:39:43 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-02-21 20:39:43 +0100 |
commit | 946252efabf79792aac655914276aab3fad36ef2 (patch) | |
tree | 1471b4a48f9f4f15eded8b20f71b965cac5bce78 /cv/video-widget.cpp | |
parent | d90d57a85d81bc16e14310e41c820f47e110e484 (diff) |
cv/video-widget: fix logic error
Also try not to poke size() outside UI thread.
Diffstat (limited to 'cv/video-widget.cpp')
-rw-r--r-- | cv/video-widget.cpp | 25 |
1 files changed, 20 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; |