diff --git a/Application/src/commons/common/video/GenericVideo.cpp b/Application/src/commons/common/video/GenericVideo.cpp index fbfcc0c33dca106437f17aa10b2bc5decf77225a..c3078adaba07952b2170c53cad04b4200695dd39 100644 --- a/Application/src/commons/common/video/GenericVideo.cpp +++ b/Application/src/commons/common/video/GenericVideo.cpp @@ -1,6 +1,7 @@ #include "GenericVideo.h" #include <misc/Timer.h> #include <misc/GlobalSettings.h> +#include <grabber/default_config.h> using namespace cmn; @@ -111,8 +112,8 @@ void GenericVideo::generate_average(cv::Mat &av, uint64_t frameIndex) { gpuMat f, ref; std::vector<gpuMat> vec; - std::string averaging_method = GlobalSettings::has("averaging_method") ? utils::lowercase(SETTING(averaging_method).value<std::string>()) : "mean"; - bool use_mean = averaging_method != "max" && averaging_method != "min"; + auto averaging_method = GlobalSettings::has("averaging_method") ? SETTING(averaging_method).value<grab::averaging_method_t::Class>() : grab::averaging_method_t::mean; + bool use_mean = averaging_method != grab::averaging_method_t::max && averaging_method != grab::averaging_method_t::min; Debug("Use max: %d", !use_mean); if(average.empty() || average.cols != size().width || average.rows != size().height) { @@ -146,7 +147,7 @@ void GenericVideo::generate_average(cv::Mat &av, uint64_t frameIndex) { } else { ref.copyTo(local); - if(averaging_method == "max") + if(averaging_method == grab::averaging_method_t::max) av = cv::max(av, local); else av = cv::min(av, local); diff --git a/Application/src/grabber/default_config.cpp b/Application/src/grabber/default_config.cpp index 0a2afc6a6ab226c42b9d5e7eaa4646284816902e..a52e473996863cfafe51a1261eae9d52cd0098b3 100644 --- a/Application/src/grabber/default_config.cpp +++ b/Application/src/grabber/default_config.cpp @@ -12,6 +12,8 @@ namespace grab { + ENUM_CLASS_DOCS(averaging_method_t, "Mean", "Mode", "Min", "Max"); + #ifndef WIN32 struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; @@ -118,7 +120,7 @@ namespace default_config { CONFIG("correct_luminance", false, "Attempts to correct for badly lit backgrounds by evening out luminance across the background.", STARTUP); CONFIG("equalize_histogram", false, "Equalizes the histogram of the image before thresholding and background subtraction."); CONFIG("quit_after_average", false, "If set to true, this will terminate the program directly after generating (or loading) a background average image.", STARTUP); - CONFIG("averaging_method", std::string("mean"), "This can be either 'mean', 'mode', 'min' or 'max'. All accumulated background images (to be used for generating an average background) will be combined using the max or mean function."); + CONFIG("averaging_method", averaging_method_t::mean, "Determines the way in which the background samples are combined. The background generated in the process will be used to subtract background from foreground objects during conversion."); CONFIG("average_samples", int(100), "Number of samples taken to generate an average image. Usually has to be less if `average_method` is set to max."); CONFIG("reset_average", false, "If set to true, the average will be regenerated using the live stream of images (video or camera)."); diff --git a/Application/src/grabber/default_config.h b/Application/src/grabber/default_config.h index ac98d9a00b972f6fdb9bddb3998c8a07fb627494..767f4b78e26ab559089f56b22570c0558db35d0e 100644 --- a/Application/src/grabber/default_config.h +++ b/Application/src/grabber/default_config.h @@ -4,6 +4,9 @@ #include <misc/GlobalSettings.h> namespace grab { + ENUM_CLASS(averaging_method_t, mean, mode, max, min); + ENUM_CLASS_HAS_DOCS(averaging_method_t); + namespace default_config { using namespace cmn; diff --git a/Application/src/grabber/grabber.cpp b/Application/src/grabber/grabber.cpp index 318570aa3e65d557005f9c8643c12ad2e344c27a..b186cf52aa6aea2bc8821286f60b5827ac24d16b 100644 --- a/Application/src/grabber/grabber.cpp +++ b/Application/src/grabber/grabber.cpp @@ -791,8 +791,8 @@ bool FrameGrabber::add_image_to_average(const Image_t& current) { _current_image = nullptr; } - static std::string averaging_method = GlobalSettings::has("averaging_method") ? utils::lowercase(SETTING(averaging_method).value<std::string>()) : "mean"; - static bool use_mean = averaging_method != "max" && averaging_method != "min"; + static auto averaging_method = GlobalSettings::has("averaging_method") ? utils::lowercase(SETTING(averaging_method).value<grab::averaging_method_t::Class>()) : grab::averaging_method_t::mean; + static bool use_mean = averaging_method != grab::averaging_method_t::max && averaging_method != grab::averaging_method_t::max; static gpuMat empty_image; if(empty_image.empty()) empty_image = gpuMat::zeros(_cropped_size.height, _cropped_size.width, CV_8UC1); @@ -815,9 +815,9 @@ bool FrameGrabber::add_image_to_average(const Image_t& current) { _current_average.copyTo(local_av); empty_image.copyTo(local); - if(averaging_method == "max") + if(averaging_method == grab::averaging_method_t::max) _current_average = cv::max(local, local_av); - else if(averaging_method == "min") + else if(averaging_method == grab::averaging_method_t::min) _current_average = cv::min(local, local_av); } } diff --git a/Application/src/tracker/VideoOpener.cpp b/Application/src/tracker/VideoOpener.cpp index 807031e3c732d73fb84bb914f8ae6505a20e6d30..0a03eaa3bc513bd1d277c7786a0994c34ff6cbc7 100644 --- a/Application/src/tracker/VideoOpener.cpp +++ b/Application/src/tracker/VideoOpener.cpp @@ -37,6 +37,7 @@ VideoOpener::VideoOpener() { _raw_info->set_policy(gui::VerticalLayout::LEFT); _screenshot = std::make_shared<gui::ExternalImage>(); _text_fields.clear(); + _text_fields["output_name"] = LabeledField("output name"); _text_fields["output_name"]._text_field->set_text(TEMP_SETTING(output_name).get().valueString()); _text_fields["output_name"]._text_field->on_text_changed([this](){ @@ -54,11 +55,10 @@ VideoOpener::VideoOpener() { if(_buffer) { _buffer->_threshold = number; } - - } catch(...) { - - } + + } catch(...) {} }); + _text_fields["average_samples"] = LabeledField("average_samples"); _text_fields["average_samples"]._text_field->set_text(TEMP_SETTING(average_samples).get().valueString()); _text_fields["average_samples"]._text_field->on_text_changed([this](){ @@ -69,9 +69,23 @@ VideoOpener::VideoOpener() { if(_buffer) { _buffer->restart_background(); } - } catch(...) { - + + } catch(...) {} + }); + + _text_fields["averaging_method"] = LabeledField("averaging_method"); + _text_fields["averaging_method"]._text_field->set_text(TEMP_SETTING(average_samples).get().valueString()); + _text_fields["averaging_method"]._text_field->on_text_changed([this]() { + try { + auto number = Meta::fromStr<grab::averaging_method_t::Class>(_text_fields["averaging_method"]._text_field->text()); + TEMP_SETTING(average_samples) = number; + + if (_buffer) { + _buffer->restart_background(); + } + } + catch (...) {} }); std::vector<Layout::Ptr> objects{}; diff --git a/Application/src/tracker/VideoOpener.h b/Application/src/tracker/VideoOpener.h index a680da7adf37213736df4e6b591d08952db60ecd..70d95726189b1412c8dc923e190ba7e5b16ed808 100644 --- a/Application/src/tracker/VideoOpener.h +++ b/Application/src/tracker/VideoOpener.h @@ -31,7 +31,7 @@ public: cv::Mat _local; gpuMat _flt, _img, _mask, _diff, _alpha, _output; cv::Mat _accumulator, _background_copy; - bool _set_copy_background; + bool _set_copy_background = false; uint64_t _background_samples = 0; uint64_t _background_video_index = 0; @@ -42,7 +42,7 @@ public: std::atomic<bool> _terminate = false, _terminate_background = false; std::atomic<double> _playback_index = 0; Timer _video_timer; - double _seconds_between_frames; + double _seconds_between_frames = 0; std::atomic<uint32_t> _threshold = 0;