Skip to content

Instantly share code, notes, and snippets.

@sazio
Created August 28, 2020 14:20
Show Gist options
  • Save sazio/a7e28981b5ea21edc215675b78de77be to your computer and use it in GitHub Desktop.
Save sazio/a7e28981b5ea21edc215675b78de77be to your computer and use it in GitHub Desktop.
# OpenCV face detector
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
def detect_face_cv2(img):
# Move to grayscale
gray_img = cv2.cvtColor(img.copy(), cv2.COLOR_RGB2GRAY)
face_locations = []
face_rects = face_cascade.detectMultiScale(gray_img, scaleFactor=1.3, minNeighbors=5)
for (x,y,w,h) in face_rects:
face_location = (x,y,w,h)
face_locations.append((face_location, 1.0))
return face_locations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment