summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-02-21 20:19:19 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-02-21 20:19:19 +0100
commit954264be24b68fbfa7cbce9c8f759643e2e3c96d (patch)
tree2851549110a3457fff38fd095ab38641fed5444d
parent28a5f315b368f8ac0bcb49e452fb44de821f22eb (diff)
cv/video-widget: resize image in tracker thread
Otherwise it hangs up the main UI thread.
-rw-r--r--cv/video-widget.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp
index 5d72da7e..f45830b8 100644
--- a/cv/video-widget.cpp
+++ b/cv/video-widget.cpp
@@ -27,6 +27,18 @@ void cv_video_widget::update_image(const cv::Mat& frame)
_frame = cv::Mat(frame.rows, frame.cols, CV_8UC3);
frame.copyTo(_frame);
freshp = true;
+
+ 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);
+
+ 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);
}
}
@@ -41,19 +53,9 @@ void cv_video_widget::update_and_repaint()
{
QMutexLocker l(&mtx);
- if (_frame.empty() || !freshp)
- return;
-
- 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);
-
- cv::cvtColor(_frame, _frame2, cv::COLOR_RGB2BGR);
- 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);
- freshp = false;
- update();
+ if (freshp)
+ {
+ freshp = false;
+ update();
+ }
}