Skip to content

Commit 3e4ec9b

Browse files
Generate laser line detection heat maps
1 parent 0e14a69 commit 3e4ec9b

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

src/auv_cal/laser_calibrator.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,37 @@ class to trigger the computation of laser plane parameters
11371137
Console.info("Found {} bottom peaks in camera 1!".format(str(count1lb)))
11381138
Console.info("Found {} bottom peaks in camera 2!".format(str(count2lb)))
11391139

1140+
# Generate laser detection heat maps
1141+
ts = time.strftime("%Y%m%d_%H%M%S")
1142+
size_l = (self.sc.left.image_height, self.sc.left.image_width)
1143+
size_r = (self.sc.right.image_height, self.sc.right.image_width)
1144+
output_path = (
1145+
get_processed_folder(limages[0].parents[1])
1146+
/ f"{limages[0].parent.name}_laser_detection"
1147+
/ f"{ts}_laser_detection_heatmap.png"
1148+
)
1149+
self.generate_detection_heat_map(peaks1, size_l, output_path)
1150+
output_path = (
1151+
get_processed_folder(rimages[0].parents[1])
1152+
/ f"{rimages[0].parent.name}_laser_detection"
1153+
/ f"{ts}_laser_detection_heatmap.png"
1154+
)
1155+
self.generate_detection_heat_map(peaks2, size_r, output_path)
1156+
if self.two_lasers:
1157+
output_path = (
1158+
get_processed_folder(limages[0].parents[1])
1159+
/ f"{limages[0].parent.name}_laser_detection"
1160+
/ f"{ts}_laser_detection_heatmap_bottom.png"
1161+
)
1162+
self.generate_detection_heat_map(peaks1b, size_l, output_path)
1163+
output_path = (
1164+
get_processed_folder(rimages[0].parents[1])
1165+
/ f"{rimages[0].parent.name}_laser_detection"
1166+
/ f"{ts}_laser_detection_heatmap_bottom.png"
1167+
)
1168+
self.generate_detection_heat_map(peaks2b, size_r, output_path)
1169+
1170+
# Triangulate point cloud from laser detections
11401171
point_cloud = []
11411172
point_cloud_b = []
11421173

@@ -1239,6 +1270,35 @@ class to trigger the computation of laser plane parameters
12391270
# self.yaml_msg_b = self.fit_and_save(point_cloud_b_rs)
12401271
self.yaml_msg_b = self.fit_and_save(point_cloud_b_filt, processed_folder)
12411272

1273+
def generate_detection_heat_map(self, laser_detections, image_size, output_path):
1274+
"""Generate heat map of laser detections for debugging purposes"""
1275+
1276+
heat_map = np.zeros(image_size, dtype=np.uint16)
1277+
for frame in laser_detections:
1278+
for p in frame:
1279+
row = int(round(p[0]))
1280+
col = int(round(p[1]))
1281+
if 0 <= row < image_size[0] and 0 <= col < image_size[1]:
1282+
heat_map[row, col] += 1
1283+
1284+
heat_map_normalized = cv2.normalize(
1285+
heat_map,
1286+
None,
1287+
alpha=0,
1288+
beta=255,
1289+
norm_type=cv2.NORM_MINMAX,
1290+
dtype=cv2.CV_8U,
1291+
)
1292+
1293+
heat_map_jet = cv2.applyColorMap(heat_map_normalized, cv2.COLORMAP_JET)
1294+
# Make pixels with no detections black
1295+
no_detections = np.where(heat_map == 0)
1296+
heat_map_jet[no_detections] = [0, 0, 0]
1297+
1298+
output_path.parent.mkdir(parents=True, exist_ok=True)
1299+
cv2.imwrite(str(output_path), heat_map_jet)
1300+
Console.info(f"Saved laser detection heat map to {output_path}")
1301+
12421302
def yaml(self):
12431303
return self.yaml_msg
12441304

0 commit comments

Comments
 (0)