Filters for your webcam
This is a pet project motivated mostly by my desire to learn both Rust and FFmpeg
It grabs an input video feed (most likely your original webcam, but any video source should work, in theory), and outputs a transformed video feed.
You need to create a virtual camera device on your system. Currently, I only know how to do this on Linux (instructions below).
If an equivalent tool exists for other systems, there should be no other major blockers to getting this to work (both FFmpeg and Rust are widely available in most systems).
Setup v4l2loopback, and create a virtual webcam, such as:
sudo modprobe v4l2loopback devices=1 video_nr=2 card_label="Instacam" exclusive_caps=1
On my machine, this creates a /dev/video2
device. Depending on how many you
already have, yours might be named differently.
- Clone the repo
# clone the repo
git clone https://github.com/naps62/instacam.git
cd instacam
- Create a configuration file under
~/.config/instacam/config.json
(changing each value acording to your system):
{
"input": "/dev/video0",
"output": "/dev/video2",
"width": 1280,
"height": 720,
"fps": 30,
"pipeline": [
{
"name": "preview"
}
]
}
- Start the program:
cargo run
After the initial setup, filters are configured mostly through the pipeline
of
the config file. You can compose the multiple existing filters, and the final
image will be output to your output
device.
For instance, the following pipeline:
"pipeline": [
{
"name": "pixelate",
"k": 64
},
{
"name": "sharpen"
},
{
"name": "preview"
}
]
Does not alter the image, but renders the current frame in a window, allow you to see the result in different stages of the pipeline.
"pipeline": [
{
"name": "preview",
}
]
Blurs the image by a given factor
"pipeline": [
{
"name": "blur",
"k": 32
}
]
Pixelates the image. k
here is maximum desired number of pixels per
line.
"pipeline": [
{
"name": "pixelate",
"k": 128
}
]
"pipeline": [
{
"name": "sepia"
}
]
"pipeline": [
{
"name": "sharpen"
}
]
Mostly an experimental filter I was playing with, while learning more about the OpenCV API
"pipeline": [
{
"name": "edges",
"t1": 100,
"t2": 200
}
]
Also an experimental filter, with a background subtractor algorithm. This sample image is hurt by my low-quality webcam, as well as the lack of a more prominent foreground in this picture.
"pipeline": [
{
"name": "bgsub"
}
]
Instacam was authored by Miguel Palhas.
The project is fully open-source. Use it as you wish.