Skip to Content
Python Robotics Projects
book

Python Robotics Projects

by Prof. Diwakar Vaish
May 2018
Intermediate to advanced
340 pages
7h 20m
English
Packt Publishing
Content preview from Python Robotics Projects

Recognizing the face

Now that we have learned how to make our system learn, it's time to use that learned data and recognize the face. So without much talking, let's go ahead and understand how this would be done:

import numpy as npimport cv2faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')cam = cv2.VideoCapture(0)rec = cv2.face.LBPHFaceRecognizer_create()rec.read("recognizer/trainningData.yml")id = 0font = cv2.FONT_HERSHEY_SIMPLEXwhile True:   ret, img = cam.read()   gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)   faces = faceDetect.detectMultiScale(gray,1.3,5)   for (x,y,w,h) in faces:       cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,255), 2)       id, conf = rec.predict(gray[y:y+h, x:x+w])       if id==1:           id = "BEN" cv2.putText(img, str(id), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Robotics using Python

Learning Robotics using Python

Lentin Joseph
Hands-On ROS for Robotics Programming

Hands-On ROS for Robotics Programming

Bernardo Ronquillo Japón

Publisher Resources

ISBN: 9781788832922Supplemental Content