Simple Optical Flow

SimpleHead is a simple program that analyzes movement and a few other things in video (offline) or from a camera (real-time). It runs on Macs, and Field can use either its analysis product files or talk to it live. Installation instructions are at the bottom of the page.

Realtime use

Field can initiate a SimpleHead with the following code:

var SimpleHead = Java.type("")

As you can see, Field needs a path to wherever you’ve put the binary that you’ve downloaded. The path is the folder.

Run that (once) and you’ll see something like this:

Those two windows can be safely hidden.

Having started a SimpleHead you can now ask for parts of its analysis: contains the current set of values for the last frame that was analyzed. These include:

Offline use

_.stage.withImageDirectory now looks for .simpleHead files in parallel with it. Given that you can ask a layer for a .head and get the same kind of object as returns for the frame (or mix of frames) that they layer is currently showing. For example, this code here, which combines some standard code for playing out a video on a Stage with some code that draws a line in the direction of motion:

var t = 0

	// play out a video stretched over the whole stage
	var layer = _.stage.withImageSequence("/Users/marc/Documents/Videos/Pexels Videos 1793414.mp4.dir/")

	var f = new FLine().rect(0,0,100,100)



	layer.lines.f = f 
	t = t + 1

	layer.time = 0.2+t/10000.0

	// draw a line from the middle of stage out in the direction of
	// the average flow

	// we need another layer (because we don't want it textured)
	var arrowLayer = _.stage.withName("arrowLayer")
	// a line from 50,50 to 50,50 + average flow
	var arrow = new FLine()
	arrow.lineTo(50 + layer.head.vx*10, 50 + layer.head.vy*10)

	// a bright red line
	arrow.color = vec(1,0,0,1)
	// thats 1 pixel thick
	arrow.thicken = 1
	arrowLayer.lines.arrow = arrow


Installation [Mac Only]

If you want to process your own files, or run SimpleHead in real-time, there’s a three stage process.

Install Homebrew

First you’ll need to install some command line tools called Homebrew. You can read all about that here. Copy and paste this into a new terminal window:

/usr/bin/ruby -e "$(curl -fsSL"

Next enter your password when prompted. That should install Homebrew and the Apple Developer Tools. Don’t, in general, trust websites that download random things to your machines and ask for your password…

Install ffmpeg

Now that you have Homebrew installed you can install other things easily. We need ffmpeg which is a command line program for manipulating video.

brew install ffmpeg

That was easy!

Install SimpleHead

Download SimpleHead. If you are using Safari, get it out of the all-too-special Downloads folder and put it somewhere else (like your desktop).

Offline / analyze a movie

The magic command in the terminal for analyzing a movie, turning it into a .simpleHead file, looks like this:

/Users/loganmediacenter/Desktop/head/simpleHead myAwesomeMovie.mp4 > myAwesomeMovie.simpleHead

You’ll have to stare at that carefully though (like anything else from the command line). There’s three parts — the command simpleHead, your movie file and then the name of your simpleHead file that you want to create, which should be the same name as your .dir directory for Field, but with .simpleHead rather than .dir. One way to make sure you spell everything right is to exploit the fact that you can drag things from the finder into Terminal and have them written out for you. So, drag the simpleHead executable into Terminal, drag your mp4, write the > and so on.