Esempio n. 1
0
    def send_email(cls, image, image_name):
        """
        
        """
        logger().debug("Sending Email")
        receivers = ','.join(rcptlist)

        msg = MIMEMultipart('mixed')
        msg['Subject'] = 'From GVW speed detector camera - Speeding car in GVW'
        msg['From'] = cls.username
        msg['To'] = cls.receivers

        alternative = MIMEMultipart('alternative')
        textplain = MIMEText('Captured a picture of a speeding car.')
        alternative.attach(textplain)
        msg.attach(alternative)
        jpgpart = MIMEApplication(image)
        jpgpart.add_header('Content-Disposition',
                           'attachment',
                           filename=image_name)
        msg.attach(jpgpart)

        client = smtplib.SMTP('smtp.gmail.com', 587)
        client.starttls()
        client.login(cls.username, password)
        client.sendmail(cls.username, rcptlist, msg.as_string())
        logger().debug("Email Sent")
        client.quit()
    def send_email(cls, temp_file, image_name):
        """
        
        """
        logger().debug("Sending Email")
        receivers = ','.join(cls.rcptlist)

        msg = MIMEMultipart('mixed')
        msg['Subject'] = 'From GVW speed detector camera - Speeding car in GVW'
        msg['From'] = cls.username
        msg['To'] = receivers

        alternative = MIMEMultipart('alternative')
        textplain = MIMEText('Captured a picture of a speeding car.')
        alternative.attach(textplain)
        msg.attach(alternative)
        with open(temp_file.path, 'rb') as fp:
            #jpgpart = MIMEApplication(fp.read())
            jpgpart = email.mime.image.MIMEImage(fp.read())
            jpgpart.add_header('Content-Disposition', 'attachment', filename=image_name)
            msg.attach(jpgpart)

        client = smtplib.SMTP('smtp.gmail.com', 587)
        client.starttls()
        #client = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        #client.ehlo()
        client.login(cls.username, cls.password)
        client.sendmail(cls.username, cls.rcptlist, msg.as_string())
        logger().debug("Email Sent")
        client.quit()
        os.remove(temp_file.path)
 def initialize_camera(self):
     """
     Initialize the video stream and allow the camera sensor to warmup.
     """
     logger().info(
         "Warming up Raspberry PI camera connected via the PCB slot.")
     self.video_stream = VideoStream(usePiCamera=True).start()
     time.sleep(2.0)
 def initialize_camera(self):
     """
     Initialize the video stream and allow the camera sensor to warmup.
     """
     if self.estimate_speed_from_video_file:
         logger().info("Reading the input video file.")
         self.video_stream = cv2.VideoCapture(self.args["input"])
     else:
         logger().info(
             "Warming up Raspberry PI camera connected via the PCB slot.")
         self.video_stream = VideoStream(usePiCamera=True).start()
     time.sleep(2.0)
Esempio n. 5
0
 def estimate_trackable_object(cls, trackable_object, centroid, ts):
     if trackable_object.current_index == -1:
         #initialize it for the first time to 0.
         trackable_object.current_index = 0
     elif trackable_object.current_index == len(SPEED_ESTIMATION_LIST):
         logger().error("Unable to find an empty slot in the trackable_object timestamp.")
         return
     
     if centroid[0] > SPEED_ESTIMATION_LIST[trackable_object.current_index]:
         logger().debug("Recording timestamp and centroid at column {}".format(SPEED_ESTIMATION_LIST[trackable_object.current_index]))
         trackable_object.timestamp_list.append(ts)
         trackable_object.position_list.append(centroid[0])
         trackable_object.current_index += 1
 def load_model(self):
     """
     Load our serialized model from disk
     """
     logger().info("Loading model name:{}, proto_text:{}.".format(
         MODEL_NAME, PROTO_TEXT_FILE))
     self.net = cv2.dnn.readNetFromCaffe(PROTO_TEXT_FILE, MODEL_NAME)
     # Set the target to the MOVIDIUS NCS stick connected via USB
     # Prerequisite: https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_raspbian.html
     logger().info(
         "Setting MOVIDIUS NCS stick connected via USB as the target to run the model."
     )
     self.net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
 def estimate_trackable_object(cls, trackable_object, centroid, ts):
     empty_slot = -1
     current_index = -1
     for speed_zone, index in enumerate(cls.fetch_speed_zones(trackable_object, centroid)):
         if speed_zone not in trackable_object.timestamp:
             empty_slot = speed_zone
             current_index = index
             break
     if empty_slot == -1:
         logger().error("Unable to find an empty slot in the trackable_object timestamp.")
         return
     if centroid[0] > SPEED_ESTIMATION_DICT[empty_slot]:
         trackable_object.timestamp[empty_slot] = ts
         trackable_object.position[empty_slot] = centroid[0]
         if current_index == len(LIST_OF_SPEED_ZONES)-1:
             trackable_object.lastPoint = True
Esempio n. 8
0
 def calculate_distance_in_pixels(cls, start, end, trackable_object, meter_per_pixel, estimated_speeds):
     # calculate the distance in pixels
     logger().debug("position_list={}".format(trackable_object.position_list))
     d = trackable_object.position_list[end] - trackable_object.position_list[start]
     distance_in_pixels = abs(d)
     # check if the distance in pixels is zero, if so,
     # skip this iteration
     if distance_in_pixels == 0:
         estimated_speeds.append(0)
         return
     # calculate the time in hours
     t = trackable_object.timestamp_list[end] - trackable_object.timestamp_list[start]
     time_in_seconds = abs(t.total_seconds())
     time_in_hours = time_in_seconds / (60 * 60)
     # calculate distance in kilometers and append the
     # calculated speed to the list
     distance_in_meters = distance_in_pixels * meter_per_pixel
     distance_in_km = distance_in_meters / 1000
     estimated_speeds.append(distance_in_km / time_in_hours)
 def estimate_object_speed(cls, trackable_object, centroid, ts, meter_per_pixel):
     if not trackable_object.estimated:
         cls.estimate_trackable_object(trackable_object, centroid, ts)
         # check to see if the vehicle is past the last point and
         # the vehicle's speed has not yet been estimated, if yes,
         # then calculate the vehicle speed and log it if it's
         # over the limit
         if trackable_object.lastPoint:
             # initialize the list of estimated speeds
             estimated_speeds = []
             # loop over all the pairs of points and estimate the
             # vehicle speed
             for (start, end) in POINTS:
                 cls.calculate_distance_in_pixels(start, end, trackable_object, meter_per_pixel, estimated_speeds)
             # calculate the average speed
             trackable_object.calculate_speed(estimated_speeds)
             # set the object as estimated
             trackable_object.estimated = True
             logger().info("Speed of the vehicle that just passed" \
                   " is: {:.2f} MPH".format(trackable_object.speedMPH))
Esempio n. 10
0
 def estimate_object_speed(cls, trackable_object, centroid, ts, meter_per_pixel):
     if not trackable_object.estimated:
         cls.estimate_trackable_object(trackable_object, centroid, ts)
         # check to see if the vehicle is past the last point and
         # the vehicle's speed has not yet been estimated, if yes,
         # then calculate the vehicle speed and log it if it's
         # over the limit
         if trackable_object.current_index == len(SPEED_ESTIMATION_LIST):
             # initialize the list of estimated speeds
             estimated_speeds = []
             # loop over all the pairs of points and estimate the
             # vehicle speed
             for index in range(len(SPEED_ESTIMATION_LIST)-1):
                 start = index
                 end = index + 1
                 logger().debug("start={},end={}".format(start, end))
                 cls.calculate_distance_in_pixels(start, end, trackable_object, meter_per_pixel, estimated_speeds)
             # calculate the average speed
             for index in range(len(SPEED_ESTIMATION_LIST)-1):
                 logger().info("Between column indices {} to {}, measured speed = {}".format(SPEED_ESTIMATION_LIST[index], SPEED_ESTIMATION_LIST[index+1],estimated_speeds[index] * MILES_PER_ONE_KILOMETER))
             trackable_object.calculate_speed(estimated_speeds)
             # set the object as estimated
             trackable_object.estimated = True
             logger().info("Speed of the vehicle that just passed" \
                   " is: {:.2f} MPH".format(trackable_object.speedMPH))
Esempio n. 11
0
    def clean_up(self):
        # stop the timer and display FPS information
        self.fps.stop()
        logger().info("elapsed time: {:.2f}".format(self.fps.elapsed()))
        logger().info("approx. FPS: {:.2f}".format(self.fps.fps()))

        #Close the log file.
        SpeedValidator.close_log_file()

        # close any open windows
        cv2.destroyAllWindows()

        # clean up
        logger().info("cleaning up...")
        self.video_stream.stop()