<commit_before># interactive-fluid-demo

In the [NGCM-CDT](http://ngcm.soton.ac.uk/), we spend a lot of time programming complex simulations designed to be run on powerful computers. But you don't need a fast computer or a large, complicated program to model real physics. For example, this fluid physics simulation is only about 150 lines of Python code and can be run in real time on a modest single core computer.

## Project Aim

The aim of this project is to create an engaging, interactive demonstration of the kinds of simulations we develop as part of the [NGCM-CDT](http://ngcm.soton.ac.uk/). The basic concept is to combine real-time simulations with live video so that participants can interact with the simulation directly. It was inspired by the Lego(tm) Fluid Dynamics idea suggested at the 2017 NGCM outreach workshop. The ultimate goal is to create an easy to setup, maintain and develop demo that can be an ongoing part of the NGCM's contribution to the University of Southampton's public outreach (http://www.southampton.ac.uk/per/).

As a proof-of-concept, I have combined a simple real-time 2D fluid dynamics simulation with live webcam footage, using *Python* and a computer vision library, *OpenCV*. This can be interacted with directly and simultaneously used to examine the aerodynamics of any object (like a car built from Lego(tm)) placed in front of the camera.

[![FluidDemo](https://github.com/ngcm/interactive-fluid-demo/blob/master/FluidDemo.png)](https://github.com/ngcm/interactive-fluid-demo/blob/master/FluidDemo.webm)


![FluidDemo](https://github.com/ngcm/interactive-fluid-demo/blob/master/FluidDemoDebug.png)

Possible improvements;
* The model is very rough, and does not handle boundaries very well.
* Replace the model entirely (SPH), as this one tends to soften too much.
* Improve the subject/background separation, perhaps using *OpenCV*'s image processing (chromakey?)

## VirtualBox

I currently develop inside a VM. If doing the same, make sure to install the [VirtualBox 5.1.14 Oracle VM VirtualBox Extension Pack](https://www.virtualbox.org/wiki/Downloads) to get access to the host webcam from the guest VM. Then you should be able to enable the webcam from the `Devices` menu.

## OpenCV

*OpenCV* is an open source computer vision library. At present it's only used to get data from the webcam, superimpose some images, and render an output window. It is also a little tricky to install. An alternative may be warranted if this makes it difficult for people to collaborate. I'm sticking with it for now as I have not found a suitable alternative and the computer vision, image processing and GUI functions may prove useful to the project as it develops.

### Installation via pre-built packages (Updated 03/03/2017)

As *OpenCV* is quite picky, I found it best to use a *Python* environment (i.e. *Conda*).

If you are on a Mac, then the conda-forge packages work fine (thanks [ryanpepper](https://github.com/ryanpepper)). Install *OpenCV* to an environment using the following;
```
conda create -n opencv -c conda-forge opencv numba
```

If you are using Ubuntu 16.04, then the following will work;
```
conda create -n opencv -c menpo opencv3 ffmpeg numba
```<commit_msg>embed video?<commit_after># interactive-fluid-demo

In the [NGCM-CDT](http://ngcm.soton.ac.uk/), we spend a lot of time programming complex simulations designed to be run on powerful computers. But you don't need a fast computer or a large, complicated program to model real physics. For example, this fluid physics simulation is only about 150 lines of Python code and can be run in real time on a modest single core computer.

## Project Aim

The aim of this project is to create an engaging, interactive demonstration of the kinds of simulations we develop as part of the [NGCM-CDT](http://ngcm.soton.ac.uk/). The basic concept is to combine real-time simulations with live video so that participants can interact with the simulation directly. It was inspired by the Lego(tm) Fluid Dynamics idea suggested at the 2017 NGCM outreach workshop. The ultimate goal is to create an easy to setup, maintain and develop demo that can be an ongoing part of the NGCM's contribution to the University of Southampton's public outreach (http://www.southampton.ac.uk/per/).

As a proof-of-concept, I have combined a simple real-time 2D fluid dynamics simulation with live webcam footage, using *Python* and a computer vision library, *OpenCV*. This can be interacted with directly and simultaneously used to examine the aerodynamics of any object (like a car built from Lego(tm)) placed in front of the camera.

[![FluidDemo](https://github.com/ngcm/interactive-fluid-demo/blob/master/FluidDemo.png)](https://raw.githubusercontent.com/ngcm/interactive-fluid-demo/blob/master/FluidDemo.webm)


![FluidDemo](https://github.com/ngcm/interactive-fluid-demo/blob/master/FluidDemoDebug.png)

Possible improvements;
* The model is very rough, and does not handle boundaries very well.
* Replace the model entirely (SPH), as this one tends to soften too much.
* Improve the subject/background separation, perhaps using *OpenCV*'s image processing (chromakey?)

## VirtualBox

I currently develop inside a VM. If doing the same, make sure to install the [VirtualBox 5.1.14 Oracle VM VirtualBox Extension Pack](https://www.virtualbox.org/wiki/Downloads) to get access to the host webcam from the guest VM. Then you should be able to enable the webcam from the `Devices` menu.

## OpenCV

*OpenCV* is an open source computer vision library. At present it's only used to get data from the webcam, superimpose some images, and render an output window. It is also a little tricky to install. An alternative may be warranted if this makes it difficult for people to collaborate. I'm sticking with it for now as I have not found a suitable alternative and the computer vision, image processing and GUI functions may prove useful to the project as it develops.

### Installation via pre-built packages (Updated 03/03/2017)

As *OpenCV* is quite picky, I found it best to use a *Python* environment (i.e. *Conda*).

If you are on a Mac, then the conda-forge packages work fine (thanks [ryanpepper](https://github.com/ryanpepper)). Install *OpenCV* to an environment using the following;
```
conda create -n opencv -c conda-forge opencv numba
```

If you are using Ubuntu 16.04, then the following will work;
```
conda create -n opencv -c menpo opencv3 ffmpeg numba
```
{'fraction_non_alphanumeric': 0.07332920792079207, 'fraction_numerical': 0.007735148514851485, 'mean_word_length': 4.530367835757057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1127336', 'n_tokens_mistral': 1833, 'n_tokens_neox': 1682, 'n_words': 903}