From bb82a0ddd5a4389a5f5b5bef9d8e98c84b88e263 Mon Sep 17 00:00:00 2001 From: Epicalert Date: Sat, 3 Jul 2021 17:53:57 +0800 Subject: [PATCH] Add option to enable/disable camera feed window By default, camera feed will not be shown to the user. --- src/args.cpp | 8 +++++++- src/args.hpp | 5 +++-- src/configfile.cpp | 4 ++++ src/cv.cpp | 2 +- src/fc2dconfig.cpp | 5 +++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/args.cpp b/src/args.cpp index 75fbabe..46789e4 100644 --- a/src/args.cpp +++ b/src/args.cpp @@ -12,7 +12,8 @@ const char* argp_program_version = const struct argp_option options[] = { //name, key, arg, flags, doc, group {"haar-cascade", 0x00, 0, 0, "Use Haar Cascades for faster (but less accurate) face detection.", 0}, - {"model", 'm', "model", 0, "Name of the model file to use. (not including '.fma')", 0}, + {"show-camera", 0x01, 0, 0, "Show the camera feed in another window", 0}, + {"model", 'm', "model", 0, "Name of the model file to use. (not including '.fma')", 0}, {0} }; @@ -25,6 +26,7 @@ struct argp argp = { #endif struct optData optData = { + false, false, "test", }; @@ -36,6 +38,10 @@ error_t parseOptions(int key, char* arg, struct argp_state* state) { optData.useHaar = true; break; + case 0x01: //--show-camera + optData.showCamera = true; + break; + case 'm': optData.model = std::string(arg); break; diff --git a/src/args.hpp b/src/args.hpp index 8e4edc0..e006bef 100644 --- a/src/args.hpp +++ b/src/args.hpp @@ -10,8 +10,9 @@ error_t parseOptions(int key, char* arg, struct argp_state* state); #endif struct optData { - bool useHaar; //use haar cascades (0x00) - std::string model; //model to open (0x6d "m") + bool useHaar; // use haar cascades (0x00) + bool showCamera; // show camera feed (0x01) + std::string model; // model to open (0x6d 'm') }; extern const char* argp_program_version; diff --git a/src/configfile.cpp b/src/configfile.cpp index 8666627..80275a9 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -16,6 +16,10 @@ bool configFileOpen(struct optData* data) { if (useHaarResult.first) { data->useHaar = useHaarResult.second; } + auto showCameraResult = configFile.table->getBool("show_camera"); + if (showCameraResult.first) { + data->showCamera = showCameraResult.second; + } auto modelNameResult = configFile.table->getString("model"); if (modelNameResult.first) { data->model = modelNameResult.second; diff --git a/src/cv.cpp b/src/cv.cpp index 1047684..23b5c52 100644 --- a/src/cv.cpp +++ b/src/cv.cpp @@ -209,7 +209,7 @@ void cvFrame() { } void cvShowFrame() { - if(frame.empty()) return; + if(frame.empty() || !optData.showCamera) return; cv::imshow("Video Input", frame); cv::waitKey(1); diff --git a/src/fc2dconfig.cpp b/src/fc2dconfig.cpp index ed8ded6..72e209a 100644 --- a/src/fc2dconfig.cpp +++ b/src/fc2dconfig.cpp @@ -22,6 +22,7 @@ class ConfigurationFrame : public wxFrame { private: std::vector modelVec; wxCheckBox* useHaarCheckBox; + wxCheckBox* showCameraCheckBox; wxChoice* modelNameChoice; void loadExistingConfig(); // loads existing config file and populates controls void OnApply(wxCommandEvent& event); @@ -52,6 +53,7 @@ ConfigurationFrame::ConfigurationFrame() : wxFrame(NULL, wxID_ANY, "Configure " // define all controls and labels useHaarCheckBox = new wxCheckBox(panel, wxID_ANY, "Disable DNN face detection"); + showCameraCheckBox = new wxCheckBox(panel, wxID_ANY, "Show camera feed"); wxStaticText* modelNameText = new wxStaticText(panel, wxID_ANY, "Model name:"); modelNameChoice = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, modelVec.size(), modelArray); @@ -61,6 +63,7 @@ ConfigurationFrame::ConfigurationFrame() : wxFrame(NULL, wxID_ANY, "Configure " wxStaticBoxSizer* generalBoxSizer = new wxStaticBoxSizer(new wxStaticBox(panel, wxID_ANY, "General"), wxVERTICAL); generalBoxSizer->Add(modelSizer, 0, wxALL, 5); + generalBoxSizer->Add(showCameraCheckBox, 0, wxALL, 5); wxStaticBoxSizer* performanceBoxSizer = new wxStaticBoxSizer(new wxStaticBox(panel, wxID_ANY, "Performance"), wxVERTICAL); performanceBoxSizer->Add(useHaarCheckBox, 0, wxALL, 5); @@ -92,6 +95,7 @@ void ConfigurationFrame::loadExistingConfig() { configFileOpen(&configData); useHaarCheckBox->SetValue(configData.useHaar); + showCameraCheckBox->SetValue(configData.showCamera); for (int i = 0; i < modelVec.size(); i++) { if (modelVec[i] == configData.model) { modelNameChoice->SetSelection(i); @@ -105,6 +109,7 @@ void ConfigurationFrame::OnApply(wxCommandEvent& event) { std::ofstream configFile; configFile.open(prefixConfig + "config.toml"); configFile << "use_haar = " << (useHaarCheckBox->GetValue() ? "true" : "false") << std::endl; + configFile << "show_camera = " << (showCameraCheckBox->GetValue() ? "true" : "false") << std::endl; // janky edge case lmao // if user did not select any model, don't write the line in the config file! if (modelNameChoice->GetSelection() != wxNOT_FOUND) {