From a652bf3333365c9b306361d4819262a95390bbcc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 21 Feb 2017 21:23:38 +0100 Subject: cv/video-widget: short-circuit early in widget creation Otherwise opencv has an assertion failure when creating a matrix with a zero dimension. --- cv/video-widget.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cv') diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp index b9c1e38e..3158fa8a 100644 --- a/cv/video-widget.cpp +++ b/cv/video-widget.cpp @@ -22,6 +22,11 @@ void cv_video_widget::update_image(const cv::Mat& frame) if (!freshp) { + const int w = preview_size.width(), h = preview_size.height(); + + if (!w || !h) + return; + if (_frame.cols != frame.cols || _frame.rows != frame.rows) _frame = cv::Mat(frame.rows, frame.cols, CV_8UC3); frame.copyTo(_frame); @@ -30,8 +35,6 @@ 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); - const int w = preview_size.width(), h = preview_size.height(); - if (_frame3.cols != w || _frame3.rows != h) _frame3 = cv::Mat(h, w, CV_8UC3); @@ -50,7 +53,7 @@ void cv_video_widget::update_image(const cv::Mat& frame) const cv::Mat& img = *img_; - texture = QImage((const unsigned char*) img.data, img.cols, img.rows, QImage::Format_RGB888); + texture = QImage((const unsigned char*) img.data, w, h, QImage::Format_RGB888); } } -- cgit v1.2.3