opencv python chapter5 人脸检测

import cv2 as cv
from chapter4 import stackImages
faceCascade = cv.CascadeClassifier(r"data/haarcascade_frontalface_default.xml")
frameWidth = 640
frameHeight = 480
cap = cv.VideoCapture(0)
cap.set(3,frameWidth)
cap.set(4,frameHeight)
cap.set(10,130)
while True:
success ,img = cap.read()
#人脸识别
imgGray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imgGray, 1.1, 4)
for (x, y, w, h) in faces:
cv.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
imgStack = stackImages(1, ([img]))
cv.imshow("img", imgStack)
cv.waitKey(1)
if cv.waitKey(1)& 0xFF ==ord('q'):
break
posted @ 2021-02-11 03:20  whatareyougiao  阅读(67)  评论(0)    收藏  举报