Python程序调⽤摄像头实现⼈脸识别
使⽤简单代码实现摄像头进⾏在线⼈脸识别
import cv2
import sys
import logging as log七夕单身
import datetime as dt
from time import sleep
cascPath = "D:\\Python27\\Lib\\site-packages\\cv2\\data\\haarcascade_l"
faceCascade = cv2.CascadeClassifier(cascPath)
# 打开视频捕获设备
video_capture = cv2.VideoCapture(0)
吴秀波儿子个人资料while True:
if not video_capture.isOpened():
print('Unable to load camera.')邓煌老公孙达简历
sleep(5)
pass
# 读视频帧
ret, frame = ad()
# 转为灰度图像
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# 调⽤分类器进⾏检测
faces = faceCascade.detectMultiScale(
gray,
韩天宇
scaleFactor=1.1,
minNeighbors=5,梦见自己鬼上身
minSize=(30, 30),
#flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# 画矩形框
for (x, y, w, h) in faces:
# 显⽰视频
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# 关闭摄像头设备
lease()
卜算子 苏轼# 关闭所有窗⼝
cv2.destroyAllWindows()
运⾏程序后按q键退出程序。注意⼀些模块的导⼊,否则代码⽆法运⾏。笔者使⽤笔记本运⾏程序,可以调⽤笔记本的摄像头进⾏⼈脸识别。