facial detection on

31
Face Detection On RPI2 Steven

Upload: steven-song

Post on 15-Apr-2017

194 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Facial Detection On

Face Detection OnRPI2

Steven

Page 2: Facial Detection On

Outline

• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo

Page 3: Facial Detection On

RaspberryPi Camera

Page 4: Facial Detection On

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

Page 5: Facial Detection On

Applications• Taking Picture• Video Stream • Time lapse video• Dashcam recorded at 1080p

Page 6: Facial Detection On

What Else?Face Detection

Page 7: Facial Detection On

Outline

• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo

Page 8: Facial Detection On

OpenCV Face Detection

• Rapid Object Detection using a Boosted Cascade of Simple Features

• Haar Feature Cascade Classifier• Haar feature: Simple rectangular feature

Page 9: Facial Detection On

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)

Page 10: Facial Detection On

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

Page 11: Facial Detection On

Human Face Has Some Features

Page 12: Facial Detection On

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

….

Page 13: Facial Detection On

Final Strong Classifier

Page 14: Facial Detection On

Cascade of Classifiers

Page 15: Facial Detection On

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

Page 16: Facial Detection On

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

Page 17: Facial Detection On

haarcascade_frontalface_alt.xml

• <_>3 7 14 4 -1.</_>• <_>x y h w weight</_>

(x,y)

h

w

Page 18: Facial Detection On

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.

Page 19: Facial Detection On

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

Page 20: Facial Detection On

Parameter : minNeighbors

minNeighbors=0

minNeighbors=1

Page 21: Facial Detection On

Outline

• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo

Page 22: Facial Detection On

My RaspberryPi 2Big Red Buttion

USB WIFI Dangle

RPI 2

Camera

USB Battery

Page 23: Facial Detection On

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 ?

Page 24: Facial Detection On

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')

Page 25: Facial Detection On

Compile OpenCV on PI2

Page 26: Facial Detection On

Outline

• RaspberryPi Camera• OpenCV Face Detection• My Pi2 • Demo

Page 27: Facial Detection On

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

Page 28: Facial Detection On

JewelryBox

• Box mode • Send images and comments

Page 29: Facial Detection On

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

Page 30: Facial Detection On

Q & A

Page 31: Facial Detection On

Thanks