summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt/pt_video_widget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-pt/pt_video_widget.cpp')
-rw-r--r--tracker-pt/pt_video_widget.cpp44
1 files changed, 16 insertions, 28 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();
}