41 import libmultisense
as lms
44 luma_point_type = np.dtype({
'names': [
'x',
'y',
'z',
'luma'],
45 'formats': [np.float32, np.float32, np.float32, np.uint8],
46 'offsets': [0, 4, 8, 12],
49 color_point_type = np.dtype({
'names': [
'x',
'y',
'z',
'blue',
'green',
'red'],
50 'formats': [np.float32, np.float32, np.float32, np.uint8, np.uint8, np.uint8],
51 'offsets': [0, 4, 8, 12, 13, 14],
55 channel_config = lms.ChannelConfig()
56 channel_config.ip_address = args.ip_address
57 channel_config.mtu = args.mtu
59 with lms.Channel.create(channel_config)
as channel:
61 print(
"Invalid channel")
64 config = channel.get_config()
65 config.frames_per_second = 10.0
66 if channel.set_config(config) != lms.Status.OK:
67 print(
"Cannot set configuration")
70 info = channel.get_info()
71 color_stream = lms.DataSource.AUX_RECTIFIED_RAW
if args.use_color
and info.device.has_aux_camera()
else lms.DataSource.LEFT_RECTIFIED_RAW
73 if channel.start_streams([color_stream, lms.DataSource.LEFT_DISPARITY_RAW]) != lms.Status.OK:
74 print(
"Unable to start streams")
78 frame = channel.get_next_image_frame()
80 if color_stream == lms.DataSource.LEFT_RECTIFIED_RAW:
81 point_cloud = lms.create_gray8_pointcloud(frame,
83 lms.DataSource.LEFT_RECTIFIED_RAW,
84 lms.DataSource.LEFT_DISPARITY_RAW)
87 point_cloud_array = point_cloud.as_raw_array.view(luma_point_type)
88 mean_depth = np.mean(point_cloud_array[
"z"])
89 print(
"Mean depth:", mean_depth,
"(m)")
91 print(
"Saving pointcloud for frame id: ", frame.frame_id)
96 point_cloud = lms.create_bgr_pointcloud(frame.get_image(lms.DataSource.LEFT_DISPARITY_RAW),
102 point_cloud_array = point_cloud.as_raw_array.view(color_point_type)
103 mean_depth = np.mean(point_cloud_array[
"z"])
104 print(
"Mean depth:", mean_depth,
"(m)")
106 print(
"Saving color pointcloud for frame id: ", frame.frame_id)
110 if __name__ ==
'__main__':
111 parser = argparse.ArgumentParser(
"LibMultiSense save image utility")
112 parser.add_argument(
"-a",
"--ip_address", default=
"10.66.171.21", help=
"The IPv4 address of the MultiSense.")
113 parser.add_argument(
"-m",
"--mtu", type=int, default=1500, help=
"The MTU to use to communicate with the camera.")
114 parser.add_argument(
"-r",
"--max-range", type=float, default=50.0, help=
"The max point cloud range in meters.")
115 parser.add_argument(
"-c",
"--use-color", action=
"store_true", help=
"Try to use the aux color image for colorizing")
116 main(parser.parse_args())