facial detection on
TRANSCRIPT
Face Detection OnRPI2
Steven
Outline
• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo
RaspberryPi Camera
Spec Net price 940 NTW
Still resolution 5 Megapixels
Video modes 1080p30, 720p60 and 640x480p60/90
Picture formats JPEG , JPEG + RAW , GIF , BMP , PNG , YUV420 , RGB888
Video formats raw h.264
Applications• Taking Picture• Video Stream • Time lapse video• Dashcam recorded at 1080p
What Else?Face Detection
Outline
• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo
OpenCV Face Detection
• Rapid Object Detection using a Boosted Cascade of Simple Features
• Haar Feature Cascade Classifier• Haar feature: Simple rectangular feature
How to Represent Haar Feature
• sum of the pixels which lie within the white rectangles are subtracted from the sum of pixels in the black rectangles– Feature = sum of pixels (white rec) – sum of pixels(black rec)
Integral Image
• The integral value for each pixel is the sum of all the pixels above it and to its left
• The sum within D =4+1-2-3
Human Face Has Some Features
Adaboost Training MethodPositive
1Negative
4Negative
3Positive
2Negative
5
p n pn n0.2 0.2 0.2 0.2 0.2
HaarFeature 1
Positive1
Negative4
Negative3
Positive2
Negative5
p p pn n
0.13 0.3 0.13 0.3 0.13
StrongClassifier(x)=1.5*h1(x)Err rate = 0.4 a1 = (1-err)/err=1.5
HaarFeature 2
StrongClassifier(x)=1.5*h1(x)+2.3*h2(x)
Err rate = 0.3 a2 = (1-err)/err=2.3
Positive1
Negative4
Negative3
Positive2
Negative5
0.11 0.25 0.40.11 0.11
….
Final Strong Classifier
Cascade of Classifiers
Detection • There are huge numbers of sub-window of each size• Resize sub-window to the training size • Each sub-window goes through the Haar Feature Cascade
Classifier
c
OpenCV Pre-Trained Classifiers• haarcascade_eye_tree_eyeglasses.xml
haarcascade_eye.xml haarcascade_frontalface_alt2.xml haarcascade_frontalface_alt_tree.xml haarcascade_frontalface_alt.xml haarcascade_frontalface_default.xml haarcascade_fullbody.xml haarcascade_lefteye_2splits.xml haarcascade_profileface.xml haarcascade_lowerbody.xml haarcascade_righteye_2splits.xml haarcascade_mcs_eyepair_big.xml haarcascade_smile.xml haarcascade_mcs_eyepair_small.xml haarcascade_upperbody.xml
haarcascade_frontalface_alt.xml
• <_>3 7 14 4 -1.</_>• <_>x y h w weight</_>
(x,y)
h
w
OpenCV detectMultiScale• faces = haar_faces.detectMultiScale(image,
scaleFactor,minNeighbors, minSize)
Parameters:• image – captured imgae• scaleFactor – Parameter specifying how much the image
size is reduced at each image scale.• minNeighbors – Parameter specifying how many neighbors
each candidate rectangle should have to retain it.• minSize – Minimum possible object size. Objects smaller
than that are ignored.
Parameter : scaleFactor• detection window has a fixed size defined during training• detecting large and small faces using the same detection window• If scaleFactor=1.05 (small step for resizing)
– reducing image size by 5% can increase the chance of a matching fixed size of detection window. Slow but accurate
• If scaleFactor=1.4 (bigger step fro resizing)fast but risk of missing some detected faces
scale pyramid
Parameter : minNeighbors
minNeighbors=0
minNeighbors=1
Outline
• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo
My RaspberryPi 2Big Red Buttion
USB WIFI Dangle
RPI 2
Camera
USB Battery
Big Red Button GPIO27 echo 27 > /sys/class/gpio/export
f=open(‘sys/class/gpio/gpio27/value’,’r’)• RPi.GPIO module
GPIO.setmode(GPIO.BCM)GPIO.setup(27,GPIO.IN)GPIO.input(27)
No access to /dev/mem. Try running as root!• GPIO Permission is root• Using ssh (user permission) to remote rapi can’t control the
gpio (user permission)• Work around
echo 27 > /sys/class/gpio/exportf=open(‘sys/class/gpio/gpio27/value’,’r’)
Chmod and chown of /dev/mem ?
python-picamera
• sudo apt-get update • sudo apt-get install python-picamera• import picamera
camera = picamera.PiCamera()camera.start_preview()sleep(7)camera.capture(data, format='jpeg')
Compile OpenCV on PI2
Outline
• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo
Demo FlowPress Button
Start Preview
Capture Image
OpenCV face Classifier
Where to display the
image ?
Add rectangular line on detected faces
and output the image
JewelryBox
• Box mode • Send images and comments
Reference
• Rapid Object Detection using a Boosted Cascade of SimpleFeatures
• http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html
• https://learn.adafruit.com/raspberry-pi-face-recognition-treasure-box/overview
Q & A
Thanks