[人脸识别]07-视频输入人脸检测
1-程序
#导入CV模块 import cv2 as cv def face_detect_fun(img): gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY) print(cv.data.haarcascades) face_detect=cv.CascadeClassifier(cv.data.haarcascades+"haarcascade_frontalface_default.xml") face=face_detect.detectMultiScale(gray) for x,y,w,h in face: cv.rectangle(img,(x,y),(x+w,y+h),color=(0,0,255),thickness=2) cv.imshow("result",img) #读取摄像头 cap=cv.VideoCapture(0) #//WSN定位技术.mp4 #cap=cv.VideoCapture('WSN定位技术.mp4') #等待 while True: flag,frame=cap.read() if not flag: break face_detect_fun(frame) if ord('q')==cv.waitKey(0): break #释放内存 cv.destroyAllWindows() #释放摄像头 cap.release()
2-运行效果