Tuesday, August 28, 2012

Summer project

Every summer i have a little free time, some time away from home but always two concerns :

  • keeping the cat alive (i'am pretty sure the cat can survive two weeks on its own, but my wife does not agree).
  • keeping my home safe (i don't have many valuable things, but you know ... the wife)
I found a solution for the first concern but i had a hard time thinking about the second one.
The solution i found is to build my very own home surveillance system ! The feature i want are :
  • free to maintain (no expensive subscritpion)
  • discrete (no big red box to fix up a wall)
  • loud only when usefull (the cat is no burglar)
  • image on demand (of the home and ... the cat)
  • secure 

Free : Internet based, no 3G dongle. I understand that internet is not free but i already have a subscritpion sor no additionnal costs.

Discrete : Must feet in a easy to hide box

Loud only when usefull : hmmm ... I do trust neural network are efficient or detection method can be accurate but none have a 100% detection rate and 0% false positive. So i decided i should rely on the most powerful computing resource ... the human brain ! The principle is the device sends me message whenever a detection/event occur and i have to decide whether to turn the horn on.

Image on demand : I must have a way to request a picture of my living room. I already have a bifferboard (www.bifferos.com) running the mjpeg-streamer software, but its only purpose is to have a view of the cat preferred spot.

The device is based on an ARM9 board i bought in a buying frenzy crisis, and as the project had a two week lead time, i decided to use Python to code the whole thing. The board is a pico-SAM9G45 (http://www.mini-box.com/pico-SAM9G45-X), this board is fairly low cost and is incredibly well built. Its minor drawback is the use of 2mm header for IOs.

my pico-SAM9G45 protected with plexi

I used a PS3Eye camera for the grabbing (low-cost camera for vision, good sensitivity), and added an ultrasonic range finder connected to the board ADC. I also have a pair of truk horn, but did not have the time ot connect them at this moment.

At first i wanted to use twitter to interact with the device but i coudn't get a python twitter library to work with that board (did not want to recompile Angstrom). So i decided to rely on a mail based system. The device uses a mail account it checks periodically to received commands (enclosed in the mail subject) and respond by sending an email to a predifined mail address.

The utrasonic range finder is used to detect a change in the environement.  It is placed aiming a my appartement front door and detects whenever the door is opened. When this happens, it takes five pictures and mail them to me. Depending on what i see i can then decide to call the police. The nice thing is that, even if the burglars detect my device they cannot erase the pictures.

I did a first test of the device over a week and the device failed after two days,  a cron job was restarting the device every two days but the device kept failing. When i went back i discovered that i plugged the ethernet jack into the TV port of my router ... A second test over two weeks worked better. I had changed the cron job to restart the device everyday but after some day the device was sending blank image after 10pm ... As my appartement can get very hot i assume that the PS3Eye failed maybe due to the temperature. I still need to do a software fix for this (reboot when camera fails).

A last step is to enclose the device and camera in a box (i have a nice wood box) and had the truck horns. I also want to had another camera pointing at my main window and maybe add wireless sensor on windows and door to detect intrusion.




Sunday, August 26, 2012

Vision processing on FPGA (part 1)

A while ago i started working with openCV to design a simple ball tracking robot. The robot was based on a beagleboard (www.beagleboard.org) and a PS3 eye camera. The openCV code was simple but was the tracking performance was poor and the speed was disapointing (~10FPS on QVGA frames).
Later i started working with FPGA and i thought i would try to do the same task at higher frame rate thanks to the available processing power. Unfortunately FPGA board are expensive and at the time i could not find cheap camera module. Then i bought a papilio (www.gadgetfactory.net)  board and found on ebay cheap camera modules (ov7670 based ~10$).  The main hurdle was that there is no such thing as openCV for FPGAs ...

At the same time i started working with systemc and i liked how easy it was to code and simulate using this tool. I googled a bit to find an open source VHDL to SystemC translator but couldn't find any. In my previsou position i had the oportunity to work with grammar using a tool called AntLR and i heard about a nifty template engine StringTemplate that would help designing language to language transformations. Most differences between SystemC (synthesizable) and VHDL are purely syntactical so i used ANTLR + Java and wrote a converter (took 3 week). The converter works nice but does not cover all cases. I needed a test case so i wrote systemc for a full basic vision system (camera model, camera interface, down-scaling) and tested it using systemc, then i applied the converter and after some minor corrections (systemC takes care of signal initialisation while you need to use reset to initialize signals in VHDL) i had a system simulating in Xilinx ISim.

To test the code on harware i quickly soldered a camera adapter for the papilio and i was ready to test.


The main drawback of the papilio is the slow communication with a host PC (FT2232 based 3Mbit/s max) so i used a downscaler to send the image over serial port and a Java app to display it.
At first nothing worked but using an OpenBench Logic Sniffer(http://www.gadgetfactory.net/logic-sniffer-2/) i was able to debug the I2C communication (error in my I2c master module) and finaaly got an image to display !



The next step is now to process the image ...

(all this project code is available on http://code.google.com/p/fpga-cam/)

Saturday, August 25, 2012

First post

I have been thinking about writing a blog for quite a long time but never found the motivation. Last year i became assistant professor and started to think that all my electronic and computing experiments could be valuable to others.
This blog is intended to be place to save my experiments results,thoughts and idea and to share my work. 
I don't pretend to do extraordinary things but from my experience even simple stuff can become valuable to others.