# -*- coding:utf-8 -*-
import cv2 as cv
import numpy as np
import sys
# src = cv.imread('test1.jpg')
path = r'D:\face'
def face_detect_demo(image):
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
face_detector = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
face_detector.load(path + '\haarcascade_frontalface_default.xml')
faces = face_detector.detectMultiScale(gray,1.3,5)
for x,y,w,h in faces:
cv.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2)
cv.imshow("face detect",image)
print("--------------python face detect-------------")
capture = cv.VideoCapture(0) # 开摄像头
#cv.namedWindow("input image",0)
cv.namedWindow("face detect",0)
while (True):
ret, frame = capture.read()
frame = cv.flip(frame,1)
face_detect_demo(frame)
cv.waitKey(10)
python+opencv人脸检测摄像头
最新推荐文章于 2023-02-17 14:56:25 发布
