user2206637
user2206637

Reputation: 1

How to detect face on different angles using opencv+python

I want to detect the face on different angles . Now my code detect faces , if the face is exactly in front of camera. But i want to detect faces on different angles . How could i do this .. Please help me.

My code is below: detector.py

import cv2
import numpy as np

faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);
rec=cv2.createLBPHFaceRecognizer();
rec.load("recognizer/trainningData.yml")
id=0
font=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_COMPLEX_SMALL,2,1,0,2)
while(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="Aftab Ahmed"
              elif (id==2):
                      id="Ahmed"
              cv2.cv.PutText(cv2.cv.fromarray(img),str(id),(x,y+h),font,255);
        cv2.imshow("Face", img);
        if(cv2.waitKey(1)==ord('q')):
            break;
cam.release()
cv2.destroyAllWindows()

Upvotes: 0

Views: 4572

Answers (1)

Jeru Luke
Jeru Luke

Reputation: 21203

In order to detect the non-frontal portion of the face, you have to use a different classifier. For frontal face detection you have used haarcascade_frontalface_default.xml file. The side portion of the face is usually called the profile.

To detect the non frontal portion there is a different xml file available namely lbpcascade_profileface.xml. You can find this .xml file on THIS GITHUB PAGE

Use the xml to detect the profile.

Upvotes: 1

Related Questions