summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt/ftnoir_tracker_pt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-pt/ftnoir_tracker_pt.cpp')
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp56
1 files changed, 23 insertions, 33 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index d13c5545..40293f56 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();
}
@@ -65,12 +57,21 @@ bool Tracker_PT::get_focal_length(f& ret)
using std::tan;
using std::atan;
using std::sqrt;
-
+#if 1
const double w = info.res_x, h = info.res_y;
const double diag = sqrt(w/h*w/h + h/w*h/w);
const double diag_fov = static_cast<int>(s.fov) * M_PI / 180.;
const double fov = 2.*atan(tan(diag_fov/2.)/diag);
ret = .5 / tan(.5 * fov);
+#else
+ // the formula looks correct but doesn't work right regardless
+
+ const double diag_fov = s.fov * M_PI/180;
+ const double aspect = w / sqrt(w*w + h*h);
+ const double fov = 2*atan(tan(diag_fov*.5) * aspect);
+ ret = .5 / tan(fov * .5);
+ static bool once = false; if (!once) { once = true; qDebug() << "f" << ret << "fov" << (fov * 180/M_PI); }
+#endif
return true;
}
return false;
@@ -171,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()
@@ -180,37 +181,26 @@ void Tracker_PT::apply_settings()
QMutexLocker l(&camera_mtx);
- CamInfo info = camera.get_desired();
- const QString name = camera.get_desired_name();
+ CamInfo info;
- if (s.cam_fps != info.fps ||
- s.cam_res_x != info.res_x ||
- s.cam_res_y != info.res_y ||
- s.camera_name != name)
- {
- qDebug() << "pt: starting camera";
- camera.stop();
- camera.set_device(s.camera_name);
- camera.set_res(s.cam_res_x, s.cam_res_y);
- camera.set_fps(s.cam_fps);
+ if (!camera.get_info(info) || frame.rows != info.res_y || frame.cols != info.res_x)
frame = cv::Mat();
- camera.start();
- }
+
+ camera.start(camera_name_to_index(s.camera_name), s.cam_fps, s.cam_res_x, s.cam_res_y);
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();
}