Nimbin[12]?Linux & System / webcam-loopback-manipulation-screensharing-and-stuff / commits / 61bab7f

webcam-loopback-manipulation-screensharing-and-stuff git · main

vcam: v4l2 loopback with overlays, filters, OpenCV and RVM matting

webcam v4l2 opencv onnx c · first commit 2026-06-29 · last commit 2026-11-12 (11 days ago) · synced 1 hour ago · upstream: github.com/nimbin2/Webcam-Filter---ScreenSharing---and-Stuff

C 51.3% C++ 40.7% Markdown 6.9% Makefile 1%
git clone https://git.christianimmanuel.de/linux-system/webcam-loopback-manipulation-screensharing-and-stuff.gitwget https://git.christianimmanuel.de/linux-system/webcam-loopback-manipulation-screensharing-and-stuff/archive/webcam-loopback-manipulation-screensharing-and-stuff.tar.gz

OpenCV 5 AND AI lol

Christian Immanuel · 2026-07-08 07:29 · 61bab7f79c5fcf4840b568d6e6dbee0c5df3c2e8

 include/vcam_cv.h |  2 +-
 scripts/vcam-tune |  6 +++++-
 src/filter.c      |  2 +-
 src/ipc.c         |  4 +++-
 src/opencv_fx.cpp | 17 ++++++++++++-----
 src/opencv_stub.c |  4 ++--
 6 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/include/vcam_cv.h b/include/vcam_cv.h
index c737bc7..b9b53fe 100644
--- a/include/vcam_cv.h
+++ b/include/vcam_cv.h
@@ -109,7 +109,7 @@ void cv_fx_face(unsigned char *data, int w, int h, int stride,
  *   2 = replace background with a moving color gradient
  * Needs human_segmentation_pphumanseg_2023mar.onnx. */
 void cv_fx_bgblur(unsigned char *data, int w, int h, int stride,
-                  int mode);
+                  int mode, float edge, float smooth);
 
 /* Live neural style transfer (fast-neural-style, 5 styles).
  *   style: 0=mosaic 1=candy 2=rain-princess 3=udnie 4=pointilism
diff --git a/scripts/vcam-tune b/scripts/vcam-tune
index 0e8b6d5..64e1294 100755
--- a/scripts/vcam-tune
+++ b/scripts/vcam-tune
@@ -84,7 +84,7 @@ n_params_for() {
         neon|kaleidoscope|wave) echo 4 ;;
         chromashift|glitch|vignette|feedback|ripples|life|plasma) echo 3 ;;
         swirl|pinch|bulge|shuffle|rain|lightpaint|hologram|duotone|spotlight) echo 3 ;;
-        predator|liquid|clones|styleai) echo 3 ;;
+        predator|liquid|clones|styleai|personfx) echo 3 ;;
         contour|fireworks|infinity|moire) echo 2 ;;
         cartoon|drift|slitscan|mosh|zoompulse|oilslick|ascii|sketch) echo 2 ;;
         shards|portal|heattrail|wormhole|magnet|nightvision|badtv|ghosts) echo 2 ;;
@@ -214,6 +214,8 @@ param_label() {
         bgsub:1) echo "sens" ;;
         facefx:1) echo "mode" ;;
         personfx:1) echo "mode" ;;
+        personfx:2) echo "edge" ;;
+        personfx:3) echo "smooth" ;;
         styleai:1) echo "style" ;;
         styleai:2) echo "blend" ;;
         styleai:3) echo "size" ;;
@@ -291,6 +293,8 @@ param_step() {
         nightvision:2)  echo 5 ;;
         badtv:2)        echo 0.5 ;;
         ghosts:2)       echo 0.5 ;;
+        personfx:2)     echo 0.02 ;;
+        personfx:3)     echo 0.05 ;;
         styleai:2)      echo 0.05 ;;
         styleai:3)      echo 32 ;;
         moodfx:2)       echo 0.1 ;;
diff --git a/src/filter.c b/src/filter.c
index 7b5442e..d593d40 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -5903,7 +5903,7 @@ void filter_chain_apply(FilterChain *fc, Frame *frame)
         case FX_CV_FLOW:      cv_fx_flow   (frame->data, frame->width, frame->height, frame->stride, f->param); break;
         case FX_CV_BGSUB:     cv_fx_bgsub  (frame->data, frame->width, frame->height, frame->stride, f->param); break;
         case FX_CV_FACE:      cv_fx_face   (frame->data, frame->width, frame->height, frame->stride, (int)f->param); break;
-        case FX_CV_PERSON:    cv_fx_bgblur (frame->data, frame->width, frame->height, frame->stride, (int)f->param); break;
+        case FX_CV_PERSON:    cv_fx_bgblur (frame->data, frame->width, frame->height, frame->stride, (int)f->param, f->param2, f->param3); break;
         case FX_CV_STYLE:     cv_fx_style  (frame->data, frame->width, frame->height, frame->stride, (int)f->param, f->param2, f->param3); break;
         case FX_CV_MOOD:      cv_fx_mood   (frame->data, frame->width, frame->height, frame->stride, (int)f->param, f->param2); break;
         case FX_CV_PAINT:     cv_fx_paintflow(frame->data, frame->width, frame->height, frame->stride, f->param, f->param2); break;
diff --git a/src/ipc.c b/src/ipc.c
index ddfc4d0..19b99e4 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -310,7 +310,9 @@ static void handle_command(int client_fd, char *line, OverlayRegistry *reg)
             send_line(client_fd, "OK   opticalflow <mix>             motion visualized as flowing color");
             send_line(client_fd, "OK   bgsub <sensitivity>           moving foreground vivid, static background dimmed");
             send_line(client_fd, "OK   facefx <mode>                 YuNet faces: 0=blur 1=ring+dots 2=googly-eyes (needs model)");
-            send_line(client_fd, "OK   personfx <mode>               person seg (needs model): 0=blur-bg 1=spotlight 2=gradient-bg");
+            send_line(client_fd, "OK   personfx <mode> [<edge> <smooth>] person seg (needs model): 0=blur-bg 1=spotlight 2=gradient-bg");
+            send_line(client_fd, "OK                                    edge 0.05..0.5 (lower=more hair, higher=tighter cut, def 0.22)");
+            send_line(client_fd, "OK                                    smooth 0.4..1 (mask responsiveness, 1=instant, def 0.8)");
             send_line(client_fd, "OK                                    3=YOUR-image-bg (filter bgimage <path>) 4=INVISIBILITY CLOAK 5=neon person");
             send_line(client_fd, "OK   styleai <style> [<blend> <size>] LIVE NEURAL STYLE TRANSFER: 0=mosaic 1=candy 2=rain-princess 3=udnie 4=pointilism");
             send_line(client_fd, "OK                                    blend 0..1 mixes with original; size 96..384 = quality vs speed");
diff --git a/src/opencv_fx.cpp b/src/opencv_fx.cpp
index 6b1f4d2..371a377 100644
--- a/src/opencv_fx.cpp
+++ b/src/opencv_fx.cpp
@@ -355,7 +355,7 @@ bool ensure_seg()
  * Returns a full-frame CV_8U mask (255 = person) or empty on failure.
  * Preprocessing: (pixel/255 - 0.5)/0.5  ==  pixel/127.5 - 1, which
  * blobFromImage produces as scalefactor=1/127.5, mean=127.5. */
-cv::Mat seg_infer(const cv::Mat &bgr, const cv::Rect &body)
+cv::Mat seg_infer(const cv::Mat &bgr, const cv::Rect &body, float edge)
 {
     /* Segment only the body ROI (from the face detector), LETTERBOXED
      * into the square input instead of aspect-squished. The person now
@@ -428,7 +428,7 @@ cv::Mat seg_infer(const cv::Mat &bgr, const cv::Rect &body)
      * 0.6-0.8, which — used directly as alpha — rendered the person
      * translucent. Remap 0.30..0.60 -> 0..1 (smoothstep): confident
      * regions become solid, the feather survives only at true edges. */
-    full = (full - 0.22) * (1.0 / 0.33);
+    full = (full - edge) * (1.0 / 0.33);
     cv::min(full, 1.0, full);
     cv::max(full, 0.0, full);
     cv::Mat f2 = full.mul(full);
@@ -802,9 +802,16 @@ void cv_fx_face(unsigned char *data, int w, int h, int stride, int mode)
     }
 }
 
-void cv_fx_bgblur(unsigned char *data, int w, int h, int stride, int mode)
+void cv_fx_bgblur(unsigned char *data, int w, int h, int stride, int mode,
+                  float edge, float smooth)
 {
     if (!data || w < 16 || h < 16) return;
+    if (edge <= 0.0f) edge = 0.22f;          /* mask generosity: lower = more hair */
+    if (edge < 0.05f) edge = 0.05f;
+    if (edge > 0.50f) edge = 0.50f;
+    if (smooth <= 0.0f) smooth = 0.80f;      /* responsiveness: 1 = instant */
+    if (smooth < 0.40f) smooth = 0.40f;
+    if (smooth > 1.00f) smooth = 1.00f;
     try {
         std::lock_guard<std::mutex> lock(g_seg.mtx);
         cv::Mat img = wrap_bgr(data, w, h, stride);
@@ -849,10 +856,10 @@ void cv_fx_bgblur(unsigned char *data, int w, int h, int stride, int mode)
                     }
                 }
             }
-            cv::Mat m = seg_infer(img, body);
+            cv::Mat m = seg_infer(img, body, edge);
             if (!m.empty()) {
                 if (!g_seg.mask.empty() && g_seg.mask.size() == m.size())
-                    cv::addWeighted(m, 0.80, g_seg.mask, 0.20, 0.0, g_seg.mask);
+                    cv::addWeighted(m, smooth, g_seg.mask, 1.0 - smooth, 0.0, g_seg.mask);
                 else
                     m.copyTo(g_seg.mask);
             }
diff --git a/src/opencv_stub.c b/src/opencv_stub.c
index 8024fae..f1d54d9 100644
--- a/src/opencv_stub.c
+++ b/src/opencv_stub.c
@@ -45,8 +45,8 @@ void cv_fx_bgsub(unsigned char *d, int w, int h, int s, float x)
 void cv_fx_face(unsigned char *d, int w, int h, int s, int m)
 { (void)d; (void)w; (void)h; (void)s; (void)m; }
 
-void cv_fx_bgblur(unsigned char *d, int w, int h, int s, int m)
-{ (void)d; (void)w; (void)h; (void)s; (void)m; }
+void cv_fx_bgblur(unsigned char *d, int w, int h, int s, int m, float e, float sm)
+{ (void)d; (void)w; (void)h; (void)s; (void)m; (void)e; (void)sm; }
 
 void cv_fx_style(unsigned char *d, int w, int h, int s, int st, float b, float sz)
 { (void)d; (void)w; (void)h; (void)s; (void)st; (void)b; (void)sz; }