I am using a Jetson Nano Devkit and trying to develop a drowsiness detection system. Shortly, when driver closes their eyes, system should give warnings. I am using YOLO V8n
Here is the problematic part. When I run the code below, I always get “Camera Doesnt Work” and “Error! Camera is Closing” errors. I can’t get the camera to work no matter I do.
Below is my code.
from ultralytics import YOLO
import cv2
from PIL import Image
import time
import pygame
model = YOLO(“File Path”)
cap = cv2.VideoCapture(0)
pygame.mixer.init()
pygame.mixer.music.load(‘uyari2.mp3’)
warning= False
try:
while cap.isOpened():
succes, frame = cap.read() #THIS CAMERA CODE DOESNT WORK AND CAP THE FRAMES :(
if not succes: #THIS ALWAYS COMES TRUE AND CAMERA DOESNT WORK
print("Camera Doesnt Work)
break
results = model.predict(frame,show=True,stream=True)
for result in results:
if hasattr(result,"boxes"):
for box in result.boxes:
cls = int(box.cls[0])
if cls==1:
print("Warning:Eyes Are Closed")
if(uyari == False):
pygame.mixer.music.play()
uyari=True
else:
if(warning== True):
warning=False
pygame.mixer.music.stop()
if cv2.waitKey(1) & 0XFF ==ord("q"):
break
except KeyboardInterrupt:
print(" Error! Camera is Closing")
finally:
cap.release()
cv2.destroyAllWindows()
print(“”)