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 to proceed")
led.write(0)
if cv2.waitKey(25) == 27:
video_capture.release()
break

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

Since the Intel Edison has only one USB port, therefore we have mentioned the parameter of cv2.VideoCapture as 0. Also notice the following line:

faces = faceCascade.detectMultiScale(gray, 2, 4) 

You will notice that the parameters have been changed to optimize them for the Intel Edison. You can easily tamper with the parameters to get a good result.

We have included some lines for LED on and off:

Console output for face detection in images using openCV

This is when you begin to notice that the Intel Edison is simply not meant for image processing because of the RAM.

Now when you are dealing with high processing applications, we cannot rely on the processing power of the Intel Edison alone.

In those cases, we opt for cloud-based solutions. For cloud-based solutions, there are multiple frameworks that exist. One of them is Project Oxford by Microsoft (https://www.microsoft.com/cognitive-services).

Microsoft Cognitive Services provides us with APIs for face detection, recognition, speech recognition, and many more. Use the preceding link to learn more about them.

After all the discussions that we've had in this chapter, we now know that voice recognition performs reasonably well. However, things are not so good with image processing. But why are we focused on using it? The answer lies in that the Intel Edison can definitely be used as an image gathering device while other processing can be carried out on the cloud:

Security-based systems architecture at a glance

Processing can either be performed at the device end or at the cloud end. It all depends on the use case and the availability of resources.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.5.57