Example #1
0
    def check_distraction(self):
        """Se detecta una distraccion en caso de que se pase un umbral con respecto a los angulos de euler originales"""

        vertical_threshold = 10
        horizontal_threshold = 25
        vertical_lower_bound = self.initial_face_angle_vertical - vertical_threshold
        horizontal_lower_bound = self.initial_face_angle_horizontal - horizontal_threshold
        horizontal_upper_bound = self.initial_face_angle_horizontal + horizontal_threshold
        if (self.face_angle_vertical < vertical_lower_bound
                or self.face_angle_horizontal < horizontal_lower_bound
                or self.face_angle_horizontal > horizontal_upper_bound):

            if (self.alarm.lost_face()):
                CsvHandler.csv_input(
                    self.CAR_REGISTRATION, self.EVENT_STRING_DISTRACTION,
                    '' + str(self.gps.get_lat()) +
                    ', ' + str(self.gps.get_lon()) + '',
                    str(self.gps.get_speed()), self.frame)
                print("Distraccion detectada y registrada")
Example #2
0
    def check_drowsiness(self):
        """Conteo de pestaneos, bostezos y detección de sueño"""

        self.blink_drowsiness_symptoms = 8

        if self.ear < self.EYE_AR_THRESH:
            if ((self.counter <= time.time() - self.EYE_AR_CONSEC_FRAMES)
                    and self.t_end_blink == 0):
                self.t_end_blink = time.time() + 5
                self.alarm.text_to_speech("alarm")  #El conductor se durmió
                CsvHandler.csv_input(
                    self.CAR_REGISTRATION, self.EVENT_STRING_SLEEP,
                    '' + str(self.gps.get_lat()) +
                    ', ' + str(self.gps.get_lon()) + '',
                    str(self.gps.get_speed()), self.frame)

        else:
            self.counter = time.time()

        if (time.time() > self.t_end_blink):
            self.t_end_blink = 0

        # conteo de pestaneos

        if self.ear < self.EYE_AR_THRESH:
            self.blink_verification = True
        else:
            if self.blink_verification == True:
                self.blink_verification = False
                self.blink_counter += 1
                print("Cantidad de pestaneos: ", self.blink_counter)

        # control de pestaneos largos en un tiempo a definir
        if self.ear < self.EYE_AR_THRESH:
            if self.blink_counter_verification == True:
                self.blink_counter_verification = False
                self.blink_eye_closed = time.time() + self.BLINK_TIME_CLOSED
            if time.time(
            ) >= self.blink_eye_closed and self.blink_eye_closed != 0:
                self.blink_time_alert_counter_a.append(time.time())
                self.blink_eye_closed = 0
                print("Se subio el contador de sintomas (pestaneos) en 1",
                      self.blink_time_alert_counter_a)
                if len(self.blink_time_alert_counter_a
                       ) == self.BLINK_TIME_ALERT:
                    self.blink_time_alert_counter_a = []
                    self.alarm.text_to_speech("drows_alert")
                    CsvHandler.csv_input(
                        self.CAR_REGISTRATION, self.EVENT_STRING_DROWSINESS,
                        '' + str(self.gps.get_lat()) +
                        ', ' + str(self.gps.get_lon()),
                        str(self.gps.get_speed()), self.frame)

        else:
            self.blink_counter_verification = True
            self.blink_eye_closed = 0

        # solamente mantiene los pestaneos que se relaizaron en el intervalo de un minuto hacia atras, el resto los elimina
        if len(self.blink_time_alert_counter_a) > 0:
            if self.blink_time_alert_counter_a[0] <= (time.time() -
                                                      self.BLINK_TIME_GAP):
                self.blink_time_alert_counter_a.pop(0)
                print("elimine un elemento (pestaneo) porque paso un min",
                      self.blink_time_alert_counter_a)

        # bostezos

        if self.lips_distance > self.YAWN_THRESH and self.t_end == 0:
            self.t_end = time.time() + 5
            if self.yawn_counter_verification == True:
                self.yawn_counter_verification = False
                self.yawn_time_alert_counter_a.append(time.time())
                print("se a incrementado en 1 bostezos",
                      self.yawn_time_alert_counter_a)
                if len(self.yawn_time_alert_counter_a) == self.YAWN_TIME_ALERT:
                    self.alarm.text_to_speech("drows_alert")
                    self.yawn_time_alert_counter_a = []
        else:
            self.yawn_counter_verification = True

        if len(self.yawn_time_alert_counter_a) > 0:
            if self.yawn_time_alert_counter_a[0] <= (time.time() -
                                                     self.YAWN_TIME_GAP):
                self.yawn_time_alert_counter_a.pop(0)
                print("se elimino un lemento (Bostezo) porque paso un min",
                      self.yawn_time_alert_counter_a)

        if (time.time() > self.t_end):
            self.t_end = 0