Spaces:
Sleeping
Sleeping
| import cv2 | |
| import gradio as gr | |
| # OpenCV의 얼굴 감지용 Haar cascade를 로드합니다. | |
| face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') | |
| def detect_faces(image): | |
| # 이미지를 그레이스케일로 변환합니다. | |
| gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
| # 그레이스케일 이미지에서 얼굴을 감지합니다. | |
| faces = face_cascade.detectMultiScale(gray, 1.1, 4) | |
| # 감지된 얼굴 주위에 사각형을 그립니다. | |
| for (x, y, w, h) in faces: | |
| cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 0), 2) | |
| return image | |
| iface = gr.Interface( | |
| fn=detect_faces, | |
| inputs=gr.Image(), # 수정된 부분 | |
| outputs=gr.Image(), | |
| title="얼굴 감지", | |
| description="이미지를 업로드하면 얼굴에 사각형을 그립니다." | |
| ) | |
| iface.launch() |