Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

Face recognition with opencv and python

$
0
0
I am trying to implement the real-time face recognition using opencv and python. Each time i open my detector it gets stuck and gives error, could please help ? import cv2 import numpy as np recognizer = cv2.face.createLBPHFaceRecognizer() recognizer.load('trainner/trainner.yml') cascadePath = "haarcascade_frontalface_default.xml" faceCascade = cv2.CascadeClassifier(cascadePath); cam = cv2.VideoCapture(0) font = (cv2.FONT_HERSHEY_SIMPLEX, 1, 1, 0, 1, 1) while True: ret, im =cam.read() gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) faces=faceCascade.detectMultiScale(gray, 1.2,5) for(x,y,w,h) in faces: cv2.rectangle(im,(x,y),(x+w,y+h),(225,0,0),2) Id, conf = recognizer.predict(gray[y:y+h,x:x+w]) if(conf<50): if(Id==1): Id="Anirban" elif(Id==2): Id="Sam" else: Id="Unknown" cv2.cv.PutText(cv2.cv.fromarray(im),str(Id), (x,y+h),font, 255) cv2.imshow('im',im) if cv2.waitKey(10) & 0xFF==ord('q'): break cam.release() cv2.destroyAllWindows() The error: TypeError Traceback (most recent call last) in () 16 for(x,y,w,h) in faces: 17 cv2.rectangle(im,(x,y),(x+w,y+h),(225,0,0),2) ---> 18 Id, conf = recognizer.predict(gray[y:y+h,x:x+w]) 19 if(conf<50): 20 if(Id==1): TypeError: 'int' object is not iterable

Viewing all articles
Browse latest Browse all 2088

Latest Images

Trending Articles



Latest Images