Spaces:
Build error
Build error
Commit
·
aa93265
1
Parent(s):
8aa5820
Agregar script de prueba de cámara simple
Browse files- test_camera.py +76 -0
test_camera.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import time
|
| 3 |
+
|
| 4 |
+
def main():
|
| 5 |
+
"""
|
| 6 |
+
Prueba simple de la cámara con dibujo de rectángulos de prueba
|
| 7 |
+
para verificar el funcionamiento básico.
|
| 8 |
+
"""
|
| 9 |
+
print("Iniciando prueba de cámara...")
|
| 10 |
+
|
| 11 |
+
# Iniciar la cámara
|
| 12 |
+
cap = cv2.VideoCapture(0)
|
| 13 |
+
|
| 14 |
+
if not cap.isOpened():
|
| 15 |
+
print("Error: No se pudo abrir la cámara.")
|
| 16 |
+
return
|
| 17 |
+
|
| 18 |
+
print("Cámara iniciada correctamente. Presione 'q' para salir.")
|
| 19 |
+
|
| 20 |
+
# Contador de frames
|
| 21 |
+
frame_count = 0
|
| 22 |
+
start_time = time.time()
|
| 23 |
+
|
| 24 |
+
while True:
|
| 25 |
+
# Leer un frame de la cámara
|
| 26 |
+
ret, frame = cap.read()
|
| 27 |
+
|
| 28 |
+
if not ret:
|
| 29 |
+
print("Error al capturar el frame.")
|
| 30 |
+
break
|
| 31 |
+
|
| 32 |
+
# Incrementar contador
|
| 33 |
+
frame_count += 1
|
| 34 |
+
elapsed = time.time() - start_time
|
| 35 |
+
fps = frame_count / elapsed if elapsed > 0 else 0
|
| 36 |
+
|
| 37 |
+
# Crear copia del frame para dibujar
|
| 38 |
+
display_frame = frame.copy()
|
| 39 |
+
|
| 40 |
+
# Dibujar rectángulo de prueba en la esquina superior izquierda
|
| 41 |
+
cv2.rectangle(display_frame, (50, 50), (200, 200), (0, 0, 255), 3)
|
| 42 |
+
cv2.putText(display_frame, "Test Rectangle", (50, 40),
|
| 43 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
|
| 44 |
+
|
| 45 |
+
# Dibujar otro rectángulo en el centro de la imagen
|
| 46 |
+
h, w = display_frame.shape[:2]
|
| 47 |
+
center_x, center_y = w // 2, h // 2
|
| 48 |
+
cv2.rectangle(display_frame,
|
| 49 |
+
(center_x - 100, center_y - 100),
|
| 50 |
+
(center_x + 100, center_y + 100),
|
| 51 |
+
(0, 255, 0), 3)
|
| 52 |
+
cv2.putText(display_frame, "Center Box", (center_x - 80, center_y - 110),
|
| 53 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 54 |
+
|
| 55 |
+
# Mostrar información de FPS
|
| 56 |
+
cv2.putText(display_frame, f"FPS: {fps:.1f}", (10, h - 20),
|
| 57 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 0, 0), 2)
|
| 58 |
+
|
| 59 |
+
# Mostrar resultado
|
| 60 |
+
cv2.imshow("Test Camera", display_frame)
|
| 61 |
+
|
| 62 |
+
# Salir si se presiona 'q'
|
| 63 |
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
| 64 |
+
break
|
| 65 |
+
|
| 66 |
+
# Imprime estadísticas
|
| 67 |
+
print(f"Frames totales: {frame_count}")
|
| 68 |
+
print(f"Tiempo total: {elapsed:.2f} segundos")
|
| 69 |
+
print(f"FPS promedio: {fps:.1f}")
|
| 70 |
+
|
| 71 |
+
# Liberar recursos
|
| 72 |
+
cap.release()
|
| 73 |
+
cv2.destroyAllWindows()
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
main()
|