Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,12 @@ import gradio as gr
|
|
| 6 |
face_detector = dlib.get_frontal_face_detector()
|
| 7 |
eye_detector = dlib.shape_predictor("path_to_shape_predictor_68_face_landmarks.dat")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
# Função para detectar piscadas de olhos
|
| 10 |
def detect_blinks():
|
|
|
|
| 11 |
cap = cv2.VideoCapture(0)
|
| 12 |
eye_closed = False
|
| 13 |
blink_count = 0
|
|
@@ -38,12 +42,21 @@ def detect_blinks():
|
|
| 38 |
if left_eye_aspect_ratio < 0.2 and right_eye_aspect_ratio < 0.2:
|
| 39 |
if not eye_closed:
|
| 40 |
blink_count += 1
|
|
|
|
|
|
|
|
|
|
| 41 |
eye_closed = True
|
| 42 |
else:
|
| 43 |
eye_closed = False
|
| 44 |
|
| 45 |
# Mostrar a contagem de piscadas na tela
|
| 46 |
cv2.putText(frame, f"Blinks: {blink_count}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
cv2.imshow("Eye Blink Detection", frame)
|
| 48 |
|
| 49 |
# Parar a execução ao pressionar a tecla 'q'
|
|
@@ -66,4 +79,4 @@ interface = gr.Interface(
|
|
| 66 |
)
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
-
interface.launch()
|
|
|
|
| 6 |
face_detector = dlib.get_frontal_face_detector()
|
| 7 |
eye_detector = dlib.shape_predictor("path_to_shape_predictor_68_face_landmarks.dat")
|
| 8 |
|
| 9 |
+
# Variável para controlar a exibição da frase
|
| 10 |
+
mostrar_frase = False
|
| 11 |
+
|
| 12 |
# Função para detectar piscadas de olhos
|
| 13 |
def detect_blinks():
|
| 14 |
+
global mostrar_frase
|
| 15 |
cap = cv2.VideoCapture(0)
|
| 16 |
eye_closed = False
|
| 17 |
blink_count = 0
|
|
|
|
| 42 |
if left_eye_aspect_ratio < 0.2 and right_eye_aspect_ratio < 0.2:
|
| 43 |
if not eye_closed:
|
| 44 |
blink_count += 1
|
| 45 |
+
# Exibir a frase quando detectar uma piscada
|
| 46 |
+
if blink_count == 1:
|
| 47 |
+
mostrar_frase = True
|
| 48 |
eye_closed = True
|
| 49 |
else:
|
| 50 |
eye_closed = False
|
| 51 |
|
| 52 |
# Mostrar a contagem de piscadas na tela
|
| 53 |
cv2.putText(frame, f"Blinks: {blink_count}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
| 54 |
+
|
| 55 |
+
# Exibir a frase se a variável mostrar_frase for verdadeira
|
| 56 |
+
if mostrar_frase:
|
| 57 |
+
cv2.putText(frame, "Quero falar pessoal", (10, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
|
| 58 |
+
mostrar_frase = False
|
| 59 |
+
|
| 60 |
cv2.imshow("Eye Blink Detection", frame)
|
| 61 |
|
| 62 |
# Parar a execução ao pressionar a tecla 'q'
|
|
|
|
| 79 |
)
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
+
interface.launch()
|