summaryrefslogtreecommitdiffhomepage
path: root/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-neuralnet/ftnoir_tracker_neuralnet.cpp')
-rw-r--r--tracker-neuralnet/ftnoir_tracker_neuralnet.cpp71
1 files changed, 66 insertions, 5 deletions
diff --git a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
index 34368478..dfee19c8 100644
--- a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
+++ b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
@@ -28,6 +28,8 @@
#include <QMutexLocker>
#include <QDebug>
#include <QFile>
+#include <QFileDialog>
+#include <QFileInfo>
#include <cstdio>
#include <cmath>
@@ -57,6 +59,12 @@ std::string convert(const QString &s) { return s.toStdString(); }
#endif
+QDir get_default_model_directory()
+{
+ return QDir(OPENTRACK_BASE_PATH+ "/" OPENTRACK_LIBRARY_PATH "models");
+}
+
+
int enum_to_fps(int value)
{
switch (value)
@@ -465,8 +473,7 @@ bool NeuralNetTracker::load_and_initialize_model()
{
const QString localizer_model_path_enc =
OPENTRACK_BASE_PATH+"/" OPENTRACK_LIBRARY_PATH "/models/head-localizer.onnx";
- const QString poseestimator_model_path_enc =
- OPENTRACK_BASE_PATH+"/" OPENTRACK_LIBRARY_PATH "/models/head-pose.onnx";
+ const QString poseestimator_model_path_enc = get_posenet_filename();
try
{
@@ -486,6 +493,7 @@ bool NeuralNetTracker::load_and_initialize_model()
allocator_info_,
Ort::Session{env_, convert(localizer_model_path_enc).c_str(), opts});
+ qDebug() << "Loading pose net " << poseestimator_model_path_enc;
poseestimator_.emplace(
allocator_info_,
Ort::Session{env_, convert(poseestimator_model_path_enc).c_str(), opts});
@@ -496,6 +504,11 @@ bool NeuralNetTracker::load_and_initialize_model()
<< e.what();
return false;
}
+ catch (const std::exception &e)
+ {
+ qDebug() << "Failed to initialize the neural network models. Error message: " << e.what();
+ return false;
+ }
return true;
}
@@ -682,7 +695,7 @@ void NeuralNetTracker::data(double *data)
const auto& mx = tmp.R.col(0);
const auto& my = tmp.R.col(1);
- const auto& mz = -tmp.R.col(2);
+ const auto& mz = tmp.R.col(2);
const float yaw = std::atan2(mx(2), mx(0));
const float pitch = -std::atan2(-mx(1), std::sqrt(mx(2)*mx(2)+mx(0)*mx(0)));
@@ -707,12 +720,31 @@ Affine NeuralNetTracker::pose()
return last_pose_affine_ ? *last_pose_affine_ : Affine{};
}
+
std::tuple<cv::Size,double, double> NeuralNetTracker::stats() const
{
QMutexLocker lck(&stats_mtx_);
return { resolution_, fps_, inference_time_ };
}
+
+QString NeuralNetTracker::get_posenet_filename() const
+{
+ QString filename = settings_.posenet_file;
+ if (QFileInfo(filename).isRelative())
+ filename = get_default_model_directory().absoluteFilePath(filename);
+ return filename;
+}
+
+
+
+
+
+
+
+
+
+
void NeuralNetDialog::make_fps_combobox()
{
#if 0
@@ -789,8 +821,7 @@ NeuralNetDialog::NeuralNetDialog() :
connect(ui_.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
connect(ui_.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));
connect(ui_.camera_settings, SIGNAL(clicked()), this, SLOT(camera_settings()));
-
- connect(&settings_.camera_name, value_::value_changed<QString>(), this, &NeuralNetDialog::update_camera_settings_state);
+ //connect(ui_.posenetSelectButton, SIGNAL(clicked()), this, SLOT(onSelectPoseNetFile()));
update_camera_settings_state(settings_.camera_name);
@@ -798,6 +829,11 @@ NeuralNetDialog::NeuralNetDialog() :
calib_timer_.setInterval(35);
connect(ui_.tcalib_button,SIGNAL(toggled(bool)), this, SLOT(startstop_trans_calib(bool)));
+ connect(&cs_.exposure, value_::value_changed<int>(), this, [this](int value) {
+ ui_.camera_settings->setEnabled(value == (int)exposure_preset::ignored);
+ });
+ ui_.camera_settings->setEnabled(cs_.exposure == exposure_preset::ignored);
+
connect(&tracker_status_poll_timer_, &QTimer::timeout, this, &NeuralNetDialog::status_poll);
tracker_status_poll_timer_.setInterval(250);
tracker_status_poll_timer_.start();
@@ -958,6 +994,31 @@ void NeuralNetDialog::startstop_trans_calib(bool start)
}
+void NeuralNetDialog::onSelectPoseNetFile()
+{
+ const auto root = get_default_model_directory();
+ // Start with the current setting
+ QString filename = settings_.posenet_file;
+ // If the filename is relative then assume that the file is located under the
+ // model directory. Under regular use this should always be the case.
+ if (QFileInfo(filename).isRelative())
+ filename = root.absoluteFilePath(filename);
+ filename = QFileDialog::getOpenFileName(this,
+ tr("Select Pose Net ONNX"), filename, tr("ONNX Files (*.onnx)"));
+ // In case the user aborted.
+ if (filename.isEmpty())
+ return;
+ // When a file under the model directory was selected we can get rid of the
+ // directory prefix. This is more robust than storing absolute paths, e.g.
+ // in case the user moves the opentrack install folder / reuses old settings.
+ // When the file is not in the model directory, we have to use the absolute path,
+ // which is also fine as developer feature.
+ if (filename.startsWith(root.absolutePath()))
+ filename = root.relativeFilePath(filename);
+ settings_.posenet_file = filename;
+}
+
+
Settings::Settings() : opts("neuralnet-tracker") {}
} // neuralnet_tracker_ns