Open Rikkert-Lensen opened 1 year ago
Changed function to:
def generate_cloud_semantic(self, bgr_img, semantic_color, depth_img, stamp):
self.generate_cloud_data_common(bgr_img, depth_img)
# Transform semantic color
self.semantic_color_vect[:,
0:1] = semantic_color[:, :, 0].reshape(-1, 1)
self.semantic_color_vect[:,
1:2] = semantic_color[:, :, 1].reshape(-1, 1)
self.semantic_color_vect[:,
2:3] = semantic_color[:, :, 2].reshape(-1, 1)
# loop over all labels to remap the color
for key, value in self.label_colors.items():
label = int(key.split("_")[1])
self.semantic_color_vect[:,0:1][self.semantic_color_vect[:, 0:1] == label] = value[0]
self.semantic_color_vect[:,1:2][self.semantic_color_vect[:, 1:2] == label] = value[1]
self.semantic_color_vect[:,2:3][self.semantic_color_vect[:, 2:3] == label] = value[2]
with open("semantic_color.txt", "w") as f:
total_number_of_points = self.semantic_color_vect.shape[0]
for i, color in enumerate(self.semantic_color_vect):
f.write(f"{i}/{total_number_of_points} {color} {color.view(np.float32).tobytes()} {color.view(np.float32).tobytes().hex()}\n")
print("saved semantic_color.txt")
# exit the program here for debugging
exit()
Yields output: semantic_color.txt
The problem:
Voxels randomly change colors as seen on the images below
Expected output:
A noiseless map where Voxels do not randomly change colors
What I found:
I went over e few steps to trace back the origin of the problem: 1. In semantic_sensor.py add to: lines 93-101:
Where
self.label_colors
is defined as:Thus forcing the
self.semantic_colors_vect
to contain only defined colors. (This is verified by looping over it and checking if the vector still contains any unknown colors) After running the code again the problem still not solved.Therefore it can be concluded that the problem is caused somewhere after lines 93-101!
2. Investigating octomap_generator.cpp In line 64 the
it->semantic_color
memory gets copied into thergb
variable.Since we know from the first step that the color values were indeed correctly set in the
self.semantic_color_vect
we expect thergb
variable to be consistent with theself.semantic_color_vect
. Thus after lines 65-67 I added:After running I do receive some "this color is not allowed:" messages in the terminal
Thus it can be concluded that the value of
it->semantic_color
is already incorrect!3. Going back to semantic_sensor.py: The only code that could be responsible for the issue can be found in:
.view('<f4')
changes the array to be represented as a float32. Maybe during this conversion something goes wrong?)Conclusion
I am not sure which one of the two is the actual cause of the problem and I am not sure how to fix it.