Wednesday, March 21, 2012

OpenCV Processing

I discovered something thats quite annoying when working with OpenCV and Processing, so I'll share here. Hopefully you can get it running without searching around.

To get OpenCV working with Processing, just follow the steps on then OpenCV website.

Then use the example given on Sparkfun, to get Face Tracking working. But, if you're like me, you'll probably run into the same problem. You try to compile, and Processing throws an error: 

Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: 

This has to do with the following line of code:

opencv.capture( width, height );

Solve this error by copying the following files into your System32 folder.


If copying them into the System32 folder doesnt work, copy the files into the WINDOWS folder. Thats it!

Note: Heres the forum thread where I discovered this solution.

Your example should work without you having to reload Processing. If you dont get any video feed, then the problem is with your Camera setup, not with Processing or OpenCV. In the past, I had a Logitech camera work on the fly (thats using Windows 7, x64bit), but now Im working with a Microsoft camera that I havent figured out how to get working. I'll post when I do.

Monday, March 12, 2012

Smart Camera

I think its about time for an update.

So this last month I was working on building a smart camera that tracks motion using Open CV, and determines range/speed for threat detection. I got the enclosure design down with Pro-E, so it was just a matter of getting electronics, and putting something together.

I had decided that a laser rangefinder was the best method to get the distance/speed measurements that I needed (range of 50-100ft). My budget for this camera was only a few hundred dollars, so was I in for a surprise. The laser rangefinding component is about $500 on its own. So I thought, maybe I can just build this thing myself, and cut out the middle-man who builds it.

I'll save you the trouble of researching it. Theres several things you'll need. First off is an Avalanche Photodiode. Those go for about 50 bucks, but since they require a few hundred volts to operate, you'll need a power circuit to supply that, and an amplifier circuit to read the data coming off. Thats not exactly easy, or cheap. Second is the laser: you'll need a solid-state hybrid pulse laser that gives you a 14W pulse every 200ns (I think). Those run for about 50 bucks also, but are a bit hard to acquire, because they are sold in Germany, and have a min order of a couple thousand. Then you'll need power, amplifier and sync circuits to power, run and synchronize the laser to the photodiode. You'll probably have to do all this on an ARM or an FPGA since calculations happen pretty fast for this thing to be accurate. So thats another 80 bucks for a BeagleBone. The custom laser/detector optics will run you for about a 100-200 bucks easy. So it all adds up to a cool $500. You can save yourself the trouble of custom making it, and order a prototype laser rangefinder from Lightware. So that wraps up the laser range finder.

Next up is the Pan/Tilt OpenCV camera. Its rather easy to make one. In fact theres a tutorial on Sparkfun to do it, but I ramped up the design a little bit. Instead of cheap analog servo's, I decided to use digital servos with metal gears (from Servocity). For the pan/tilt hardware, I decided on Servocity's SPT200. For a camera, I planned to use a cheap $40 Microsoft HD webcam. So all in all, maybe about $150 for the pan/tilt camera.

Lastly, I had to get some kind of water tight enclosure built for this thing. Since I had a design drawn in Pro-E, its simply a matter of getting it all 3D printed somewhere, and throwing hardware in it. That'll probably run me for another 200 bucks or so.

So, a cheap, couple hundred dollar project turned into a thousand dollar behemoth. Ive decided not to take up this challenge at the moment while looking for a job. Its just not practical.

What I have decided to do in the meantime, is get my Gas Monitoring system working. In fact I managed to get the MQ-6 LPG-LNG Gas Alarm working yesterday. The code I used was originally meant for Sandbox Electronics' LPG Gas Sensor Module, however, I changed a bit of it and added my alarm code. Now it triggers an alarm every time the gas level goes higher than a user threshold (thats currently set in the code, but later I'll use an interface to have a user type it in). I know thats rather easy, but setting up the calibration of the sensor isnt easy, so I had to dig around until I found someone who had done it, to make my life easier.

Im working on the MQ-7 CO Gas Alarm right now, and thats just a variation of the previous alarm. Only difference is the code has to adjust the power of the sensor heater via PWM to match the specs in the datasheet. 

Well thats all for now. Peace Out.