Blog: Extendable Webcam Customisation with Python

20 Feb 2022

Example Pixel Filter.

Discord for Linux currently doesn’t support background blurring, which is a good excuse for a side project.

So, after diving into a rabbit hole filled with OpenCV and virtual devices I’ve emerged with a solution.

CustomCam is a Python framework that makes it super easy to build and apply your own video effects to a live webcam.

Try it out now with pip install CustomCam.

Filter-First Framework

Most OpenCV-based blogs & tutorials talk a lot about webcam capture and image manipulation but don’t concern themselves with outputting those modified frames elsewhere (i.e. to Discord or Zoom). CustomCam aims to fill this gap by implementing a framework that allows users to focus on building filters not infrastructure.

You can think of the CustomCam pipeline as the following three components:

CustomCam Workflow.

  1. Input: Frames are received from your regular webcam
  2. Filter: Video effects are applied to each frame
    • The active filter can be changed mid-stream from the command line
  3. Output: Modified frames are passed to a virtual output device

Filter Buffet

Filter Effect Notes
NoFilter Removes filter  
Gray Super simple grayscale  
Sepia Standard sepia effect Based on a gist by FilipeChagasDev
Segment Silhouette-based background-blurring Utilises MediaPipe’s Selfie Segmentation. Definitely the best approach for background-blurring.
Pixel Silhouette-based foreground-blurring Utilises MediaPipe’s Selfie Segmentation. Essentially an inversion of Segment.
BlurSat Saturation-based background blurring Based on blog by PythonWithRune. I wasn’t able to effectively optimise this for a diversity of frames.
BlurBox Facial recognition-based background blurring Based on blog by data-stats. This works fairly well, but the facial detection is a bit rough. Rotating your head breaks it.
Frame Facial recognition-based Essentially a debug version of BlurBox. Adds a green box around faces.

Creating your own filters

CustomCam is built to be customisable, so it’s super simple to add your own.

Simply create a new class in filters.py that:

Filter class names are automatically detected on launch, the class name will become its run command.