📢 한이음에서 개최한 공모전 프로젝트이다.
📚 코드는 Github에서 참고!
운전자의 눈을 중점으로 해서 졸음을 인식하고 다양한 아두이노 기기를 이용해 졸음 중임을 인식한다. 이로써 운전자의 졸음 운전을 방지할 수 있는 프로젝트이다.
Opencv, Dlib, Python, Arduino
웹 카메라를 통해 눈 깜빡임과 차선을 인식하고 해당 정보를 라즈베리파이에서 입력받는다.
라즈베리파이에서 가지고 있는 입력 값과 Co2 센서의 수치에 따라 졸음인지 아닌지를 인식하고 졸음이라고 판단되면 졸음을 깨워주는 장치들이 작동한다.
rect = dlib.rectangle(int(x), int(y), int(x + w), int(y + h)) shape = predictor(gray, rect) shape = face_utils.shape_to_np(shape) leftEye = shape[lStart:lEnd] rightEye = shape[rStart:rEnd] leftEAR = eye_aspect_ratio(leftEye) rightEAR = eye_aspect_ratio(rightEye) ear = (leftEAR + rightEAR) / 2.0
if ear < EYE_AR_THRESH: COUNTER += 1 if COUNTER >= EYE_AR_CONSEC_FRAMES: if not ALARM_ON: ALARM_ON = True if args["alarm"] > 0: th.buzzer.blink(0.1, 0.1, 10, background=True) cv2.putText(frame, "DROWSINESS ALERT!", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2) else: COUNTER = 0 ALARM_ON = False
테스트 영상에서는 웹캠 대신 동영상을 이용해 인식했다.for (x, y, w, h) in cars: cv2.rectangle(temp, (x, y), (x + w, y + h), (0, 255, 255), 2) center = offset(left_fit_line[0] , 180 , right_fit_line[0]) if abs(center) > 1.5: center_x = int(640 / 2.0) center_y = int(360 / 2.0) thickness = 2 location = (center_x - 200, center_y - 100) font = cv2.FONT_HERSHEY_SIMPLEX; fontScale = 3.5 cv2.putText(temp, 'Warning', location, font, fontScale, (0, 0, 255), thickness) color = [0, 0, 255]
int hodnota = co2Sensor.read(); if (hodnota > 1000) { Serial.println("CO2 > 1000ppm, Moter On!!!"); myStepper.step(stepsPerRevolution); delay(500); }
if(Serial.available()){ val=Serial.parseInt(); analogWrite(led,255); delay(2000); } else{ analogWrite(led,0); }
📌시연 영상 : 졸음 운전 방지 프로그램