Processing: Interpreting Motion

On GitHub, I stumbled across a repository with updated examples from Daniel Schiffman’s book, Learning Processing. One of the examples found here was one of a basic motion sensor using the camera feed. The basic notion of how it works is that it compares the colours of pixels from the current frame to the previous frame and works out the difference. The difference from all the pixels is summed up to create a value for the total amount of motion seen. The total is divided by the number of pixels to get the average amount of motion which creates a variable which can be used.

In the example the variable is used to change the size of an ellipse in the centre of the screen, but obviously this isn’t very interesting so i experimented with using the variable to control different things. In the log I printed the value for the average motion to get an idea of what the range was. It seemed the value always seemed to stay between 0 & ~25, occasionally going up to 30 if I moved around a lot.

To use this value for certain parameters I created a new float to stored a mapped version of the average motion.

int FILTER = (int) map(avgMotion, 0, 25, 1, 255);

The above line of code maps the value from avgMotion from between 0 and 25 to between 1 and 255, so i could use it to apply a tint to the video feed. When there is more motion the the tint increases from 1 (near black) up to 255 (white, or clear) which make it look as if brightness of the video changes.

[gfycat data_id=”CarefreeCheerfulAntlion”]

I also experimented with using a filters, in this case I tried with a blur, mapping the value to between 0 and 16 for the amount of blur in pixels.

[gfycat data_id=”SaltyElegantChinchilla”]

After experimenting with this example, I found another motion related one which tracked the average area of motion rather than just the amount of motion. The example used an ellipse to show what it interprets as the average area of motion, and if you stayed still and waved your hand it would follow it. Again I wanted to see what I could do with this type of motion interpretation, finding something to change based on location. In the end I came up with the idea of splitting the screen into thirds to display 3 different images based on where the movement was.

To do this I used if statements to compare avgX (the average area of motion x-coordinate) and portions of the width split into thirds. If it fit into the area, a certain image would appear, at a reduced opacity so that the video could still be seen behind.


if (avgX < width/3){
    tint(255, 127); //reduce opacity
  if (avgX < (2*width)/3) {     
if (avgX > width/3) {
      tint(255, 127);
  if (avgX > (2*width)/3) {
    tint(255, 127);

Here is the result of my experimentation:

[gfycat data_id=”WillingGoodnaturedBluebird”]

One obvious limitation of tracking the average area of motion was that if there was movement on both sides of the screen, the average would be somewhere in the middle, limiting the usefulness of its tracking abilities.

I considered what would happen if these were put into the Weymouth House foyer and concluded that they would really be much use. As it is quite a busy space the amount of motion would constantly be quite high, with the odd occasion of it dropping down. As for tracking the area of motion, that isn’t must use either as there would constantly be people walking from either direction during the day, making the tracking pretty pointless. If there was a smaller area with not much traffic passing, these could work a lot better and be developed on, but for now I think more experimentation is needed to find a better direction to head in.


2 thoughts on “Processing: Interpreting Motion

  1. […] it had. My first test was to make an adaptation of my sketch which changed an image based on the average location of movement. To do this, I used a series of if statements just as before to work out which third of the screen […]

  2. Hayley says:

    Very Informative. Good job

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: