I need to detect short term horizontal motion for my quadcopter. I'm currently doing that with integrating the accelerometer which works to some extent, but I wondered whether sticking a downward facing RaspiCam under my quad could be used to track motion combined with direction? I'm not using this for long term path tracking - GPS provides a much better solution not relying on integration of the result, just purely to detect (and ultimately correct) movement detected short term. I'm sure it can be done using sequential photographs checking to match up differences, but this sounds like a complex, image processing heavy task unless the GPU is used.

The course motion estimation code recently added to the firmware and a modified raspivid could probably do what you want. You would need to process the CME data to get a general direction of movement, but the amount of data is greatly reduce from having to do it yourself so should be possible on the ARM. This data comes for free from the H264 encoder giving the entire ARM CPU over for processing the results.

Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Thank James, virtually everything you said is new to me, but that's OK, it gives me a direction to dig into which is what I'm looking for.

For others reading this thread, what I'm after is virtually the same as how an optical mouse works, but lighting is ambient - in fact previous revisions of one of the devices I listed used an optical mouse sensor! Don't know if that helps open up other solutions?

So I wrote program, which read motion vector data from raspivid and streams it over websocket to be interpreted (https://github.com/elhigu/wsstreamprocessor). Browser reads vector data from websocket and plots motion vector information to screen so that color is selected by vector angle and intensity by vector length.

Main findings about raspivid -x format is described in README.md:

Motion vectors are coming from raspicam in following format:

{
signed char dx; // values seems to be around +- 80
signed char dy; // values seems to be around +-80
signed short sad; // values seems to be around 0..512 little endian
}
Numer of motion vectors can be calculated from your video resolution

var vectorsPerLine = Math.floor(imageWidth/16)+1
var vectorLines = Math.floor(imageHeight/16)+1
So for 1920x1080 FullHD video there are 121x68 vectors. First vector in frame is from bottom-left corner.