def compute_color_histograms(cloud, using_hsv=False):
numBins = 64
# Compute histograms for the clusters
point_colors_list = []
# Step through each point in the point cloud
for point in pc2.read_points(cloud, skip_nans=True):
rgb_list = float_to_rgb(point[3])
if using_hsv:
point_colors_list.append(rgb_to_hsv(rgb_list) * 255)
else:
point_colors_list.append(rgb_list)
# Populate lists with color values
channel_1_vals = []
channel_2_vals = []
channel_3_vals = []
for color in point_colors_list:
channel_1_vals.append(color[0])
channel_2_vals.append(color[1])
channel_3_vals.append(color[2])
# Compute histograms for the colors in the point cloud
channel1_hist = np.histogram(channel_1_vals, bins=numBins, range=(0, 256))
channel2_hist = np.histogram(channel_2_vals, bins=numBins, range=(0, 256))
channel3_hist = np.histogram(channel_3_vals, bins=numBins, range=(0, 256))
# Concatenate and normalize the histograms
hist_features = np.concatenate((channel1_hist[0],channel2_hist[0], channel3_hist[0])).astype(np.float64)
normed_features = hist_features / np.sum(hist_features)
return normed_features
评论列表
文章目录