Skip to content

Instantly share code, notes, and snippets.

@Noob-can-Compile
Created December 1, 2019 12:30
Show Gist options
  • Save Noob-can-Compile/e57f2ea61a06bdbe030200fa242d645c to your computer and use it in GitHub Desktop.
Save Noob-can-Compile/e57f2ea61a06bdbe030200fa242d645c to your computer and use it in GitHub Desktop.
# load in a haar cascade classifier for detecting frontal faces
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
# run the detector
# the output here is an array of detections; the corners of each detection box
# if necessary, modify these parameters until you successfully identify every face in a given image
faces = face_cascade.detectMultiScale(image, 1.2, 2)
# make a copy of the original image to plot detections on
image_with_detections = image.copy()
# loop over the detected faces, mark the image where each face is found
for (x,y,w,h) in faces:
# draw a rectangle around each detected face
# you may also need to change the width of the rectangle drawn depending on image resolution
cv2.rectangle(image_with_detections,(x,y),(x+w,y+h),(255,0,0),3)
fig = plt.figure(figsize=(9,9))
plt.imshow(image_with_detections)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment