diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-03 07:10:12 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-03 07:10:12 +0100 |
commit | ac36fa53e970bf79d68499b52433d33ed994c4c5 (patch) | |
tree | b98ad2b555c8b16ab108ff77be6c1ea063606e0e /tracker-pt | |
parent | 1aeb193a0277e2f1319dd1e935f8111cf01d301c (diff) |
tracker/{aruco,pt}: use RAII for QObject
Diffstat (limited to 'tracker-pt')
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 27 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.h | 8 |
2 files changed, 14 insertions, 21 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index ca25e858..0e43b812 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -19,8 +19,6 @@ //----------------------------------------------------------------------------- Tracker_PT::Tracker_PT() : - video_widget(nullptr), - video_frame(nullptr), point_count(0), commands(0), ever_success(false) @@ -32,13 +30,7 @@ Tracker_PT::~Tracker_PT() { set_command(ABORT); wait(); - if (video_widget) - delete video_widget; - video_widget = NULL; - if (video_frame) - { - if (video_frame->layout()) delete video_frame->layout(); - } + // fast start/stop causes breakage camera.stop(); } @@ -180,7 +172,7 @@ void Tracker_PT::run() video_widget->update_image(frame_); } } - qDebug() << "pt: Thread stopping"; + qDebug() << "pt: thread stopped"; } void Tracker_PT::apply_settings() @@ -209,17 +201,16 @@ void Tracker_PT::apply_settings() qDebug() << "pt: done applying settings"; } -void Tracker_PT::start_tracker(QFrame *parent_window) +void Tracker_PT::start_tracker(QFrame* video_frame) { - video_frame = parent_window; video_frame->setAttribute(Qt::WA_NativeWindow); - video_frame->show(); - video_widget = new cv_video_widget(video_frame); - QHBoxLayout* video_layout = new QHBoxLayout(parent_window); - video_layout->setContentsMargins(0, 0, 0, 0); - video_layout->addWidget(video_widget); - video_frame->setLayout(video_layout); + video_widget = qptr<cv_video_widget>(video_frame); + layout = qptr<QHBoxLayout>(video_frame); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(video_widget.data()); + video_frame->setLayout(layout.data()); video_widget->resize(video_frame->width(), video_frame->height()); + video_frame->show(); start(); } diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index 020694ae..66928655 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -18,12 +18,14 @@ #include "point_tracker.h" #include "compat/timer.hpp" #include "cv/video-widget.hpp" +#include "compat/util.hpp" #include <QCoreApplication> #include <QThread> #include <QMutex> #include <QMutexLocker> #include <QTime> +#include <QLayout> #include <atomic> #include <memory> #include <vector> @@ -65,12 +67,12 @@ private: QMutex camera_mtx; QMutex data_mtx; - CVCamera camera; + Camera camera; PointExtractor point_extractor; PointTracker point_tracker; - cv_video_widget* video_widget; - QFrame* video_frame; + qshared<cv_video_widget> video_widget; + qshared<QLayout> layout; settings_pt s; Timer time; |