Skip to content

Commit

Permalink
Finishing the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
naps62 committed Nov 13, 2020
1 parent e3064e5 commit dbe7a3b
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 12 deletions.
174 changes: 163 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

This is a pet project motivated mostly by my desire to learn both [Rust](https://www.rust-lang.org/) and [FFmpeg](https://ffmpeg.org/)

It grabs an input video feed (most likely your original webcam), and outputs
a transformed video feed.
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.


## Prerequisites

Currently only Linux is supported.
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).

### Linux

Setup [v4l2loopback](https://github.com/umlaeute/v4l2loopback), and create
a virtual webcam, such as:
Expand All @@ -32,17 +38,163 @@ git clone https://github.com/naps62/instacam.git
cd instacam
```

2. Run the Rust daemon:
2. Create a configuration file under `~/.config/instacam/config.json` (changing
each value acording to your system):

```sh
cd daemon
cargo run -- -i /dev/video0 -o /dev/video2 --width 1280 --height 720 --fps 30
```
{
"input": "/dev/video0",
"output": "/dev/video2",
"width": 1280,
"height": 720,
"fps": 30,
"pipeline": [
{
"name": "preview"
}
]
}
```

3. Run the optional Web UI (for real time configuration edits)
3. Start the program:

```sh
cd ui
npm install
npm start
cargo run
```

## Using filters

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"
}
]
```

![Sample](./samples/sample.png)


### Available filters

#### 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",
}
]
```

![Preview](./samples/preview.png)

#### Blur

Blurs the image by a given factor

```
"pipeline": [
{
"name": "blur",
"k": 32
}
]
```

![Blur](./samples/blur.png)

#### Pixelate

Pixelates the image. `k` here is maximum desired number of pixels per
line.

```
"pipeline": [
{
"name": "pixelate",
"k": 128
}
]
```

![Pixelate](./samples/pixelate.png)

#### Sepia

```
"pipeline": [
{
"name": "sepia"
}
]
```

![Sepia](./samples/sepia.png)

#### Sharpen

```
"pipeline": [
{
"name": "sharpen"
}
]
```

![Sharpen](./samples/sharpen.png)

#### Edge Detection

Mostly an experimental filter I was playing with, while learning more about the
OpenCV API

```
"pipeline": [
{
"name": "edges",
"t1": 100,
"t2": 200
}
]
```

![Edges](./samples/edges.png)

#### Background Subtraction

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"
}
]
```

![BgSub](./samples/bgsub.png)

# About

Instacam was authored by [Miguel Palhas](http://naps62.com).

The project is fully open-source. Use it as you wish.
Binary file added samples/bgsub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/blur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/edges.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/pixelate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/sepia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/sharpen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/filters/bgsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct BgSub {

pub fn new(out: Frame) -> BgSub {
let out_size = utils::frame_to_mat(out).size().unwrap();
let subtractor = video::create_background_subtractor_mog2(500, 16.0, true).unwrap();
let subtractor = video::create_background_subtractor_mog2(100, 2.0, false).unwrap();
let fg_mask = unsafe { Mat::new_size(out_size, CV_8UC3).unwrap() };

BgSub {
Expand Down

0 comments on commit dbe7a3b

Please sign in to comment.