Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-pass processing #135

Draft
wants to merge 5 commits into
base: experimental
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/calcmask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,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 @@ -16,6 +16,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 @@ -58,6 +59,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 @@ -68,6 +68,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 @@ -89,6 +90,8 @@ int main(int argc, char* argv[]) try {
flipHorizontal = !flipHorizontal;
} else if (args[arg] == "-V") {
flipVertical = !flipVertical;
} else if (args[arg] == "-M") {
multipass = !multipass;
phlash marked this conversation as resolved.
Show resolved Hide resolved
} else if (args[arg] == "-v") {
if (hasArgument) {
vcam = args[++arg];
Expand Down Expand Up @@ -181,7 +184,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 @@ -200,6 +203,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 ratio mismatch)\n");
exit(1);
}

Expand All @@ -221,6 +225,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 @@ -290,7 +295,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 @@ -410,6 +415,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 @@ -479,6 +485,10 @@ int main(int argc, char* argv[]) try {
showMask = !showMask;
break;

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

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