def run_setup_reset(self): try: frame = copy(self.source.setup_current_frame) qt_image = convert_frame_qt(frame) self.main_window.setup_frame.setPixmap(qt_image) self.main_window.setup_frame.setScaledContents(True) except TypeError as e: print("Error:", e)
def draw_setup(self, frame, points): try: frame = copy(frame) frame = draw_polygon_frame(frame, points) qt_image = convert_frame_qt(frame) self.setup.main_window.setup_frame.setPixmap(qt_image) self.setup.main_window.setup_frame.setScaledContents(True) except TypeError as e: print("Error:", e)
def get_db(self, video_id): s = self.source.dbs result = s.query(Video).filter(Video.id == video_id) if result.count() == 0: print("No video id found in the database") elif result.count() == 1: print("Found 1 record in databases") video = result.first() frame = cv2.imread(video.background) self.frame = frame qt_image = convert_frame_qt(frame) self.main_window.setup_frame.setPixmap(qt_image) self.main_window.setup_frame.setScaledContents(True) else: print("Found more video id!", result.count())
def run_setup(self): try: self.setup_frame_no = self.setup_frame_no + 1 self.source.setup_get_next_frame() # process here frame = copy(self.source.setup_current_frame) frame = setup_frame(frame, self.setup) qt_image = convert_frame_qt(frame) self.main_window.setup_frame.setPixmap(qt_image) self.main_window.setup_frame.setScaledContents(True) except TypeError as e: self.setup_timer.stop() self.main_window.setup_play_btn.setEnabled(False) self.main_window.setup_pause_btn.setEnabled(False) print("Error:", e)
def run_analysis(self): def populate_analysis(): self.main_window.density_lbl.setText(str(density)) self.main_window.vehicle_area_lbl.setText(str(vehicle_area)) self.main_window.polygon_area_lbl.setText(str(polygon_area)) self.main_window.contour_no_lbl.setText(str(contour_count)) self.main_window.speed_lbl.setText(str(speed)) self.main_window.analysis_frame_no_lbl.setText(\ str(self.analysis_frame_no)) self.main_window.high_speed_lbl.setText(str(self.top_speed)) self.main_window.high_density_lbl.setText(str(self.top_density)) self.main_window.road_status_lbl.setText(traffic_status) self.main_window.congestion_lbl.setText(str(congestion_lvl)) try: self.source.analysis_get_next_frame() if self.source.analysis_current_frame != None: self.analysis_frame_no = self.analysis_frame_no + 1 # process here frame = copy(self.source.analysis_current_frame) # background subtraction frame, vehicle_area, contour_count, centers, points = \ background_subtraction(frame, \ self.source.background.frame, \ self.source.polygon.points, self.haar_collect, \ self.source.base_name) print(self.source.base_name) # draw polygon frame = draw_polygon_frame(frame, self.source.polygon.points) # get polygon area polygon_area = get_area_polygon(self.source.polygon.points) polygon_area = abs(polygon_area) print("Polygon area:", abs(polygon_area), end=' ') # compute density if vehicle_area > self.top_density: self.top_density = vehicle_area density = vehicle_area / polygon_area density = abs(density) # compute speed speed = 0 if contour_count != 0: self.centers = self.centers + centers frame, speed = draw_line_speed(frame, self.centers) if speed != 0: if speed > self.top_speed: self.top_speed = speed speed = speed / self.top_speed else: self.centers = [] # debug speed if self.speed_debug == True: if speed != 0: self.analysis_timer.stop() self.main_window.analysis_play_btn.setEnabled(True) # fuzzy logic input_val = [density, speed] congestion_lvl = 0.0 traffic_status = 'N/A' congestion_lvl, traffic_status, status_code = \ FuzzyLogic(input_val).getResult() print(congestion_lvl, traffic_status, status_code) # populate main window populate_analysis() # analysis params here analysis = { 'frame_no': self.analysis_frame_no, 'status': traffic_status, 'density': density, 'speed': speed, 'congestion': congestion_lvl, 'status_at': None } print(analysis) # check timer for sms notification self.source.analysis_dict = analysis if self.timer.status: if self.timer.is_due_inc(): print("Timer is due") # call send sms here self.notification.send_sms_user("traffic", None) # save frame tid = str(time()) tid = tid.replace('.', '') frame_file = 'frames/' + tid + "-" + \ self.source.base_name + "-" + \ traffic_status + '.jpg' cv2.imwrite(frame_file, frame) print("Density:", density) # convert to qt image qt_image = convert_frame_qt(frame) self.main_window.analysis_frame.setPixmap(qt_image) self.main_window.analysis_frame.setScaledContents(True) else: self.source.analysis.sequencer() except TypeError as e: self.analysis_timer.stop() self.main_window.analysis_play_btn.setEnabled(False) self.main_window.analysis_pause_btn.setEnabled(False) print("Error:", e)