Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,29 +33,26 @@ def draw_landmarks_on_image(rgb_image, detection_result):
|
|
| 33 |
landmark_list=face_landmarks_proto,
|
| 34 |
connections=mp.solutions.face_mesh.FACEMESH_TESSELATION,
|
| 35 |
landmark_drawing_spec=None,
|
| 36 |
-
connection_drawing_spec=mp.solutions.drawing_styles
|
| 37 |
-
.get_default_face_mesh_tesselation_style())
|
| 38 |
mp.solutions.drawing_utils.draw_landmarks(
|
| 39 |
image=annotated_image,
|
| 40 |
landmark_list=face_landmarks_proto,
|
| 41 |
connections=mp.solutions.face_mesh.FACEMESH_CONTOURS,
|
| 42 |
landmark_drawing_spec=None,
|
| 43 |
-
connection_drawing_spec=mp.solutions.drawing_styles
|
| 44 |
-
.get_default_face_mesh_contours_style())
|
| 45 |
mp.solutions.drawing_utils.draw_landmarks(
|
| 46 |
image=annotated_image,
|
| 47 |
landmark_list=face_landmarks_proto,
|
| 48 |
connections=mp.solutions.face_mesh.FACEMESH_IRISES,
|
| 49 |
landmark_drawing_spec=None,
|
| 50 |
-
connection_drawing_spec=mp.solutions.drawing_styles
|
| 51 |
-
.get_default_face_mesh_iris_connections_style())
|
| 52 |
return annotated_image
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
def
|
| 56 |
# OpenCV görüntüsünü Mediapipe formatına dönüştür
|
| 57 |
-
|
| 58 |
-
mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=
|
| 59 |
|
| 60 |
# Yüz yer işaretlerini algıla
|
| 61 |
detection_result = detector.detect(mp_image)
|
|
@@ -74,33 +71,18 @@ def process_frame(frame):
|
|
| 74 |
right_eye_status = "Kapalı" if blink_right > 0.5 else "Açık"
|
| 75 |
|
| 76 |
# Landmarkları çizin
|
| 77 |
-
annotated_image = draw_landmarks_on_image(
|
| 78 |
-
|
| 79 |
-
# # Çerçeveye göz durumunu yaz
|
| 80 |
-
# cv2.putText(annotated_image, f"Sol Goz: {left_eye_status}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 81 |
-
# cv2.putText(annotated_image, f"Sag Goz: {right_eye_status}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 82 |
|
| 83 |
return cv2.cvtColor(annotated_image, cv2.COLOR_RGB2BGR), left_eye_status, right_eye_status
|
| 84 |
else:
|
| 85 |
-
return
|
| 86 |
|
| 87 |
# Gradio arayüzü
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
while True:
|
| 91 |
-
success, frame = cap.read()
|
| 92 |
-
if not success:
|
| 93 |
-
break
|
| 94 |
-
|
| 95 |
-
frame, left_eye_status, right_eye_status = process_frame(frame)
|
| 96 |
-
yield frame, left_eye_status, right_eye_status
|
| 97 |
-
|
| 98 |
-
iface = gr.Interface(fn=video_feed,
|
| 99 |
-
inputs=None, # Giriş yok, sadece video akışı
|
| 100 |
outputs=[gr.Image(type="numpy", label="Yüz Tespiti Sonucu"),
|
| 101 |
gr.Textbox(label="Sol Göz Durumu"),
|
| 102 |
-
gr.Textbox(label="Sağ Göz Durumu")]
|
| 103 |
-
live=True)
|
| 104 |
|
| 105 |
# Gradio arayüzünü başlat
|
| 106 |
iface.launch(share=True)
|
|
|
|
| 33 |
landmark_list=face_landmarks_proto,
|
| 34 |
connections=mp.solutions.face_mesh.FACEMESH_TESSELATION,
|
| 35 |
landmark_drawing_spec=None,
|
| 36 |
+
connection_drawing_spec=mp.solutions.drawing_styles.get_default_face_mesh_tesselation_style())
|
|
|
|
| 37 |
mp.solutions.drawing_utils.draw_landmarks(
|
| 38 |
image=annotated_image,
|
| 39 |
landmark_list=face_landmarks_proto,
|
| 40 |
connections=mp.solutions.face_mesh.FACEMESH_CONTOURS,
|
| 41 |
landmark_drawing_spec=None,
|
| 42 |
+
connection_drawing_spec=mp.solutions.drawing_styles.get_default_face_mesh_contours_style())
|
|
|
|
| 43 |
mp.solutions.drawing_utils.draw_landmarks(
|
| 44 |
image=annotated_image,
|
| 45 |
landmark_list=face_landmarks_proto,
|
| 46 |
connections=mp.solutions.face_mesh.FACEMESH_IRISES,
|
| 47 |
landmark_drawing_spec=None,
|
| 48 |
+
connection_drawing_spec=mp.solutions.drawing_styles.get_default_face_mesh_iris_connections_style())
|
|
|
|
| 49 |
return annotated_image
|
| 50 |
|
| 51 |
+
# Görseli işleyen fonksiyon
|
| 52 |
+
def process_image(image):
|
| 53 |
# OpenCV görüntüsünü Mediapipe formatına dönüştür
|
| 54 |
+
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 55 |
+
mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=rgb_image)
|
| 56 |
|
| 57 |
# Yüz yer işaretlerini algıla
|
| 58 |
detection_result = detector.detect(mp_image)
|
|
|
|
| 71 |
right_eye_status = "Kapalı" if blink_right > 0.5 else "Açık"
|
| 72 |
|
| 73 |
# Landmarkları çizin
|
| 74 |
+
annotated_image = draw_landmarks_on_image(rgb_image, detection_result)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
return cv2.cvtColor(annotated_image, cv2.COLOR_RGB2BGR), left_eye_status, right_eye_status
|
| 77 |
else:
|
| 78 |
+
return image, "Göz Tespiti Yok", "Göz Tespiti Yok"
|
| 79 |
|
| 80 |
# Gradio arayüzü
|
| 81 |
+
iface = gr.Interface(fn=process_image,
|
| 82 |
+
inputs=gr.Image(type="numpy", label="Görsel Yükleyin"), # Giriş olarak görsel al
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
outputs=[gr.Image(type="numpy", label="Yüz Tespiti Sonucu"),
|
| 84 |
gr.Textbox(label="Sol Göz Durumu"),
|
| 85 |
+
gr.Textbox(label="Sağ Göz Durumu")])
|
|
|
|
| 86 |
|
| 87 |
# Gradio arayüzünü başlat
|
| 88 |
iface.launch(share=True)
|