def show_gps_locations_mc(self, mc_dir): gmap = gmplot.GoogleMapPlotter(48.3045, 14.291153333, 16) for name, mc_list in mc_dir.items(): gmap.scatter([ mc.center_latitude for mc in mc_list if GroundTruthClass.is_parking_car(mc.get_probable_ground_truth()) ], [ mc.center_longitude for mc in mc_list if GroundTruthClass.is_parking_car(mc.get_probable_ground_truth()) ], '#FF0000', size=2, marker=False) gmap.scatter([ mc.center_latitude for mc in mc_list if not GroundTruthClass.is_parking_car( mc.get_probable_ground_truth()) ], [ mc.center_longitude for mc in mc_list if not GroundTruthClass.is_parking_car( mc.get_probable_ground_truth()) ], '#000000', size=1, marker=False) gmap.draw("C:\\sw\\master\\mymap_mcs.html")
def show_distances_plus_segmentation(self, measure_collections, fig=None): if fig is None: fig = plt.figure(8) for measure_collection in measure_collections: self.show_distance_signal_scatter(measure_collection.measures, fig=fig) xs = [ measure_collection.first_measure().timestamp, measure_collection.last_measure().timestamp ] ys = [ measure_collection.first_measure().distance, measure_collection.last_measure().distance ] probable_gt = measure_collection.get_probable_ground_truth() color = 'black' if GroundTruthClass.is_parking_car(probable_gt): color = 'orange' elif GroundTruthClass.is_overtaking_situation(probable_gt): color = 'magenta' elif GroundTruthClass.is_parking_motorcycle_or_bicycle( probable_gt): color = 'yellow' plt.plot(xs, ys, color=color) plt.scatter(xs, ys, color='black', s=5) #plt.scatter([measure_collection.first_measure().timestamp], [measure_collection.get_acceleration() * 1000], color='orange') fig.show()
def create_parking_space_map(measure_collections_files_dir): parking_cars_mcs = [] clustering_data = [] # measure_collections_dir = {} for file_name, measure_collections in measure_collections_files_dir.items(): parking_cars_mcs.extend( [mc for mc in measure_collections if GroundTruthClass.is_parking_car(mc.get_probable_ground_truth())]) clustering_data.extend([[mc.first_measure().latitude, mc.first_measure().longitude, mc.last_measure().latitude, mc.last_measure().longitude] for mc in measure_collections if GroundTruthClass.is_parking_car(mc.get_probable_ground_truth())]) print(len(clustering_data)) db = DBSCAN(metric=mc_metric, eps=8.0, min_samples=2).fit(clustering_data) core_samples_mask = np.zeros_like(db.labels_, dtype=bool) core_samples_mask[db.core_sample_indices_] = True labels = db.labels_ clusters = [] noise_cluster = None unique_labels = set(labels) for k in unique_labels: class_member_mask = (labels == k) lat = [x[0] for i, x in enumerate(clustering_data) if class_member_mask[i]] long = [x[1] for i, x in enumerate(clustering_data) if class_member_mask[i]] lat.extend([x[2] for i, x in enumerate(clustering_data) if class_member_mask[i]]) long.extend([x[3] for i, x in enumerate(clustering_data) if class_member_mask[i]]) print('k %d' % k) print('len %d' % len(lat)) if len(lat) > 0 and len(long) > 0: i = 0 max_len_between = 0.0 max_len_indices = None while i < len(lat) - 1: j = i + 1 while j < len(lat): len_between = vincenty((lat[i], long[i]), (lat[j], long[j])).meters if max_len_indices is None or len_between > max_len_between: max_len_between = len_between max_len_indices = [i, j] j += 1 i += 1 if k != -1 and max_len_indices is not None: clusters.append([lat[max_len_indices[0]], long[max_len_indices[0]], lat[max_len_indices[1]], long[max_len_indices[1]]]) else: lat = [x[0] for i, x in enumerate(clustering_data) if class_member_mask[i]] long = [x[1] for i, x in enumerate(clustering_data) if class_member_mask[i]] noise_cluster = [[lat[i], long[i]] for i in range(0, len(lat))] return clusters, noise_cluster
def get_four_classes_groundtruth(mc): ground_truth = 'FREE_SPACE' gt = mc.get_probable_ground_truth() if GroundTruthClass.is_parking_car(gt): ground_truth = 'PARKING_CAR' elif GroundTruthClass.is_overtaking_situation(gt): ground_truth = 'OVERTAKING_SITUATION' elif GroundTruthClass.is_parking_motorcycle_or_bicycle(gt): ground_truth = 'PARKING_MC_BC' return ground_truth
def get_color_list(self, measurements): cs = [] for raw in measurements: if GroundTruthClass.is_parking_car( raw.ground_truth.ground_truth_class): cs.append('g') elif GroundTruthClass.is_overtaking_situation( raw.ground_truth.ground_truth_class): cs.append('r') elif GroundTruthClass.is_parking_motorcycle_or_bicycle( raw.ground_truth.ground_truth_class): cs.append('c') else: cs.append('y') return cs
def get_dataset_parking_cars(measure_collections, dataset=None): if dataset is None: dataset = DataSet(['PARKING_CAR', 'NO_PARKING_CAR']) for mc in measure_collections: features = [ mc.avg_distance, mc.get_length(), mc.get_duration(), mc.get_nr_of_measures(), mc.get_distance_variance(), mc.avg_speed, mc.get_acceleration(), mc.first_measure().distance, mc.measures[len(mc.measures) / 2].distance, mc.last_measure().distance ] for interval, surrounding_mc in mc.time_surrounding_mcs.iteritems(): features.append(surrounding_mc.avg_distance) features.append(surrounding_mc.avg_speed) features.append(surrounding_mc.length) features.append(surrounding_mc.get_acceleration()) ground_truth = 'NO_PARKING_CAR' gt = mc.get_probable_ground_truth() if GroundTruthClass.is_parking_car(gt): ground_truth = 'PARKING_CAR' dataset.append_sample(features, ground_truth) return dataset
def show_2d_scatter(self, measure_collections, fig=None): if fig is None: fig = plt.figure(500) for measure_collection in measure_collections: xs = [measure_collection.length] ys = [measure_collection.avg_distance] probable_gt = measure_collection.get_probable_ground_truth() color = 'black' if GroundTruthClass.is_parking_car(probable_gt): color = 'orange' elif GroundTruthClass.is_overtaking_situation(probable_gt): color = 'magenta' elif GroundTruthClass.is_parking_motorcycle_or_bicycle( probable_gt): color = 'yellow' plt.scatter(xs, ys, color=color, s=5) # plt.scatter([measure_collection.first_measure().timestamp], [measure_collection.get_acceleration() * 1000], color='orange') fig.show()
def get_overtaking_situation_dataset(measure_collections, dataset=None): if dataset is None: dataset = DataSet(['NO_OVERTAKING_SITUATION', 'OVERTAKING_SITUATION']) for mc in measure_collections: if mc.get_length() > 1.0: features = [ mc.avg_distance, mc.get_length(), mc.get_duration(), mc.get_nr_of_measures(), mc.get_distance_variance(), mc.avg_speed, mc.get_acceleration(), mc.first_measure().distance, mc.measures[len(mc.measures) / 2].distance, mc.last_measure().distance ] for interval, surrounding_mc in mc.time_surrounding_mcs.iteritems( ): features.append(surrounding_mc.avg_distance) features.append(surrounding_mc.avg_speed) features.append(surrounding_mc.length) features.append(surrounding_mc.get_acceleration()) ground_truth = 'NO_OVERTAKING_SITUATION' gt = mc.get_probable_ground_truth() if GroundTruthClass.is_overtaking_situation(gt): ground_truth = 'OVERTAKING_SITUATION' # undersampling if not GroundTruthClass.is_overtaking_situation( gt) and random.randint(0, 10) < 10: dataset.append_sample(features, ground_truth) elif GroundTruthClass.is_overtaking_situation(gt): i = 0 while i < 3: dataset.append_sample(features, ground_truth) i += 1 return dataset
gmap = gmplot.GoogleMapPlotter(48.3045, 14.291153333, 16) for k in range(0, len(clusters)): gmap.plot([clusters[k][0], clusters[k][2]], [clusters[k][1], clusters[k][3]], edge_width=5) bounding_box = get_bounding_box(clusters[k]) gmap.polygon([p[0] for p in bounding_box], [p[1] for p in bounding_box]) print('mcs ', [len(mc_list) for name, mc_list in measure_collections_files_dir.items()]) filtered_mcs = filter_parking_space_map_mcs(measure_collections_files_dir, clusters) print('filtered mcs ', [len(mc_list) for name, mc_list in filtered_mcs.items()]) for name, mc_list in filtered_mcs.items(): gmap.scatter( [mc.center_latitude for mc in mc_list if GroundTruthClass.is_parking_car(mc.get_probable_ground_truth())], [mc.center_longitude for mc in mc_list if GroundTruthClass.is_parking_car(mc.get_probable_ground_truth())], '#00FF00', size=2, marker=False) gmap.scatter([mc.center_latitude for mc in mc_list if not GroundTruthClass.is_parking_car(mc.get_probable_ground_truth())], [mc.center_longitude for mc in mc_list if not GroundTruthClass.is_parking_car(mc.get_probable_ground_truth())], '#000000', size=1, marker=False) if noise_cluster is not None: lat = [noise[0] for noise in noise_cluster] long = [noise[1] for noise in noise_cluster] gmap.scatter(lat, long, '#0000FF', size=4, marker=False) gmap.draw("C:\\sw\\master\\mymap_parking_clusters_directional.html")
def __init__(self, data_file, measure_collections_f, additional_interval, restart=True, **kwargs): super(VisualizationApp, self).__init__(**kwargs) self.restart = restart self.data_file = data_file self.additional_interval = additional_interval self.camera_folder = data_file + '_images_Camera\\' self.camera_files = sorted([ f for f in os.listdir(self.camera_folder) if os.path.isfile(os.path.join(self.camera_folder, f)) and f.endswith('.jpg') ]) self.ground_truth_file = [ os.path.join(self.camera_folder, f) for f in os.listdir(self.camera_folder) if os.path.isfile(os.path.join(self.camera_folder, f)) and f.startswith('00gt') ][0] self.image = Image(source=os.path.join(self.camera_folder, self.camera_files[0]), size=(352, 288), pos=(0, 0)) #with self.image.canvas as canvas: # Color(1., 0, 0) # Rectangle(size=(1, 10000)) self.graph = Graph( xlabel='Time [s]', ylabel='Distance [m]', #x_ticks_minor=0.5, x_ticks_major=2, y_ticks_major=1, y_grid_label=True, x_grid_label=True, padding=10, x_grid=True, y_grid=True, xmin=0, xmax=0, ymin=-1, ymax=11) last_mc = None self.first_timestamp = measure_collections_f[0].first_measure( ).timestamp for mc in measure_collections_f: color = [1, 1, 0, 1] if mc.prediction == 'FREE_SPACE': color = [1, 0, 1, 1] elif mc.prediction == 'PARKING_CAR': color = [0, 1, 1, 1] elif mc.prediction == 'OVERTAKING_SITUATION': color = [0, 0, 1, 1] plot = MeshLinePlot(color=color) plot.points = [(m.timestamp - self.first_timestamp, m.distance) for m in mc.measures] self.graph.add_plot(plot) color_actual = [1, 1, 0, 1] if mc.get_probable_ground_truth() == GroundTruthClass.FREE_SPACE: color_actual = [1, 0, 1, 1] elif GroundTruthClass.is_parking_car( mc.get_probable_ground_truth()): color_actual = [0, 1, 1, 1] elif GroundTruthClass.is_overtaking_situation( mc.get_probable_ground_truth()): color_actual = [0, 0, 1, 1] plot_actual = MeshLinePlot(color=color_actual) plot_actual.points = [(m.timestamp - self.first_timestamp, m.distance - 0.1) for m in mc.measures] self.graph.add_plot(plot_actual) if last_mc is not None: plot_next = MeshLinePlot(color=[1, 1, 1, 1]) plot_next.points = [ (last_mc.last_measure().timestamp - self.first_timestamp, last_mc.last_measure().distance), (mc.first_measure().timestamp - self.first_timestamp, mc.first_measure().distance) ] self.graph.add_plot(plot_next) last_mc = mc # plot = MeshLinePlot(color=[1, 1, 1, 1]) # plot.points = [(m.timestamp - self.first_timestamp, m.distance) for m in self.measurements] # self.graph.add_plot(plot) self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.running = True self.cur_index = -1 self.show_next_image(0)
def get_parking_classes_groundtruth(mc): ground_truth = 'NO_PARKING_CAR' gt = mc.get_probable_ground_truth() if GroundTruthClass.is_parking_car(gt): ground_truth = 'PARKING_CAR' return ground_truth