import numpy as np import matplotlib.pyplot as plt import cv2 from sklearn.cluster import DBSCAN import os os.chdir( '/Users/ChrisErnst/Development/Perception-Challenge-Udacity-RoboticsND-Project3' ) from extra_functions import cluster_gen # Generate some clusters! n_clusters = 50 clusters_x, clusters_y = cluster_gen(n_clusters) # Convert to a single dataset in OpenCV format data = np.float32( (np.concatenate(clusters_x), np.concatenate(clusters_y))).transpose() # Define max_distance (eps parameter in DBSCAN()) max_distance = 1 db = DBSCAN(eps=max_distance, min_samples=10).fit(data) # Extract a mask of core cluster members core_samples_mask = np.zeros_like(db.labels_, dtype=bool) core_samples_mask[db.core_sample_indices_] = True # Extract labels (-1 is used for outliers) labels = db.labels_ n_clusters = len(set(labels)) - (1 if -1 in labels else 0) unique_labels = set(labels) # Plot up the results! min_x = np.min(data[:, 0]) max_x = np.max(data[:, 0]) min_y = np.min(data[:, 1])
import numpy as np import matplotlib.pyplot as plt import cv2 from sklearn.cluster import DBSCAN import os os.chdir('/Users/ChrisErnst/Development/Perception-Challenge-Udacity-RoboticsND-Project3') from extra_functions import cluster_gen # Generate some clusters! n_clusters = 50 clusters_x, clusters_y = cluster_gen(n_clusters) # Convert to a single dataset in OpenCV format data = np.float32((np.concatenate(clusters_x), np.concatenate(clusters_y))).transpose() # Define max_distance (eps parameter in DBSCAN()) max_distance = 1 db = DBSCAN(eps=max_distance, min_samples=10).fit(data) # Extract a mask of core cluster members core_samples_mask = np.zeros_like(db.labels_, dtype=bool) core_samples_mask[db.core_sample_indices_] = True # Extract labels (-1 is used for outliers) labels = db.labels_ n_clusters = len(set(labels)) - (1 if -1 in labels else 0) unique_labels = set(labels) # Plot up the results! min_x = np.min(data[:, 0]) max_x = np.max(data[:, 0]) min_y = np.min(data[:, 1]) max_y = np.max(data[:, 1]) fig = plt.figure(figsize=(12,6))