Spaces:
Build error
Build error
| import computervision | |
| # Load the cascade classifier for face detection | |
| face_cascade = computervision.CascadeClassifier('haarcascade_frontalface_alt.xml') | |
| # Load the input image | |
| img = computervision.Image('input_image.jpg') | |
| # Convert the image to grayscale | |
| gray = img.convert_to_grayscale() | |
| # Detect faces in the grayscale image using the Haar cascade | |
| faces = face_cascade.detect_multi_scale(gray, scale_factor=1.1, min_neighbors=5, min_size=(30, 30)) | |
| # Draw rectangles around the detected faces | |
| for (x, y, w, h) in faces: | |
| img.draw_rectangle((x, y), (x+w, y+h), fill=(0, 255, 0)) | |
| # Display the output image with the detected faces | |
| img.show() |