8 from skimage.segmentation
import slic
9 from skimage.feature
import peak_local_max
10 from skimage.morphology
import binary_closing
11 import sensor_msgs.msg
18 footprint = np.ones((3, 3))
19 segments = slic(depth_img)
21 local_maxi = peak_local_max(
22 depth_img, labels=segments, footprint=footprint, indices=
False)
24 fg_mask =
descent_closing(local_maxi, init_selem=np.ones((3, 3)), n_times=6)
26 return fg_mask, bg_mask
32 depth_max = depth.max() + 1.0
36 compressed_msg = sensor_msgs.msg.CompressedImage()
37 compressed_msg.format =
'{}; compressedDepth png'.
format(
40 if encoding ==
'32FC1':
41 depth_quant_a = depth_quantization * (depth_quantization + 1.0)
42 depth_quant_b = 1.0 - depth_quant_a / depth_max
43 inv_depth_img = np.zeros_like(depth, dtype=np.uint16)
44 target_pixel = np.logical_and(depth_max > depth, depth > 0)
45 inv_depth_img[target_pixel] = depth_quant_a / \
46 depth[target_pixel] + depth_quant_b
48 compressed_msg.data = struct.pack(
49 'iff', 0, depth_quant_a, depth_quant_b)
50 compressed_msg.data += np.array(
51 cv2.imencode(
'.png', inv_depth_img)[1]).tostring()
53 raise NotImplementedError(
"Not supported compressedDepth encoding {}"