opencv實現人臉識別
阿新 • • 發佈:2018-12-16
import cv2 import matplotlib.pylab as plt import numpy as np def show(image): plt.imshow(image) plt.axis('off') plt.show() def imread(image): image = cv2.imread(image) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image def face_detect(image): image = imread(image) detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') rects = detector.detectMultiScale(image, scaleFactor=1.1, minNeighbors=2, minSize=(10, 10), flags=cv2.CASCADE_SCALE_IMAGE) for (x, y, w, h) in rects: # draw rect cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2) show(image) face_detect('face.jpg')
xml下載地址: