import cv2 def viedoFace(): # Call the local camera 0 to allow it to be called video =cv2.VideoCapture(0) faceData = cv2.CascadeClassifier("haarcascade_frontalface_alt.xml") i=1 while(True): flag,videoImg=video.read() # Use the face data feature package to compare the faces in the camera faces=faceData.detectMultiScale(videoImg) # mirror 1 horizontal flip-1 vertical+horizontal flip 0 vertical flip for x, y, w, h in faces: cv2.rectangle(videoImg, pt1=(x, y), pt2=(x + w, y + h), color=[0, 0, 255], thickness=2) # Determine whether the object is a tuple type if not isinstance(faces,tuple): facePhot=videoImg[y:y+h,x:x+w] cv2.imwrite("faceImg/per1/%s.jpg"%i,facePhot) i+=1 videoImg = cv2.flip(videoImg, 1) videoImg = cv2.resize(videoImg, None, fx=0.8, fy=0.8) cv2.imshow("hh",videoImg) index=cv2.waitKey(1000//24) if index==32: print("The window is about to close") break # print(videoImg) cv2.destroyAllWindows() if __name__ == '__main__': viedoFace()
Python face recognition learning record, call camera, recognize face
Guess you like
Origin blog.csdn.net/weixin_42835381/article/details/108735647
Ranking