OpenCV-Python(1)在Python中使用OpenCV进行人脸检测

匿名 (未验证) 提交于 2019-12-02 22:51:30
detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0) ret, img = cap.read() cv2.imshow('windowname', img) cv2.waitKey(0)  # 释放摄像头资源 cap.release()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:     cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') cap = cv2.VideoCapture(0)  while True:     ret, img = cap.read()     gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)     faces = detector.detectMultiScale(gray, 1.3, 5)     for (x, y, w, h) in faces:         cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)      cv2.imshow('frame', img)     if cv2.waitKey(1) & 0xFF == ord('q'):         break  cap.release() cv2.destroyAllWindows()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!