summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_pt
diff options
context:
space:
mode:
Diffstat (limited to 'ftnoir_tracker_pt')
-rw-r--r--ftnoir_tracker_pt/pt_video_widget.cpp48
-rw-r--r--ftnoir_tracker_pt/pt_video_widget.h3
2 files changed, 32 insertions, 19 deletions
diff --git a/ftnoir_tracker_pt/pt_video_widget.cpp b/ftnoir_tracker_pt/pt_video_widget.cpp
index aefb8199..12f01413 100644
--- a/ftnoir_tracker_pt/pt_video_widget.cpp
+++ b/ftnoir_tracker_pt/pt_video_widget.cpp
@@ -18,29 +18,43 @@ using namespace std;
void PTVideoWidget::update_image(const cv::Mat& frame)
{
QMutexLocker foo(&mtx);
- _frame = frame.clone();
- freshp = true;
+
+ if (!freshp)
+ {
+ _frame = frame.clone();
+ freshp = true;
+ }
}
void PTVideoWidget::update_and_repaint()
{
- QMutexLocker foo(&mtx);
- if (_frame.empty() || !freshp)
- return;
- freshp = false;
- QImage qframe = QImage(_frame.cols, _frame.rows, QImage::Format_RGB888);
- uchar* data = qframe.bits();
- const int pitch = qframe.bytesPerLine();
- for (int y = 0; y < _frame.rows; y++)
- for (int x = 0; x < _frame.cols; x++)
+ QImage qframe;
+ {
+ QMutexLocker foo(&mtx);
+ if (_frame.empty() || !freshp)
+ return;
+ qframe = QImage(_frame.cols, _frame.rows, QImage::Format_RGB888);
+ freshp = false;
+ uchar* data = qframe.bits();
+ const int pitch = qframe.bytesPerLine();
+ unsigned char *input = (unsigned char*) _frame.data;
+ const int chans = _frame.channels();
+ for (int y = 0; y < _frame.rows; y++)
{
- const auto& elt = _frame.at<Vec3b>(y, x);
- const cv::Scalar elt2 = static_cast<cv::Scalar>(elt);
- data[y * pitch + x * 3 + 0] = elt2.val[2];
- data[y * pitch + x * 3 + 1] = elt2.val[1];
- data[y * pitch + x * 3 + 2] = elt2.val[0];
+ const int step = y * _frame.step;
+ const int pitch_ = y * pitch;
+ for (int x = 0; x < _frame.cols; x++)
+ {
+ data[pitch_ + x * 3 + 0] = input[step + x * chans + 2];
+ data[pitch_ + x * 3 + 1] = input[step + x * chans + 1];
+ data[pitch_ + x * 3 + 2] = input[step + x * chans + 0];
+ }
}
+ }
qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
- texture = qframe;
+ {
+ QMutexLocker foo(&mtx);
+ texture = qframe;
+ }
update();
}
diff --git a/ftnoir_tracker_pt/pt_video_widget.h b/ftnoir_tracker_pt/pt_video_widget.h
index f2b41d63..07b1ee2a 100644
--- a/ftnoir_tracker_pt/pt_video_widget.h
+++ b/ftnoir_tracker_pt/pt_video_widget.h
@@ -39,7 +39,6 @@ public:
timer.start(40);
}
void update_image(const cv::Mat &frame);
- void update_frame_and_points() {}
protected slots:
void paintEvent( QPaintEvent* e ) {
QMutexLocker foo(&mtx);
@@ -52,5 +51,5 @@ private:
QImage texture;
QTimer timer;
cv::Mat _frame;
- volatile bool freshp;
+ bool freshp;
};