File size: 867 Bytes
be15e1b
 
c09c610
ccf8348
 
c09c610
ccf8348
 
 
 
be15e1b
ccf8348
be15e1b
ccf8348
 
be15e1b
64809a4
 
 
 
 
 
 
ccf8348
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()