summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-12-19 21:57:01 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-12-19 21:57:01 +0100
commitf6c32359f0697b3c8caea669d4a766b684b06a9b (patch)
treeaeae5fe6715e789923d206334fc786b7315cedaa
parent29b7e7c2cd3f7d2b72f15168ecfa167beee0ded5 (diff)
tracker/pt: avoid widget temp QImage allocation
-rw-r--r--tracker-pt/pt_video_widget.cpp44
-rw-r--r--tracker-pt/pt_video_widget.h2
2 files changed, 17 insertions, 29 deletions
diff --git a/tracker-pt/pt_video_widget.cpp b/tracker-pt/pt_video_widget.cpp
index 8c18e678..095c325f 100644
--- a/tracker-pt/pt_video_widget.cpp
+++ b/tracker-pt/pt_video_widget.cpp
@@ -9,6 +9,7 @@
*/
#include "pt_video_widget.h"
+#include <opencv2/imgproc.hpp>
void PTVideoWidget::update_image(const cv::Mat& frame)
{
@@ -16,11 +17,10 @@ void PTVideoWidget::update_image(const cv::Mat& frame)
if (!freshp)
{
- if (_frame.cols != frame.cols ||
- _frame.rows != frame.rows ||
- _frame.channels() != frame.channels())
+ if (_frame.cols != frame.cols || _frame.rows != frame.rows)
{
- _frame = cv::Mat();
+ _frame = cv::Mat(frame.rows, frame.cols, CV_8U);
+ _frame2 = cv::Mat(frame.rows, frame.cols, CV_8U);
}
frame.copyTo(_frame);
freshp = true;
@@ -29,29 +29,17 @@ void PTVideoWidget::update_image(const cv::Mat& frame)
void PTVideoWidget::update_and_repaint()
{
- {
- QMutexLocker foo(&mtx);
- if (_frame.empty() || !freshp)
- return;
- texture = QImage(_frame.cols, _frame.rows, QImage::Format_RGB888);
- freshp = false;
- uchar* data = texture.bits();
- const int chans = _frame.channels();
- const int pitch = texture.bytesPerLine();
- for (int y = 0; y < _frame.rows; y++)
- {
- unsigned char* dest = data + pitch * y;
- const unsigned char* ln = _frame.ptr(y);
- for (int x = 0; x < _frame.cols; x++)
- {
- const int idx = x * chans;
- const int x_ = x * 3;
- dest[x_ + 0] = ln[idx + 2];
- dest[x_ + 1] = ln[idx + 1];
- dest[x_ + 2] = ln[idx + 0];
- }
- }
- }
- texture = texture.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
+ QMutexLocker foo(&mtx);
+ if (_frame.empty() || !freshp)
+ return;
+ cv::cvtColor(_frame, _frame2, cv::COLOR_RGB2BGR);
+
+ if (_frame3.cols != width() || _frame3.rows != height())
+ _frame3 = cv::Mat(height(), width(), CV_8U);
+
+ cv::resize(_frame2, _frame3, cv::Size(width(), height()), 0, 0, cv::INTER_NEAREST);
+
+ texture = QImage((const unsigned char*) _frame2.data, _frame2.cols, _frame2.rows, QImage::Format_RGB888);
+ freshp = false;
update();
}
diff --git a/tracker-pt/pt_video_widget.h b/tracker-pt/pt_video_widget.h
index 1235c0d5..073b2e93 100644
--- a/tracker-pt/pt_video_widget.h
+++ b/tracker-pt/pt_video_widget.h
@@ -42,6 +42,6 @@ private:
QMutex mtx;
QImage texture;
QTimer timer;
- cv::Mat _frame;
+ cv::Mat _frame, _frame2, _frame3;
bool freshp;
};