Skip to content

Commit

Permalink
Allow for per-frame setting of multi-pass processing
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBE committed Jan 24, 2022
1 parent 2c38ad6 commit c6426df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/calcmask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> hold(lock_frame);

*frame_next = frame.clone();
this->multipass = multipass;

new_frame = true;
condition_new_frame.notify_all();
}
Expand Down
3 changes: 2 additions & 1 deletion app/calcmask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
14 changes: 12 additions & 2 deletions app/deepseg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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];
Expand Down Expand Up @@ -187,7 +190,7 @@ int main(int argc, char* argv[]) try {
fprintf(stderr, "\n");
fprintf(stderr, "usage:\n");
fprintf(stderr, " backscrub [-?] [-d] [-p] [-c <capture>] [-v <virtual>] [-w <width>] [-h <height>]\n");
fprintf(stderr, " [-t <threads>] [-b <background>] [-m <modell>] [-p <option:value>] [-H] [-V]\n");
fprintf(stderr, " [-t <threads>] [-b <background>] [-m <modell>] [-p <option:value>] [-H] [-V] [-M]\n");
fprintf(stderr, "\n");
fprintf(stderr, "-? Display this usage information\n");
fprintf(stderr, "-d Increase debug level\n");
Expand All @@ -206,6 +209,7 @@ int main(int argc, char* argv[]) try {
fprintf(stderr, "-p bgblur:<strength> 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);
}

Expand All @@ -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)");
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
};

Expand Down Expand Up @@ -485,6 +491,10 @@ int main(int argc, char* argv[]) try {
showMask = !showMask;
break;

case 'M':
multipass = !multipass;
break;

case '?':
showHelp = !showHelp;
break;
Expand Down

0 comments on commit c6426df

Please sign in to comment.