From d7fb4b69ef543c8201b043424b9f24bfe8e050d1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 27 Feb 2023 14:10:00 +0100 Subject: tracker/nn, video/opencv: allow non-trackhat cameras --- tracker-neuralnet/ftnoir_tracker_neuralnet.cpp | 39 ++++++++++++++++++-------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'tracker-neuralnet/ftnoir_tracker_neuralnet.cpp') diff --git a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp index f1585954..5f582340 100644 --- a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp +++ b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp @@ -448,9 +448,6 @@ NeuralNetTracker::~NeuralNetTracker() module_status NeuralNetTracker::start_tracker(QFrame* videoframe) { - if (camera_name_to_index("TrackHat sensor") == -1) - return error("Can't open camera 'TrackHat sensor'"); - videoframe->show(); video_widget_ = std::make_unique(videoframe); layout_ = std::make_unique(); @@ -506,15 +503,33 @@ bool NeuralNetTracker::load_and_initialize_model() bool NeuralNetTracker::open_camera() { - //int rint = std::clamp(*settings_.resolution, 0, (int)std::size(resolution_choices)-1); - int rint = 1; + int rint = std::clamp(*settings_.resolution, 0, (int)std::size(resolution_choices)-1); resolution_tuple res = resolution_choices[rint]; - //int fps = enum_to_fps(settings_.force_fps); - int fps = 60; + int fps = enum_to_fps(settings_.force_fps); QMutexLocker l(&camera_mtx_); - camera_ = video::make_camera("TrackHat sensor"); + camera_ = nullptr; + const QString name = settings_.camera_name; + + if (name.isEmpty() || name == "TrackHat sensor") + { + camera_ = video::make_camera_("TrackHat sensor"); + if (camera_) + { + video::impl::camera::info args {}; + args.width = 640; + args.height = 480; + args.fps = 60; + args.use_mjpeg = true; + if (camera_->start(args)) + return true; + } + if (!name.isEmpty()) + return false; + } + + camera_ = video::make_camera(name); if (!camera_) return false; @@ -529,8 +544,7 @@ bool NeuralNetTracker::open_camera() if (fps) args.fps = fps; - //args.use_mjpeg = settings_.use_mjpeg; - args.use_mjpeg = true; + args.use_mjpeg = settings_.use_mjpeg; if (!camera_->start(args)) { @@ -608,6 +622,8 @@ void NeuralNetTracker::run() std::chrono::duration_cast( clk.now() - t).count()*1.e-3); } + + camera_ = nullptr; } @@ -730,11 +746,12 @@ NeuralNetDialog::NeuralNetDialog() : make_fps_combobox(); make_resolution_combobox(); -#if 0 + ui_.cameraName->addItem(QString{}); for (const auto& str : video::camera_names()) ui_.cameraName->addItem(str); tie_setting(settings_.camera_name, ui_.cameraName); +#if 0 tie_setting(settings_.fov, ui_.cameraFOV); #endif tie_setting(settings_.offset_fwd, ui_.tx_spin); -- cgit v1.2.3