From 360b2748f726576698479c0b871f7005fd491268 Mon Sep 17 00:00:00 2001 From: AIRLegend Date: Sat, 5 Sep 2020 09:51:47 +0200 Subject: [PATCH 1/7] Added logging --- Client/Client.vcxproj | 6 +++--- Client/src/Main.cpp | 22 ++++++++++++++++++++++ Client/src/presenter/presenter.cpp | 17 ++++++++++++++++- Client/src/presenter/presenter.h | 4 +++- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Client/Client.vcxproj b/Client/Client.vcxproj index c665081..38fab70 100644 --- a/Client/Client.vcxproj +++ b/Client/Client.vcxproj @@ -72,11 +72,11 @@ - $(Qt_INCLUDEPATH_);$(SolutionDir)Dependencies\libusb\include\libusb-1.0;$(SolutionDir)Dependencies\OpenCV\include\;$(SolutionDir)Dependencies\onnxruntime\include\;$(SolutionDir)AITracker\src\;$(ProjectDir)Include;$(QTDIR)\include;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtQuick;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtQml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;$(Platform)\$(Configuration)\uic;$(Platform)\$(Configuration)\moc;.\;%(AdditionalIncludeDirectories) + $(Qt_INCLUDEPATH_);$(SolutionDir)Dependencies\libusb\include\libusb-1.0;$(SolutionDir)Dependencies\OpenCV\include\;$(SolutionDir)Dependencies\spdlog\include\;$(SolutionDir)Dependencies\onnxruntime\include\;$(SolutionDir)AITracker\src\;$(ProjectDir)Include;$(QTDIR)\include;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtQuick;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtQml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;$(Platform)\$(Configuration)\uic;$(Platform)\$(Configuration)\moc;.\;%(AdditionalIncludeDirectories) - $(Qt_LIBPATH_);$(SolutionDir)Dependencies\libusb\MS64\static;$(SolutionDir)Dependencies\OpenCV\lib;$(SolutionDir)Dependencies\onnxruntime\lib\;%(AdditionalLibraryDirectories) - $(Qt_LIBS_);opencv_world430.lib;onnxruntime.lib;Ws2_32.lib;libusb-1.0.lib;legacy_stdio_definitions.lib;%(AdditionalDependencies) + $(Qt_LIBPATH_);$(SolutionDir)Dependencies\libusb\MS64\static;$(SolutionDir)Dependencies\OpenCV\lib;$(SolutionDir)Dependencies\spdlog\lib\;$(SolutionDir)Dependencies\onnxruntime\lib\;%(AdditionalLibraryDirectories) + $(Qt_LIBS_);opencv_world430.lib;onnxruntime.lib;Ws2_32.lib;libusb-1.0.lib;legacy_stdio_definitions.lib;spdlog.lib;%(AdditionalDependencies) true true diff --git a/Client/src/Main.cpp b/Client/src/Main.cpp index 7d4bb49..051e7e4 100644 --- a/Client/src/Main.cpp +++ b/Client/src/Main.cpp @@ -10,6 +10,8 @@ #include #include "tracker/TrackerFactory.h" +#include "spdlog/spdlog.h" +#include "spdlog/sinks/basic_file_sink.h" int main(int argc, char *argv[]) @@ -23,15 +25,35 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif + + + std::shared_ptr logger; + try + { + logger = spdlog::basic_logger_mt("aitrack", "log.txt", true); + } + catch (const spdlog::spdlog_ex& ex) + { + std::cout << "Log init failed: " << ex.what() << std::endl; + } + + + logger->info(" ---------- AITRACK LOG ----------"); + + QApplication app(argc, argv); WindowMain w; w.show(); + auto conf_mgr = std::make_unique("./prefs.ini"); + logger->info("Created/Found prefs.ini"); + auto t_factory = std::make_unique("./models/"); Presenter p((IView&)w, std::move(t_factory), std::move(conf_mgr)); + logger->info("App initialized"); return app.exec(); } diff --git a/Client/src/presenter/presenter.cpp b/Client/src/presenter/presenter.cpp index 950307a..74ee9e3 100644 --- a/Client/src/presenter/presenter.cpp +++ b/Client/src/presenter/presenter.cpp @@ -9,6 +9,9 @@ Presenter::Presenter(IView& view, std::unique_ptr&& t_factory, std::unique_ptr&& conf_mgr) { + + logger = spdlog::get("aitrack"); + this->tracker_factory = std::move(t_factory); this->conf_mgr = std::move(conf_mgr); state = this->conf_mgr->getConfig(); @@ -27,12 +30,14 @@ Presenter::Presenter(IView& view, std::unique_ptr&& t_factory, s CameraFactory camfactory; CameraSettings camera_settings = build_camera_params(); all_cameras = camfactory.getCameras(camera_settings); + logger->info("Number of recognized cameras: {}", all_cameras.size()); if (all_cameras.size() == 0) { std::cout << "[ERROR] NO CAMERAS AVAILABLE" << std::endl; this->view->set_enabled(false); this->view->show_message("No cameras detected. Plug one and restart the program.", MSG_SEVERITY::CRITICAL); + logger->info("No cameras were detected"); } else { @@ -79,6 +84,8 @@ void Presenter::init_sender(std::string &ip, int port) port_dest = 4242; this->udp_sender = std::make_unique(ip_str.data(), port_dest); + + this->logger->info("UDP sender reinitialized. IP: {} PORT: {}", ip_str, port_dest); } void Presenter::init_tracker(int type) @@ -92,6 +99,7 @@ void Presenter::init_tracker(int type) #ifdef _DEBUG std::cout << "Resetting old tracker" << std::endl; #endif + this->logger->info("Rebuilding tracker with new parameters"); this->t.reset(); this->t.release(); this->t = tracker_factory-> @@ -108,6 +116,7 @@ void Presenter::init_tracker(int type) } else { + this->logger->info("Building Tracker with selected camera: {}", state.selected_camera); this->t = tracker_factory->buildTracker(all_cameras[state.selected_camera]->width, all_cameras[state.selected_camera]->height, (float)state.prior_distance, @@ -132,8 +141,9 @@ void Presenter::run_loop() double buffer_data[6]; + this->logger->info("Starting camera {} capture", state.selected_camera); cam->start_camera(); - + this->logger->info("Camera {} started capturing", state.selected_camera); while(run) { @@ -171,6 +181,7 @@ void Presenter::run_loop() } cam->stop_camera(); + this->logger->info("Stop camera {} capture", state.selected_camera); } @@ -197,6 +208,7 @@ void Presenter::update_stabilizer(const ConfigData& data) { this->filter = std::make_unique(66 * 2); } + this->logger->info("Updated stabilizer."); } CameraSettings Presenter::build_camera_params() @@ -212,6 +224,7 @@ CameraSettings Presenter::build_camera_params() void Presenter::update_camera_params() { + this->logger->info("Update camera parameters."); all_cameras[state.selected_camera]->set_settings(build_camera_params()); } @@ -239,6 +252,8 @@ void Presenter::toggle_tracking() void Presenter::save_prefs(const ConfigData& data) { + this->logger->info("Saving prefs"); + // Disable painting parts from the run loop if needed this->paint = data.show_video_feed; state.show_video_feed = data.show_video_feed; diff --git a/Client/src/presenter/presenter.h b/Client/src/presenter/presenter.h index 9d22109..7d42fc8 100644 --- a/Client/src/presenter/presenter.h +++ b/Client/src/presenter/presenter.h @@ -12,6 +12,8 @@ #include "../tracker/TrackerFactory.h" #include "../tracker/ITrackerWrapper.h" +#include "spdlog/spdlog.h" +#include "spdlog/sinks/basic_file_sink.h" class Presenter : IPresenter { @@ -20,8 +22,8 @@ class Presenter : IPresenter std::unique_ptr udp_sender; std::unique_ptr tracker_factory; std::unique_ptr t; - //std::unique_ptr camera; std::vector> all_cameras; + std::shared_ptr logger; // Current program's state + config. ConfigData state; From 0f06a11374f7129ccf0365af9090480f52b82b12 Mon Sep 17 00:00:00 2001 From: AIRLegend Date: Sat, 5 Sep 2020 15:55:31 +0200 Subject: [PATCH 2/7] Add logger as submodule --- .gitmodules | 3 +++ Client/Client.vcxproj | 4 ++-- Client/Vendor/spdlog | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 160000 Client/Vendor/spdlog diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a62f447 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Client/Vendor/spdlog"] + path = Client/Vendor/spdlog + url = https://github.com/gabime/spdlog diff --git a/Client/Client.vcxproj b/Client/Client.vcxproj index 38fab70..0227b67 100644 --- a/Client/Client.vcxproj +++ b/Client/Client.vcxproj @@ -72,11 +72,11 @@ - $(Qt_INCLUDEPATH_);$(SolutionDir)Dependencies\libusb\include\libusb-1.0;$(SolutionDir)Dependencies\OpenCV\include\;$(SolutionDir)Dependencies\spdlog\include\;$(SolutionDir)Dependencies\onnxruntime\include\;$(SolutionDir)AITracker\src\;$(ProjectDir)Include;$(QTDIR)\include;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtQuick;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtQml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;$(Platform)\$(Configuration)\uic;$(Platform)\$(Configuration)\moc;.\;%(AdditionalIncludeDirectories) + $(Qt_INCLUDEPATH_);$(SolutionDir)Dependencies\libusb\include\libusb-1.0;$(SolutionDir)Dependencies\OpenCV\include\;$(ProjectDir)\Vendor\spdlog\include\;$(SolutionDir)Dependencies\onnxruntime\include\;$(SolutionDir)AITracker\src\;$(ProjectDir)Include;$(QTDIR)\include;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtQuick;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtQml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;$(Platform)\$(Configuration)\uic;$(Platform)\$(Configuration)\moc;.\;%(AdditionalIncludeDirectories) $(Qt_LIBPATH_);$(SolutionDir)Dependencies\libusb\MS64\static;$(SolutionDir)Dependencies\OpenCV\lib;$(SolutionDir)Dependencies\spdlog\lib\;$(SolutionDir)Dependencies\onnxruntime\lib\;%(AdditionalLibraryDirectories) - $(Qt_LIBS_);opencv_world430.lib;onnxruntime.lib;Ws2_32.lib;libusb-1.0.lib;legacy_stdio_definitions.lib;spdlog.lib;%(AdditionalDependencies) + $(Qt_LIBS_);opencv_world430.lib;onnxruntime.lib;Ws2_32.lib;libusb-1.0.lib;legacy_stdio_definitions.lib;%(AdditionalDependencies) true true diff --git a/Client/Vendor/spdlog b/Client/Vendor/spdlog new file mode 160000 index 0000000..9cd25dd --- /dev/null +++ b/Client/Vendor/spdlog @@ -0,0 +1 @@ +Subproject commit 9cd25dd21664be8752c3c96df2d58c0544d28c29 From 71d5b241042f800849e549ac9dcb656e5c44499b Mon Sep 17 00:00:00 2001 From: AIRLegend Date: Sat, 5 Sep 2020 16:07:08 +0200 Subject: [PATCH 3/7] logging --- Client/Client.vcxproj | 2 +- Client/src/presenter/presenter.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Client/Client.vcxproj b/Client/Client.vcxproj index 0227b67..015b925 100644 --- a/Client/Client.vcxproj +++ b/Client/Client.vcxproj @@ -105,7 +105,7 @@ $(Qt_LIBS_);opencv_world430d.lib;onnxruntime.lib;Ws2_32.lib;legacy_stdio_definitions.lib;libusb-1.0.lib;%(AdditionalDependencies) - $(Qt_INCLUDEPATH_);$(SolutionDir)Dependencies\libusb\include\libusb-1.0;$(SolutionDir)Dependencies\OpenCV\include\;$(SolutionDir)Dependencies\onnxruntime\include\;$(SolutionDir)PS3Driver\include\;$(SolutionDir)AITracker\src\;$(ProjectDir)Include;$(QTDIR)\include;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtQuick;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtQml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;$(Platform)\$(Configuration)\uic;$(Platform)\$(Configuration)\moc;.\;%(AdditionalIncludeDirectories) + $(Qt_INCLUDEPATH_);$(SolutionDir)Dependencies\libusb\include\libusb-1.0;$(SolutionDir)Dependencies\OpenCV\include\;$(SolutionDir)Dependencies\onnxruntime\include\;$(ProjectDir)Vendor\spdlog\include\;$(SolutionDir)PS3Driver\include\;$(SolutionDir)AITracker\src\;$(ProjectDir)Include;$(QTDIR)\include;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtQuick;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtQml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;$(Platform)\$(Configuration)\uic;$(Platform)\$(Configuration)\moc;.\;%(AdditionalIncludeDirectories) true diff --git a/Client/src/presenter/presenter.cpp b/Client/src/presenter/presenter.cpp index 74ee9e3..c021f33 100644 --- a/Client/src/presenter/presenter.cpp +++ b/Client/src/presenter/presenter.cpp @@ -123,6 +123,7 @@ void Presenter::init_tracker(int type) tracker_factory->get_type(type)); } state.selected_model = type; + this->logger->info("Tracker initialized."); } @@ -224,8 +225,9 @@ CameraSettings Presenter::build_camera_params() void Presenter::update_camera_params() { - this->logger->info("Update camera parameters."); + this->logger->info("Updating camera parameters..."); all_cameras[state.selected_camera]->set_settings(build_camera_params()); + this->logger->info("Updated camera parameters."); } @@ -285,6 +287,7 @@ void Presenter::save_prefs(const ConfigData& data) conf_mgr->updateConfig(state); sync_ui_inputs(); + this->logger->info("Prefs saved"); } From 563b5aa11f11e64a9d4457fa9c8515f03586b37a Mon Sep 17 00:00:00 2001 From: AIRLegend Date: Sat, 5 Sep 2020 19:42:10 +0200 Subject: [PATCH 4/7] Fix viewport cropping. --- Client/src/view/WindowMain.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Client/src/view/WindowMain.cpp b/Client/src/view/WindowMain.cpp index aa4d541..8f2378f 100644 --- a/Client/src/view/WindowMain.cpp +++ b/Client/src/view/WindowMain.cpp @@ -45,6 +45,7 @@ void WindowMain::paint_video_frame(cv::Mat& img) if (check_video_preview->isChecked()) tracking_frame->setPixmap( QPixmap::fromImage(QImage(img.data, img.cols, img.rows, img.step, QImage::Format_RGB888)) + .scaled(400,280, Qt::KeepAspectRatio, Qt::FastTransformation) ); } @@ -87,8 +88,6 @@ void WindowMain::set_tracking_mode(bool is_tracking) } - - void WindowMain::update_view_state(ConfigData conf) { set_inputs(conf); From 6676c7c30cdcecc095b9a9d5ad3a293473704726 Mon Sep 17 00:00:00 2001 From: AIRLegend Date: Sat, 5 Sep 2020 19:45:56 +0200 Subject: [PATCH 5/7] Update gitignote --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e145363..a290142 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,4 @@ healthchecksdb */Dependencies/* Client/models prefs.ini +log.txt From f19ede2f76cfec5093c5994d20eb5977ea764f05 Mon Sep 17 00:00:00 2001 From: AIRLegend Date: Sat, 5 Sep 2020 19:46:54 +0200 Subject: [PATCH 6/7] Fixed camera cropping bug. Now the resolution is applied natively to the camera. --- Client/src/Main.cpp | 1 + Client/src/camera/CameraFactory.cpp | 3 +- Client/src/camera/OCVCamera.cpp | 45 +++++++++++++++++++---------- Client/src/camera/OCVCamera.h | 2 +- Client/src/model/Config.cpp | 6 ++-- Client/src/presenter/presenter.cpp | 20 +++++++++++-- Client/src/view/ConfigWindow.ui | 12 ++++---- 7 files changed, 60 insertions(+), 29 deletions(-) diff --git a/Client/src/Main.cpp b/Client/src/Main.cpp index 051e7e4..f6fe835 100644 --- a/Client/src/Main.cpp +++ b/Client/src/Main.cpp @@ -31,6 +31,7 @@ int main(int argc, char *argv[]) try { logger = spdlog::basic_logger_mt("aitrack", "log.txt", true); + logger->flush_on(spdlog::level::info); } catch (const spdlog::spdlog_ex& ex) { diff --git a/Client/src/camera/CameraFactory.cpp b/Client/src/camera/CameraFactory.cpp index 4ca6412..442c461 100644 --- a/Client/src/camera/CameraFactory.cpp +++ b/Client/src/camera/CameraFactory.cpp @@ -55,7 +55,8 @@ std::vector> CameraFactory::getCameras(CameraSettings& s { try { - std::shared_ptr c = std::make_shared(640, 480, 30, i); + std::shared_ptr c = std::make_shared(settings.width, settings.height, settings.fps, i); + c->set_settings(settings); // Brightness / Exposure cams.push_back(std::move(c)); std::cout << "Found ID: " << i << std::endl; } diff --git a/Client/src/camera/OCVCamera.cpp b/Client/src/camera/OCVCamera.cpp index ad22f6e..a892415 100644 --- a/Client/src/camera/OCVCamera.cpp +++ b/Client/src/camera/OCVCamera.cpp @@ -17,7 +17,24 @@ OCVCamera::OCVCamera(int width, int height, int fps, int index) : } is_valid = true; - w_scale = (float)width/(float)cam_native_width; + + if (width < 0 || height < 0) + { + this->width = cam_native_width; + this->height = cam_native_height; + } + + if (fps < 0) + this->fps = cam_native_fps; + + + cap.set(cv::CAP_PROP_FRAME_WIDTH, this->width); + cap.set(cv::CAP_PROP_FRAME_HEIGHT, this->height); + cap.set(cv::CAP_PROP_FPS, this->fps); + + + + //w_scale = (float)width / w;//(float)cam_native_width; exposure, gain = -1; } @@ -39,7 +56,9 @@ bool OCVCamera::is_camera_available() if (frame.empty()) return false; - cam_native_width = cap.get(cv::CAP_PROP_FRAME_WIDTH); + cam_native_width = (int)cap.get(cv::CAP_PROP_FRAME_WIDTH); + cam_native_height = (int)cap.get(cv::CAP_PROP_FRAME_HEIGHT); + cam_native_fps = (int)cap.get(cv::CAP_PROP_FPS); cap.release(); } return available; @@ -63,9 +82,6 @@ void OCVCamera::get_frame(uint8_t* buffer) { cv::Mat frame; cap.read(frame); - //Scale maintaining aspect ratio. If distorted, the model will get confused. - //TODO: Maybe cropping (width,height) section from the center is better. - cv::resize(frame, frame, size, w_scale, w_scale); cv::flip(frame, frame, 1); for (int i = 0; i < frame.cols * frame.rows * 3; i++) buffer[i] = frame.data[i]; @@ -74,16 +90,15 @@ void OCVCamera::get_frame(uint8_t* buffer) void OCVCamera::set_settings(CameraSettings& settings) { - this->width = settings.width; - this->fps = settings.fps; - this->height = settings.height; - w_scale = (float)width / (float)cam_native_width; - - // Opencv needs [0,1] ranges - exposure = settings.exposure < 0 ? -1.0F : (float)settings.exposure/255; - gain = settings.gain < 0 ? -1.0F : (float)settings.gain / 64; - cap.set(cv::CAP_PROP_EXPOSURE, exposure); - cap.set(cv::CAP_PROP_GAIN, gain); + this->width = settings.width > 0 ? settings.width : this->cam_native_width; + this->height = settings.height > 0 ? settings.height : this->cam_native_height; + this->fps = settings.fps > 0 ? settings.fps : this->cam_native_fps; + + // Disabled for the moment because of the different ranges in generic cameras. + //exposure = settings.exposure < 0 ? -1.0F : (float)settings.exposure/255; + //gain = settings.gain < 0 ? -1.0F : (float)settings.gain / 64; + //cap.set(cv::CAP_PROP_EXPOSURE, exposure); + //cap.set(cv::CAP_PROP_GAIN, gain); } CameraSettings OCVCamera::get_settings() diff --git a/Client/src/camera/OCVCamera.h b/Client/src/camera/OCVCamera.h index 2d51b2f..2d1e0bd 100644 --- a/Client/src/camera/OCVCamera.h +++ b/Client/src/camera/OCVCamera.h @@ -9,7 +9,7 @@ class OCVCamera : public Camera cv::Size size; float w_scale; float exposure, gain; - int cam_native_width; + int cam_native_height, cam_native_width, cam_native_fps; int cam_index; int CV_BACKEND; diff --git a/Client/src/model/Config.cpp b/Client/src/model/Config.cpp index a9b1cd3..628e13b 100644 --- a/Client/src/model/Config.cpp +++ b/Client/src/model/Config.cpp @@ -16,9 +16,9 @@ ConfigData ConfigData::getGenericConfig() conf.selected_model = 0; conf.selected_camera = 0; conf.num_cameras_detected = 0; - conf.video_width = 640; - conf.video_height = 480; - conf.video_fps = 30; + conf.video_width = -1; + conf.video_height = -1; + conf.video_fps = -1; conf.use_landmark_stab = true; conf.x, conf.y, conf.z, conf.pitch, conf.yaw, conf.roll = 0; conf.cam_exposure = -1; diff --git a/Client/src/presenter/presenter.cpp b/Client/src/presenter/presenter.cpp index c021f33..988f9c7 100644 --- a/Client/src/presenter/presenter.cpp +++ b/Client/src/presenter/presenter.cpp @@ -24,11 +24,9 @@ Presenter::Presenter(IView& view, std::unique_ptr&& t_factory, s // Init available model names to show in the GUI this->tracker_factory->get_model_names(state.model_names); - // Setup a filter to stabilize the recognized facial landmarks if needed. - update_stabilizer(state); - CameraFactory camfactory; CameraSettings camera_settings = build_camera_params(); + logger->info("Searching for cameras..."); all_cameras = camfactory.getCameras(camera_settings); logger->info("Number of recognized cameras: {}", all_cameras.size()); @@ -52,6 +50,12 @@ Presenter::Presenter(IView& view, std::unique_ptr&& t_factory, s // Build tracker init_tracker(state.selected_model); + // Setup a filter to stabilize the recognized facial landmarks if needed. + update_stabilizer(state); + + // Sync camera prefs between active camera and state. + update_camera_params(); + } // Check if there was a problem initing tracker @@ -227,6 +231,16 @@ void Presenter::update_camera_params() { this->logger->info("Updating camera parameters..."); all_cameras[state.selected_camera]->set_settings(build_camera_params()); + + //if (state.video_height < 0 || state.video_width < 0) + //{ + // The camera is using its default resolution so we must update our state + // to it. If we are using our custom resolution that wont be necessary. + state.video_height = all_cameras[state.selected_camera]->height; + state.video_width = all_cameras[state.selected_camera]->width; + state.video_fps = all_cameras[state.selected_camera]->fps; + //} + this->logger->info("Updated camera parameters."); } diff --git a/Client/src/view/ConfigWindow.ui b/Client/src/view/ConfigWindow.ui index 2a2dcda..224dba0 100644 --- a/Client/src/view/ConfigWindow.ui +++ b/Client/src/view/ConfigWindow.ui @@ -70,13 +70,13 @@ - 640 + -1 3000 - 640 + -1 @@ -97,26 +97,26 @@ - 480 + -1 3000 - 480 + -1 - 15 + -1 120 - 30 + -1 From 3f4753180559e4e06bae144078ede1ea78f65c86 Mon Sep 17 00:00:00 2001 From: AIRLegend Date: Sat, 5 Sep 2020 20:42:16 +0200 Subject: [PATCH 7/7] Camera width was not being updated right --- Client/src/camera/CameraSettings.cpp | 2 +- Client/src/camera/OCVCamera.cpp | 3 --- Client/src/presenter/presenter.cpp | 11 ++++------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Client/src/camera/CameraSettings.cpp b/Client/src/camera/CameraSettings.cpp index afa15d9..ea9bfde 100644 --- a/Client/src/camera/CameraSettings.cpp +++ b/Client/src/camera/CameraSettings.cpp @@ -16,7 +16,7 @@ CameraSettings::CameraSettings(CameraSettings& settings) gain = settings.gain; fps = settings.fps; width = settings.width; - height = settings.width; + height = settings.height; } CameraSettings::~CameraSettings() diff --git a/Client/src/camera/OCVCamera.cpp b/Client/src/camera/OCVCamera.cpp index a892415..45f0986 100644 --- a/Client/src/camera/OCVCamera.cpp +++ b/Client/src/camera/OCVCamera.cpp @@ -32,9 +32,6 @@ OCVCamera::OCVCamera(int width, int height, int fps, int index) : cap.set(cv::CAP_PROP_FRAME_HEIGHT, this->height); cap.set(cv::CAP_PROP_FPS, this->fps); - - - //w_scale = (float)width / w;//(float)cam_native_width; exposure, gain = -1; } diff --git a/Client/src/presenter/presenter.cpp b/Client/src/presenter/presenter.cpp index 988f9c7..6322191 100644 --- a/Client/src/presenter/presenter.cpp +++ b/Client/src/presenter/presenter.cpp @@ -232,16 +232,12 @@ void Presenter::update_camera_params() this->logger->info("Updating camera parameters..."); all_cameras[state.selected_camera]->set_settings(build_camera_params()); - //if (state.video_height < 0 || state.video_width < 0) - //{ - // The camera is using its default resolution so we must update our state - // to it. If we are using our custom resolution that wont be necessary. + // The camera can be using its default resolution so we must sync our state + // to it. If we are using our custom resolution that wont be necessary. state.video_height = all_cameras[state.selected_camera]->height; state.video_width = all_cameras[state.selected_camera]->width; state.video_fps = all_cameras[state.selected_camera]->fps; - //} - - this->logger->info("Updated camera parameters."); + this->logger->info("Updated camera parameters. {}x{}@{}", state.video_width, state.video_height, state.video_fps); } @@ -292,6 +288,7 @@ void Presenter::save_prefs(const ConfigData& data) state.video_fps = data.video_fps; state.video_height = data.video_height; state.video_width = data.video_width; + update_camera_params();