Creating a face-recognising security cam with a Raspberry Pi – Part 1

This series of posts builds upon the mini-series on building a motion-detecting security cam based around the Raspberry Pi. Once you have your motion detecting security cam up and running, you should be able to move on to the next stage: enabling that system to recognize faces that it has been trained against.

My specific project (which I'm calling the Facecam, although I haven't applied for a trademark 😉 pulls data down from Facebook and uses that to train the face recognition system, but that's far from being a requirement: it's also very possible to train the database in other ways.

We'll go into detail on the various parts over the coming weeks (probably once a week, as I want to continue blogging about other topics, too), but let's start by introducing the project and the system architecture.

Here's the elevator pitch: Facecam is a security camera that recognises a resident's Facebook friends when they come to their front door and allows for tailored communication both to the resident and the visitor.

This would basically mean that instead of the resident receiving a notification email saying "You have a visitor" (as in the case of the motion-detection system we saw previously), the email would read "John Smith visited you". And John could potentially receive a customized "we're out" message while standing at the door and even a post on his Facebook wall thanking him for the visit.

A lot of this is clearly contingent on the accuracy of the facial recognition system – something we'll look at much more closely later on. In case the accuracy isn't adequate, it would be nice at least to provide some feedback to the visitor, saying "Welcome, John!" (even if it's actually Megan at the door ;-).

Right, now let's dive into the system architecture. Here's a quick diagram of the Facecam system:

Facecam system architecture

Here's a look at the new components (in addition to the "Motion detection" box we saw previously):

1. A component to download information on the resident's Facebook friends (.NET desktop application)

This component will build a "friend" database (stored in a file named facedata.xml) to be used at runtime by the security cam. The database will be trained with the friends' photos as downloaded from Facebook. So the component will need to access – for each friend – both their names and the photos in which they have been tagged (as well as the tag information, of course).

Using the tag information, the component will use OpenCV to attempt to extract the friend's face (by checking the list of detected faces against the tag location, to get the closest match), and – if it finds it – it will resize, crop and equalize the greyscale intensity of the image before saving it to disk for later use in the database training process.

This is ultimately an offline, CPU-intensive operation – we will simply need the database transferred across to the Raspberry Pi from time to time – so the approach we'll take is to create a .NET desktop application that performs this task on a higher-powered device.

2. A component to analyse frames saved by the motion-detection system, checking for friends (face recognition)

This is the guts of the system: the runtime component that will again use OpenCV to process images captured from the webcam, detect faces and then check the results against the facial recognition database on the Raspberry Pi. This needs to be pretty efficient – as the feedback should be in close to real-time – which may be a challenge: given the relatively low power of the Raspberry Pi CPU, we'll have to jump through some interesting hoops to get this working well enough.

3. A component to provide feedback to the visitor (LED messaging)

If we're going to tell the visitor that they have been recognised (or in some way warn unwanted visitors that their photo has been sent to the property's residents), then we're going to need some kind of screen. The Raspberry Pi has both HDMI and component video outputs, but I've decided to go the way of a USB-powered LED message-board. More on this in due course.

Right, that's it for this introductory post. We'll look in more detail at each of these components over the coming weeks, starting with the .NET desktop application to download friend information.

  1. Hi Kean,

    Sounds neat and clear and interesting.

    I really wonder what kind of data is going to go into the face data XML file. I would not put pixel data there, but store that in external individual image files, and reference those.

    Some of my friends boycott internet-based social networking and thus hopefully cannot be identified by facebook, so I would enable private non-facebook photos from the local system to be used as well.

    Cheers, Jeremy.

  2. Hi Jeremy,

    We'll of course talk about the XML format (although it's something this project has inherited), which uses an algorithm called Eigenfaces to greatly reduce the amount of data stored.

    And yes - I'm probably not even going to share the Facebook-specific code (for once), but will certainly explain more about the file/folder structure you'd need to build to train the database in some other way.

    Cheers,

    Kean

  3. Hi Kean,

    This looks really interesting!

    An API I'm not familiar with (but which I believe might prove useful here) is the Google Picasa Web API; As I say, I only know there exists an API from Google which (in some way) ties in with the Picasa Web offering from the big G.

    In case you aren't aware, Picasa (the desktop application) offers you the ability to tag faces of the people it finds within your picture library, and will (with your permission) sync them to your Picasa Web Photos albums. I've tagged all my family with it, so if it's possible to use this API instead of Facebook, that might be another avenue that would likely get around the friends-not-tagged-on-Facebook issue that Jeremy mentions.

    Here is the best link I could find that will be of help:

    Retrieving face tag data from the Picasa Web API (which in turn links to this page: Google Groups Picasa issues page

    Cheers,

    Alex.

  4. Hi Alex,

    That's interesting... it should certainly be possible to swap out the Facebook-oriented piece to pull down data from Picasa.

    I'll be describing the process I've used to isolate and extract faces to train the database next week.

    Cheers,

    Kean

  5. Especially the part on Face Recognition in Videos might be interesting to you:

    * docs.opencv.org/trunk/modules/contrib/doc/facerec/tutorial/facerec_video_recognition.html

  6. Thanks, Philipp - that's very helpful.

    I'm pretty much done with that side of things, but I'll certainly revisit the code once I've looked at the tutorial more closely.

    Kean

  7. That was an interesting thing,security camera purpose is really a lot specially on giving a security a shop and home.In Finland country many of people are still having doubt on putting security cameras however most of the already did.Anyway this is really excellent one.

  8. Hi Kean, hope you are still following this thread. I'm wondering whether to start a face recognition project. My concept would be based on linkedin profile pics, thus only 1 reference pic per face.

    Based on your experience is recognizing a face with only one reference pic available from a photo by any chance possible? Did you encounter in your experiment cases where the user had only one pic in fb?

  9. Hi Pyryl,

    Based on my experience the problems would be:

    * 1 photo is way too few, at least for the system I tried to use.
    * Profile photos aren't representative enough of how people look when they come to your door (or sit at their PC, if somehow recognising people's faces via their webcam).

    Cheers,

    Kean

  10. Thanks Kean! I think you just saved me a week of hacking towards a dead end.

  11. I want to say thank to you people for this great and helpful info.
    Thanks!!!surveillance
    camera system for business

Leave a Reply to Jeremy Tammik Cancel reply

Your email address will not be published. Required fields are marked *