Raspberry Pi Motion tracking in Python Pt. 2

Not all USB webcams are created equal.

OK, this is obvious, cheap things are on average crappier than expensive things but the difference here is really marked.

I've built one of these cheap '6 LED' webcams into my project and until I got the code sorted wasn't that worried it would only do 8 FPS.

I was kind of expecting an imperfect image from a cheap webcam but now my code is good the difference in performance is really noticeable.

Knowing I can hit 18-20 FPS or higher with the MS Xbox 360 Live Camera I picked up later is really annoying as the basis of the project is mostly physically built and I thought I could just concentrate on the coding.

The Xbox camera also does a much sharper image with more consistent colour balance and contrast. Which is important as if the camera jerkily changes colour/contrast of the output as the cheaper one is prone to, this gets detected as motion.

None of this is overly surprising as the Xbox cameras were originally reasonably pricey and MS tend to make nice accessories for their consoles.

So unless I can get to the bottom of the poor performance of the original camera (unlikely) I'm going to have to pull it out and replace it with an Xbox one.

If you're thinking of a webcam based project these Xbox ones are really solidly made and seem to be supported by V4L just fine. More importantly they can be picked up secondhand for £1 from CEX, which is a bargain. So you can order a handful of identical cameras to mess about with and embed in things without worrying about cost much.

The ultimate thing to use is probably the official Pi camera which produces fantastic images. But that's 25x the cost for a bare board you need to make or buy an enclosure for.

Raspberry Pi Motion tracking in Python Pt. 1

My next project involves using a Raspberry Pi to do motion tracking. Not something that is difficult nowadays with well developed libraries for image processing like OpenCV.

What I did discover is that a lot of the example code I found was targetted at more powerful things than the Pi and runs at a snail's pace.
So I took one of these projects as a starting point and after initially trying to slim it down and failing I've started from scratch, taking inspiration from a couple of the examples I found.

I now have some Python/OpenCV code that will do >25fps from a USB webcam on the Pi if you keep the source image small.
Here's some of the output of this, with the object outlined and the green blobs showing the track it has moved through. My next step is to do some anticipation so it can track ahead of the object.

Ideally you need to overclock the Pi for best performance but if you only use a 160x120 source image it's still fine at 700Mhz.
I've ordered a Beaglebone Black for this project by way of an upgrade, but for now I'll stick with the Pi as I've managed to squeeze enough performance out of it to be going on with.

To keep power use and heat down the script drops the FPS deliberately when nothing is moving and then ramps up when something happens. I'm not sure if this is 100% necessary but it feels like something you should do and the temperature definitely stays down a bit.

RFu Protoyping

Having messed around with my RFu uploading simple sketches to send serial data I really need to start prototyping with it. The board Ciseco sell for this is pretty much bare. Tonight I've added a breadboard and headers so I can start messing around.

First up I think will work on a wireless PIR detector. Basic stuff but I want to work with LLAP a bit so it is 'smart'. This means learning an LLAP address from the hub and storing it in EEPROM, turning power to the PIR detector off and on, being able to sleep for a set amount of time, warn when the battery is going flat and so on. Stuff that should be the foundation for making a network of these things that is controllable and robust rather than just something that blasts data over serial.


I have been doing a lot of faffing around with the Raspberry Pi but they're obviously not the only word in barebones computing.

My brother loaned me a Pandaboard ages ago, finally last night I stuck an Ubuntu image on it and fired it up.

It's obviously got a lot more horsepower than the Pi (Dual core 1Ghz ARM Cortex-A9) but then they are ~£120 vs ~£25.

I've been doing some image processing on the Pi and it groans a bit, only really working acceptably when overclocked. I'll drag my code across to this and see how it does.

PS: "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn"

Angry wasp in a box

The project I should be working on instead of messing around with radios involves a Raspberry Pi and Arduino Nano stuck in this old joystick base and working together.

The Pi could almost certainly do all the work but the Arduino is a very robust way to connect to stuff that is 5V friendly, can source a passable amount of current and it's cheap.

It's quite tight in there and the Pi is overclocked running flat out so gets very hot. Hot enough I think to affect stability as the thing tends to hang, which similar code didn't cause before I crammed it all in there.

This evening I hot glued a small fan to the composite socket just above a CPU heatsink I fitted thinking it would help with this. It does a fantastic job but sounds like there's an angry wasp in there. A VERY angry VERY large wasp, so loud I could hear it downstairs. I was expecting it to be a little noisy but it's so horrendous I've just ripped it out again.

Obviously a larger fan would be less noisy but there's really not much space.

Dangly bits

Today I have been connecting dangly bits to things. First up simple whip aerials to the Ciseco Explorer and Slice of radio. Range indoors isn't as good as I'd hoped, walls really do kill the signal.

Then I added the Pi Noir camera my brother bought me for Christmas to one of my Raspberry Pis. This works beautifully and produces a great image but seems to need a bit of faff to make it work with v4l.

The whole thing, especially the ribbon cable, feels like it won't stand rattling around exposed very well. So I've removed it again and packed it away until I can come up with something to hold it secure and have a bit more time to mess with it.

RFu rescue

If you're thinking of playing with the Ciseco RFu radios I would recommend getting one of these from them at the same time.

Having painted myself into a corner by uploading an stupid sketch that saturates the radio, it was just a case of changing a couple of jumpers, popping the RFu into the socket inside and reprogramming it.

It's only a couple of quid more than their straight USB stick radios but you get yourself a more versatile device. This is doubly so if like me you don't already have a USB FTDI interface.

While the lid's open I may fit an external whip antenna, it seems rude not to.