Untitled

 avatar
unknown
plain_text
2 years ago
837 B
4
Indexable
import cv2
import os

def detect_faces(folder_path):
    face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
    files_with_faces = []
    
    for filename in os.listdir(folder_path):
        file_path = os.path.join(folder_path, filename)
        if not os.path.isfile(file_path):
            continue
        
        image = cv2.imread(file_path)
        gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5)
        
        if len(faces) > 0:
            files_with_faces.append(filename)
            
    return files_with_faces

if __name__ == '__main__':
    folder_path = '/path/to/folder'
    files_with_faces = detect_faces(folder_path)
    print('Files with faces:', files_with_faces)
Editor is loading...