Skip to content

Instantly share code, notes, and snippets.

@oliverlee
Created April 23, 2018 09:28
Show Gist options
  • Select an option

  • Save oliverlee/29add169238a84ac587d5b4d19f1ffbc to your computer and use it in GitHub Desktop.

Select an option

Save oliverlee/29add169238a84ac587d5b4d19f1ffbc to your computer and use it in GitHub Desktop.
sample car detection with lidar
from hdbscan import HDBSCAN
from sklearn import metrics
from sklearn.preprocessing import StandardScaler
import numpy as np
import scipy.spatial
import seaborn as sns
xy_lim = ((-60, 60), (0, 60))
n = 12
x, y = map(lambda x: x.compressed(), record[n:n + 1].cartesian(*xy_lim))
X = np.vstack((x, y)).transpose()
hdb = HDBSCAN(min_cluster_size=40, metric='euclidean').fit(X)
hdb_labels = hdb.labels_
hdb_unique_labels = set(hdb_labels)
colors = sns.husl_palette(len(hdb_unique_labels))
fig, ax = plt.subplots()
ax.plot(x, y, '*', color='black', zorder=0)
for i in range(len(hdb_unique_labels)):
index = hdb_labels == i
if len(index):
hull = scipy.spatial.ConvexHull(X[index])
if hull.area < 10:
ax.scatter(x[index], y[index], color=colors[i], zorder=1)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment