def __write_settings(self): """ Zapisz wartości z widgetów """ Configuration.distance_border1(self.border1_adjustment.get_value()) Configuration.distance_border2(self.border2_adjustment.get_value()) Configuration.meters_length( self.meters_length_spin_adjustment.get_value()) Configuration.color_number( self.color_number_spin_adjustment.get_value()) Configuration.horizontal_border( self.horizontal_border_spin_adjustment.get_value()) Configuration.vertical_border( self.vertical_border_spin_adjustment.get_value()) Configuration.pixel_limit(self.pixel_limit_spin_adjustment.get_value()) Configuration.distance_from_border( self.distance_from_border_spin_adjustment.get_value()) Configuration.draw_detection_region( self.draw_detection_region_check.get_active()) Configuration.draw_speed_region( self.draw_speed_region_check.get_active()) Configuration.draw_cars(self.draw_cars_check.get_active()) Configuration.draw_conturs(self.draw_conturs_check.get_active()) Configuration.draw_speed_info(self.draw_speed_info_check.get_active()) Configuration.draw_size_info(self.draw_size_info_check.get_active()) Configuration.draw_color_bar(self.draw_color_bar_check.get_active()) Configuration.save_config()
def draw_detection_region(frame: Frame, mask): """ Rysuje na klatce obszar czułości kamery. :param Frame frame: Klatka obrazu. :return: Klatka obrazu z oznaczonym obszarem. :rtype: Frame """ height, width = frame.size() horizontal_border = Configuration.horizontal_border() vertical_border = Configuration.vertical_border() lup = (int(horizontal_border), int(vertical_border)) rup = (int(width-horizontal_border), int(vertical_border)) llp = (int(horizontal_border), int(height-vertical_border)) rlp = (int(width-horizontal_border), int(height-vertical_border)) frame.img = cv2.line(frame.img, llp, lup, (0, 0, 255), thickness=3) frame.img = cv2.line(frame.img, llp, rlp, (0, 0, 255), thickness=3) frame.img = cv2.line(frame.img, rlp, rup, (0, 0, 255), thickness=3) frame.img = cv2.line(frame.img, lup, rup, (0, 0, 255), thickness=3) mask = cv2.line(mask, llp, lup, (0, 0, 255), thickness=3) mask = cv2.line(mask, llp, rlp, (0, 0, 255), thickness=3) mask = cv2.line(mask, rlp, rup, (0, 0, 255), thickness=3) mask = cv2.line(mask, lup, rup, (0, 0, 255), thickness=3) return frame, mask
def draw_detection_region(frame: Frame, mask): """ Rysuje na klatce obszar czułości kamery. :param Frame frame: Klatka obrazu. :return: Klatka obrazu z oznaczonym obszarem. :rtype: Frame """ height, width = frame.size() horizontal_border = Configuration.horizontal_border() vertical_border = Configuration.vertical_border() lup = (int(horizontal_border), int(vertical_border)) rup = (int(width - horizontal_border), int(vertical_border)) llp = (int(horizontal_border), int(height - vertical_border)) rlp = (int(width - horizontal_border), int(height - vertical_border)) frame.img = cv2.line(frame.img, llp, lup, (0, 0, 255), thickness=3) frame.img = cv2.line(frame.img, llp, rlp, (0, 0, 255), thickness=3) frame.img = cv2.line(frame.img, rlp, rup, (0, 0, 255), thickness=3) frame.img = cv2.line(frame.img, lup, rup, (0, 0, 255), thickness=3) mask = cv2.line(mask, llp, lup, (0, 0, 255), thickness=3) mask = cv2.line(mask, llp, rlp, (0, 0, 255), thickness=3) mask = cv2.line(mask, rlp, rup, (0, 0, 255), thickness=3) mask = cv2.line(mask, lup, rup, (0, 0, 255), thickness=3) return frame, mask
def __load_settings(self): """ Wczytaj obecną konfigurację znajdującą się config.json do widgetów okna. """ self.border1_adjustment.set_value(Configuration.distance_border1()) self.border2_adjustment.set_value(Configuration.distance_border2()) self.meters_length_spin_adjustment.set_value( Configuration.meters_length()) self.color_number_spin_adjustment.set_value( Configuration.color_number()) self.horizontal_border_spin_adjustment.set_value( Configuration.horizontal_border()) self.vertical_border_spin_adjustment.set_value( Configuration.vertical_border()) self.pixel_limit_spin_adjustment.set_value(Configuration.pixel_limit()) self.distance_from_border_spin_adjustment.set_value( Configuration.distance_from_border()) self.draw_detection_region_check.set_active( Configuration.draw_detection_region()) self.draw_speed_region_check.set_active( Configuration.draw_speed_region()) self.draw_cars_check.set_active(Configuration.draw_cars()) self.draw_conturs_check.set_active(Configuration.draw_conturs()) self.draw_speed_info_check.set_active(Configuration.draw_speed_info()) self.draw_size_info_check.set_active(Configuration.draw_size_info()) self.draw_color_bar_check.set_active(Configuration.draw_color_bar())
def __is_on_right(new_car): """ Sprawdza czy samochód jest blisko prawej krawędzi obszaru czułości. :param Vehicle new_car: Obserwoway samochód. :return: Prawda/fałsz. :rtype: bool """ hborder = Configuration.horizontal_border() distance = Configuration.distance_from_border() return new_car.centerx > (Follower.__frame_width - hborder - distance)
def __is_on_left(new_car: Vehicle): """ Sprawdza czy samochód jest blisko lewej krawędzi obszaru czułości. :param Vehicle new_car: Obserwoway samochód. :return: Prawda/fałsz. :rtype: bool """ hborder = Configuration.horizontal_border() distance = Configuration.distance_from_border() return new_car.centerx < (hborder + distance)
def __write_settings(self): """ Zapisz wartości z widgetów """ Configuration.distance_border1(self.border1_adjustment.get_value()) Configuration.distance_border2(self.border2_adjustment.get_value()) Configuration.meters_length(self.meters_length_spin_adjustment.get_value()) Configuration.color_number(self.color_number_spin_adjustment.get_value()) Configuration.horizontal_border(self.horizontal_border_spin_adjustment.get_value()) Configuration.vertical_border(self.vertical_border_spin_adjustment.get_value()) Configuration.pixel_limit(self.pixel_limit_spin_adjustment.get_value()) Configuration.distance_from_border(self.distance_from_border_spin_adjustment.get_value()) Configuration.draw_detection_region(self.draw_detection_region_check.get_active()) Configuration.draw_speed_region(self.draw_speed_region_check.get_active()) Configuration.draw_cars(self.draw_cars_check.get_active()) Configuration.draw_conturs(self.draw_conturs_check.get_active()) Configuration.draw_speed_info(self.draw_speed_info_check.get_active()) Configuration.draw_size_info(self.draw_size_info_check.get_active()) Configuration.draw_color_bar(self.draw_color_bar_check.get_active()) Configuration.save_config()
def __select(vehicles: list, frame: Frame): """ Dokonuje selekcji znalezionych obiektów. Odrzuca obiekty znajdujące się przy krawędzi obrazu. :param list vehicles: Wektor potencjalnych samochodów. :param Frame frame: Klatka obrazu :return: Wyseleksjonowane pojazdy. :rtype: list """ height, width = frame.size() result = [] for vehic in vehicles: horizontal_border = Configuration.horizontal_border() vertical_border = Configuration.vertical_border() if (vehic.centerx > horizontal_border) and (vehic.centerx < width-horizontal_border)\ and (vehic.centery > vertical_border) and (vehic.centery < height-vertical_border): result.append(vehic) return result
def __load_settings(self): """ Wczytaj obecną konfigurację znajdującą się config.json do widgetów okna. """ self.border1_adjustment.set_value(Configuration.distance_border1()) self.border2_adjustment.set_value(Configuration.distance_border2()) self.meters_length_spin_adjustment.set_value(Configuration.meters_length()) self.color_number_spin_adjustment.set_value(Configuration.color_number()) self.horizontal_border_spin_adjustment.set_value(Configuration.horizontal_border()) self.vertical_border_spin_adjustment.set_value(Configuration.vertical_border()) self.pixel_limit_spin_adjustment.set_value(Configuration.pixel_limit()) self.distance_from_border_spin_adjustment.set_value(Configuration.distance_from_border()) self.draw_detection_region_check.set_active(Configuration.draw_detection_region()) self.draw_speed_region_check.set_active(Configuration.draw_speed_region()) self.draw_cars_check.set_active(Configuration.draw_cars()) self.draw_conturs_check.set_active(Configuration.draw_conturs()) self.draw_speed_info_check.set_active(Configuration.draw_speed_info()) self.draw_size_info_check.set_active(Configuration.draw_size_info()) self.draw_color_bar_check.set_active(Configuration.draw_color_bar())
def __select(vehicles: list, frame: Frame): """ Dokonuje selekcji znalezionych obiektów. Odrzuca obiekty znajdujące się przy krawędzi obrazu. :param list vehicles: Wektor potencjalnych samochodów. :param Frame frame: Klatka obrazu :return: Wyseleksjonowane pojazdy. :rtype: list """ height, width = frame.size() result = [] for vehic in vehicles: horizontal_border = Configuration.horizontal_border() vertical_border = Configuration.vertical_border() if ( (vehic.centerx > horizontal_border) and (vehic.centerx < width - horizontal_border) and (vehic.centery > vertical_border) and (vehic.centery < height - vertical_border) ): result.append(vehic) return result