Reader small image

You're reading from  Intel Edison Projects

Product typeBook
Published inMay 2017
PublisherPackt
ISBN-139781787288409
Edition1st Edition
Concepts
Right arrow
Author (1)
Avirup Basu
Avirup Basu
author image
Avirup Basu

http://www.avirupbasu.com/p/resume_9.html
Read more about Avirup Basu

Right arrow

Intel Edison and Security System

In previous chapters, we learned how we can use the Intel Edison to develop applications related to IoT where we displayed live sensor data and also controlled the Edison itself. We also learned the development of an Android and a WPF app that was used to control the Intel Edison. Well, this chapter is more on the local front of the Intel Edison where we are going to use the built-in features of the device. This chapter is concentrated mainly on two key points:

  • Speech and voice processing with the Intel Edison
  • Image processing with the Intel Edison

All the codes are to be written in Python, so some parts of the chapter will concentrate on Python programming as well. In this chapter, we'll operate the Intel Edison using voice commands and then ultimately detect faces using the Intel Edison and a webcam. This chapter will thus explore the core capabilities of the Intel Edison...

Speech/voice processing using Edison

Speech processing typically refers to the various mathematical techniques that are applied on an audio signal to process it. It may be some simple mathematical operation or some complex operation. It's a special case of digital signal processing. However, we are not typically dealing with speech processing as a whole entity. We are interested only in a specific area of speech to text conversion. It is to be noted that everything in this chapter is to be performed by the Edison itself without accessing any cloud services. The scenario that this chapter will tackle initially is that we'll make the Edison perform some tasks based on our voice commands. We'll be using a lightweight speech processing tool, but before we proceed further with all the code and circuits, make sure you have the following devices with you. Initially, we'll walk you through switching...

Door lock/unlock based on voice commands

In this section, we'll just open and close a door based on voice commands. Similar to the previous section, where we switched an LED on and off using voice commands such as ON and OFF, here we are going to do a similar thing using a servo motor. The main target is to make the readers understand the core concepts of the Intel Edison where we use voice commands to perform different tasks. The question may arise, why are we using servo motors?

A servo motor, unlike normal DC motors, rotates up to a specific angle set by the operator. In normal scenarios, controlling the lock of a door may use a relay. The usage of relays was discussed in Chapter 3, Intel Edison and IoT (Home Automation).

Let us also explore the use of servo motors so that we can widen the spectrum of controlling devices. In this case, when a servo is set to 0 degrees, it is unlocked and when it is set to...

Image processing using the Intel Edison

Image processing or computer vision is one such field that requires tremendous amounts of research. However, we're not going to do rocket science here. We are opting for an open source computer vision library called OpenCV. OpenCV supports multiple languages and we are going to use Python as our programming language to perform face detection.

Typically, an image processing application has an input image; we process the input image and we get an output processed image.

Intel Edison doesn't have a display unit. So essentially we will run the Python script on our PC first. Then after the successful working of the code in the PC, we'll modify the code to run on the Edison. Things will get clearer when we do the practical implementation.

Our target is to perform face detection and, if detected, perform some action.

...

Real-time video display using OpenCV

Before we move on to face detection, let's first see whether we can access our camera or not. To do that, let's write a very simple Python script to display the webcam video feed:

import cv2 

cap = cv2.VideoCapture(0)

while(True):
# Capture frame-by-frame
ret, frame = cap.read()

# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

In the preceding code, we initially import the openCV module as import cv2.

Next we initialize the video capture device and set the index to zero as we're using the default webcam that comes with the laptop. For desktop users, you may need to vary the parameter.

After...

Face detection theory

Face detection is a very specific case of object recognition. There are many approaches to face recognition. However, we are going to discuss the two given here:

  • Segmentation based on color
  • Feature-based recognition

Segmentation based on color

In this technique, the face is segmented out based on skin color. The input of this is typically an RGB image, while in the processing stage we shift it to Hue saturation value (HSV) or YIQ ( Luminance (Y), In-phase Quadrature) color formats. In this process, each pixel is classified as a skin-color pixel or a non-skin-color pixel. The reason behind the use of other color models other than RGB is that sometimes RGB isn't able to distinguish skin colors in different light conditions. This significantly...

Intel Edison code

For the Intel Edison, let's find out what is actually possible. We don't have a display, so we can rely only on console messages and LED, perhaps, for visual signals. Next, we may need to optimize the code to run on the Intel Edison. But first let's edit the code discussed previously to include an LED and some kind of messages to the picture:

import cv2 
import numpy as np
import sys
import os

faceCascade = cv2.CascadeClassifier('C:/opencv/build/haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)
led = mraa.Gpio(13)
led.dir(mraa.DIR_OUT)
while (1):
led.write(0)
# Capture frame-by-frame
ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray, 2, 4)
iflen(faces) > 0:
print("Detected")
led.write(1)
else:
print("You are clear...

Open-ended task for the reader

The task for this chapter may require a bit of time, but the end result is going to be awesome. Implement Microsoft Cognitive Services to perform facial recognition. Use the Edison to gather data from the user and send it to the service for processing and perform some actions based on the result.

Summary

Throughout this chapter, we have learned some techniques of voice recognition using the Intel Edison. We also learned how image processing can be done in Python and implemented the same on the Intel Edison. Finally, we explored how a real life security-based system would look like and an open-ended question for Microsoft Cognitive Services.

Chapter 5, Autonomous Robotics with Intel Edison, will be entirely dedicated to robotics and how the Intel Edison can be used with robotics. We'll be covering both autonomous and manual robotics.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Intel Edison Projects
Published in: May 2017Publisher: PacktISBN-13: 9781787288409
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Avirup Basu

http://www.avirupbasu.com/p/resume_9.html
Read more about Avirup Basu