stay
opencv root directory \sources\data\haarcascades A lot of trained classifiers are provided in , We use haarcascade_frontalface_alt.xml classifier .
Haar cascade yes Paul Viola and Michael Jone stay 2001 year , paper ”Rapid Object Detection using a
Boosted Cascade of Simple Features” A new method is proposed Object Detection method .
import cv2 # Read in image img = cv2.imread("test.jpg") # Loading face features , The document is in
python Installation directory \Lib\site-packages\cv2\data lower face_cascade =
cv2.CascadeClassifier(r'haarcascade_frontalface_default.xml') #
Convert the read image to COLOR_BGR2GRAY, Reduce calculation intensity gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #
Number of faces detected faces = face_cascade.detectMultiScale(gray, scaleFactor = 1.15,
minNeighbors = 5, minSize = (5, 5)) print("Face : {0}".format(len(faces))) #
Circle the face with a rectangle for(x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h),
(0, 255, 0), 2) cv2.namedWindow("Faces") cv2.imshow("Faces", img)
cv2.waitKey(0) cv2.destroyAllWindows()

Technology