Hi everyone, first of all, thanks for ur attention on my post, i really need some guidance from you guys. I faced some issue currently and I wish to get some help from experienced maker. I am working on a DROWSINESS DETECTOR, which is can automatically on when the driver start their engine ( I also not sure run this script in virtual environment is correct or not). But when I run the script, it show the error below:
I have totally no idea for this, but I can provide my code here, not sure it contain any error or not.
Code:
(venv) cheeyong@raspberrypi:~ $ python3 /home/cheeyong/github1.pypygame 2.5.2 (SDL 2.28.3, Python 3.11.2)Hello from the pygame community. https://www.pygame.org/contribute.htmlTraceback (most recent call last): File "/home/cheeyong/github1.py", line 35, in <module> frame = imutils.resize(frame, width=900) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/cheeyong/venv/lib/python3.11/site-packages/imutils/convenience.py", line 69, in resize (h, w) = image.shape[:2] ^^^^^^^^^^^AttributeError: 'NoneType' object has no attribute 'shape'(venv) cheeyong@raspberrypi:~ $
Code:
from scipy.spatial import distanceimport dlibimport cv2from imutils import face_utilsimport imutilsimport pygameimport RPi.GPIO as GPIOBUZZER_PIN = 16GPIO.setmode(GPIO.BCM)GPIO.setup(BUZZER_PIN, GPIO.OUT)def eye_aspect_ratio(eye): a = distance.euclidean(eye[1], eye[5]) b= distance.euclidean(eye[2], eye[4]) c= distance.euclidean(eye[0], eye[3]) ear = (a + b) / (2.0 * c) return earpygame.mixer.init()pygame.mixer.music.load('/home/cheeyong/Downloads/alarm.wav')thresh = 0.25frame_check = 50count = 0detect = dlib.get_frontal_face_detector()predict = dlib.shape_predictor("/home/cheeyong/Downloads/shape_predictor_81_face_landmarks.dat")(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_68_IDXS["left_eye"](rStart, rEnd) = face_utils.FACIAL_LANDMARKS_68_IDXS["right_eye"]cap = cv2.VideoCapture(0)while True: ret, frame = cap.read() frame = imutils.resize(frame, width=900) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) subjects = detect(gray, 0) for subject in subjects: shape = predict(gray, subject) shape = face_utils.shape_to_np(shape) leftEye = shape[lStart:lEnd] rightEye = shape[rStart:rEnd] leftEyeHull = cv2.convexHull(leftEye) rightEyeHull = cv2.convexHull(rightEye) leftEyeAspectRatio = eye_aspect_ratio(leftEye) rightEyeAspectRatio = eye_aspect_ratio(rightEye) EyeaspectRatio = (leftEyeAspectRatio + rightEyeAspectRatio) / 2 cv2.drawContours(frame, [leftEyeHull], -1, (0, 255, 0), 1) cv2.drawContours(frame, [rightEyeHull], -1, (0, 255, 0), 1) if (EyeaspectRatio < thresh): count += 1 if count >= frame_check: pygame.mixer.music.play(-1) cv2.putText(frame, " Driver is Drowsy ", (150,100), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0, 0, 255), 2) else: pygame.mixer.music.stop() count = 0 cv2.imshow("Frame", frame) key = cv2.waitKey(1) if key == ord("q"): breakcv2.destroyAllWindows()cap.stop()
Statistics: Posted by matteo2002starter — Fri Feb 02, 2024 3:03 am