python opencv 人脸+眼

python 3.4 pycharm 
 
  
import cv2 as cv
import numpy as np


def face_detect(image):
    # gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
    face_detector= cv.CascadeClassifier('D:/opencv/opencv/build/etc/haarcascades/haarcascade_frontalface_alt.xml')
    face_detect =cv.CascadeClassifier('D:/opencv/opencv/build/etc/haarcascades/haarcascade_eye_tree_eyeglasses.xml')
    faces = face_detector.detectMultiScale(gray,1.3,4)
    face  = face_detect.detectMultiScale(gray,1.4,5)
    for x,y,w,h in faces:
        cv.rectangle(image ,(x,y),(x+w,y+h),(0,255,255),2)
    cv.imshow('a',image)

    for x,y,w,h in face:
        cv.rectangle(image ,(x,y),(x+w,y+h),(0,0,255),2)
    cv.imshow('a',image)


capture = cv.VideoCapture(0)
cv.namedWindow('result',cv.WINDOW_AUTOSIZE)
cv.namedWindow('a',cv.WINDOW_AUTOSIZE)

while(True) :
    ret ,frame = capture.read()
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    #dst = cv.GaussianBlur(gray,(5,5),3)

    face_detect(frame)

    c = cv.waitKey(20)
    if c==27:
        break

capture.release()
cv.destroyAllWindows()

你可能感兴趣的:(python opencv 人脸+眼)