Last active
July 3, 2024 15:31
-
-
Save trialan/459c5fa457cd453f2106685df17a8469 to your computer and use it in GitHub Desktop.
Count faces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dlib_count_faces(image_path): | |
img = Image.open(image_path) | |
img = img.convert('RGB') | |
img_array = np.array(img) | |
detector = dlib.get_frontal_face_detector() | |
faces = detector(img_array) | |
return len(faces) | |
def haar_cascade_count_faces(image_path): | |
img = cv2.imread(image_path, cv2.IMREAD_COLOR) | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') | |
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) | |
return len(faces) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment