代码讲解:
video_capture = cv2.VideoCapture(0)
# Load a sample picture and learn how to recognize it.
obama_image = face_recognition.load_image_file("BOSS2.bmp")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
whileTrue:
ret, frame = video_capture.read()
face_locations = face_recognition.face_locations(frame)
face_encodings = face_recognition.face_encodings(frame, face_locations)
其中cv2.VideoCapture函数定义摄像头对象,0为第一个摄像头,一般为笔记本内置摄像头。
face_recognition.load_image_file:读取项目下的图片文件
face_recognition.face_encodings:对图片进行编码
while True:进入死循环
video_capture.read:是一个返回当前帧的函数,它能返回两个参数,ret和frame
第一个参数是bool型的ret,其值为True或False,代表有没有读到图片
第二个参数是frame,是当前截取一帧的图片。
face_recognition.face_locations(frame):获取视频流帧,识别人脸
face_recognition.face_encodings(frame, face_locations):对视频流进行编码
video_capture = cv2.VideoCapture(0)
# Load a sample picture and learn how to recognize it.
obama_image = face_recognition.load_image_file("BOSS2.bmp")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
whileTrue:
ret, frame = video_capture.read()
face_locations = face_recognition.face_locations(frame)
face_encodings = face_recognition.face_encodings(frame, face_locations)
其中cv2.VideoCapture函数定义摄像头对象,0为第一个摄像头,一般为笔记本内置摄像头。
face_recognition.load_image_file:读取项目下的图片文件
face_recognition.face_encodings:对图片进行编码
while True:进入死循环
video_capture.read:是一个返回当前帧的函数,它能返回两个参数,ret和frame
第一个参数是bool型的ret,其值为True或False,代表有没有读到图片
第二个参数是frame,是当前截取一帧的图片。
face_recognition.face_locations(frame):获取视频流帧,识别人脸
face_recognition.face_encodings(frame, face_locations):对视频流进行编码