From c6426df6960651692323ab6c635adb6f67b77f20 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 22 Jan 2022 22:19:07 +0100 Subject: [PATCH] Allow for per-frame setting of multi-pass processing --- app/calcmask.cc | 4 +++- app/calcmask.h | 3 ++- app/deepseg.cc | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/calcmask.cc b/app/calcmask.cc index 6b2a9e1..1509026 100644 --- a/app/calcmask.cc +++ b/app/calcmask.cc @@ -44,10 +44,12 @@ CalcMask::~CalcMask() { bs_maskgen_delete(maskctx); } -void CalcMask::set_input_frame(cv::Mat &frame) { +void CalcMask::set_input_frame(const cv::Mat &frame, bool multipass) { std::lock_guard hold(lock_frame); *frame_next = frame.clone(); + this->multipass = multipass; + new_frame = true; condition_new_frame.notify_all(); } diff --git a/app/calcmask.h b/app/calcmask.h index 903da07..b80820a 100644 --- a/app/calcmask.h +++ b/app/calcmask.h @@ -18,6 +18,7 @@ enum class thread_state_t { RUNNING, DONE }; class CalcMask final { protected: volatile thread_state_t state; + volatile bool multipass; void *maskctx; timestamp_t t0; @@ -60,6 +61,6 @@ class CalcMask final { CalcMask(const std::string& modelname, size_t threads, size_t width, size_t height); ~CalcMask(); - void set_input_frame(cv::Mat &frame); + void set_input_frame(const cv::Mat &frame, bool multipass); void get_output_mask(cv::Mat &out); }; diff --git a/app/deepseg.cc b/app/deepseg.cc index c8f4ed3..d59e035 100644 --- a/app/deepseg.cc +++ b/app/deepseg.cc @@ -74,6 +74,7 @@ int main(int argc, char* argv[]) try { bool flipHorizontal = false; bool flipVertical = false; + bool multipass = false; std::string vcam = "/dev/video1"; std::string ccam = "/dev/video0"; @@ -95,6 +96,8 @@ int main(int argc, char* argv[]) try { flipHorizontal = !flipHorizontal; } else if (args[arg] == "-V") { flipVertical = !flipVertical; + } else if (args[arg] == "-M") { + multipass = !multipass; } else if (args[arg] == "-v") { if (hasArgument) { vcam = args[++arg]; @@ -187,7 +190,7 @@ int main(int argc, char* argv[]) try { fprintf(stderr, "\n"); fprintf(stderr, "usage:\n"); fprintf(stderr, " backscrub [-?] [-d] [-p] [-c ] [-v ] [-w ] [-h ]\n"); - fprintf(stderr, " [-t ] [-b ] [-m ] [-p ] [-H] [-V]\n"); + fprintf(stderr, " [-t ] [-b ] [-m ] [-p ] [-H] [-V] [-M]\n"); fprintf(stderr, "\n"); fprintf(stderr, "-? Display this usage information\n"); fprintf(stderr, "-d Increase debug level\n"); @@ -206,6 +209,7 @@ int main(int argc, char* argv[]) try { fprintf(stderr, "-p bgblur: Blur the video background\n"); fprintf(stderr, "-H Mirror the output horizontally\n"); fprintf(stderr, "-V Mirror the output vertically\n"); + fprintf(stderr, "-M Activate multi-pass filtering (for aspect ration mismatch)\n"); exit(1); } @@ -227,6 +231,7 @@ int main(int argc, char* argv[]) try { printf("height: %zu\n", height); printf("flip_h: %s\n", flipHorizontal ? "yes" : "no"); printf("flip_v: %s\n", flipVertical ? "yes" : "no"); + printf("multi: %s\n", multipass ? "yes" : "no"); printf("threads:%zu\n", threads); printf("back: %s\n", s_backg ? s_backg.value().c_str() : "(none)"); printf("model: %s\n\n", s_model ? s_model.value().c_str() : "(none)"); @@ -296,7 +301,7 @@ int main(int argc, char* argv[]) try { // copy new frame to buffer cap.retrieve(raw); ti.retrns = timestamp(); - ai.set_input_frame(raw); + ai.set_input_frame(raw, multipass); ti.copyns = timestamp(); if (raw.rows == 0 || raw.cols == 0) @@ -416,6 +421,7 @@ int main(int argc, char* argv[]) try { " f: toggle FPS display on/off", " b: toggle background display on/off", " m: toggle mask display on/off", + " M: toggle multi-pass processing on/off", " ?: toggle this help text on/off" }; @@ -485,6 +491,10 @@ int main(int argc, char* argv[]) try { showMask = !showMask; break; + case 'M': + multipass = !multipass; + break; + case '?': showHelp = !showHelp; break;