Build Your Own Face-Recognition System with Intel Edison

The Intel demo team at CES posing with some of the awards the Edison won.

Computer vision is a processor-demanding task, but thanks to a dual-core Atom processor, the Intel Edison handles it with ease. The Edison ships with a highly custom Linux image, but you’ll only need to add a few software packages and custom code to get OpenCV — a wildly popular approach to computer vision — operational and recognizing human faces in photos.

4. Add an Unofficial Package Repository

Access to every package is not available without adding repository locations to the opkg/base-feeds.conf file. By doing this, you’ll add an enormous number of compiled applications, saving you the hassle of compiling from source.

NOTE: Unofficial repositories are quite common across most Linux distributions.

Next, download the XML file that defines the parameters for the OpenCV facial-recognition algorithm. This file is also saved to the public directory of the Edison’s web server as haarcascade_frontal face_alt.xml.

Import the photo using OpenCV and convert it to grayscale for use in the facial-recognition process:

img = cv2.imread('/usr/lib/edison_config_tools/public/in.jpg')

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

Using the OpenCV libraries, create the facial-recognition algorithm and process the grayscale image:

faceCascade =

cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')

faces =

faceCascade.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5,

minSize=(30, 30), flags = cv2.cv.CV_HAAR_SCALE_IMAGE)

The faces variable now contains an array of rectangular coordinates that surround each face that OpenCV found in the image. These coordinates are then used to draw a box around each face in the original color image, which you’ll save as a new file:

for (x,y,w,h) in faces:

cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

cv2.imwrite('in_facefound.png',img)

Finally, save the text file by pressing Ctrl-X on your keyboard. When prompted to save the file, type Y and Enter.

6. Web page Setup

Download a simple HTML file which will display the pre- and post-processed images on the Edison’s onboard web server.

wget http://cdn.makezine.com/make/43/OpenCV.html

Change directories to the web server’s public directory:

cd /usr/lib/edison_config_tools/public

7. Viewing the Images

Going Further

Now that OpenCV and Python are configured on your Edison, be sure to see the official documentation for great example code and ideas at makezine.com/go/opencv-python-tutorials. OpenCV can detect all kinds of shapes, analyze video, and much more.