3 import pyrealsense2
as rs
9 sd = rs.software_device()
10 depth_sensor = sd.add_sensor(
"Depth")
12 intr = rs.intrinsics()
15 intr.ppx = 637.951293945312
16 intr.ppy = 360.783233642578
17 intr.fx = 638.864135742188
18 intr.fy = 638.864135742188
20 vs = rs.video_stream()
21 vs.type = rs.stream.infrared
26 vs.height = intr.height
30 depth_sensor.add_video_stream(vs)
32 vs.type = rs.stream.depth
33 vs.fmt = rs.format.z16
37 depth_sensor.add_video_stream(vs)
39 vs.type = rs.stream.depth
40 vs.fmt = rs.format.z16
44 depth_sensor.add_video_stream(vs)
46 vs.type = rs.stream.depth
47 vs.fmt = rs.format.z16
51 depth_sensor.add_video_stream(vs)
53 depth_sensor.add_read_only_option(rs.option.depth_units, 0.001)
54 name =
"virtual camera"
55 sd.register_info(rs.camera_info.name, name)
60 dev = ctx.query_devices()[0]
61 for d
in ctx.query_devices():
62 if d.get_info(rs.camera_info.name) == name:
66 if (len(sys.argv) > 1):
67 images_path =
str(sys.argv[1])
69 rec = rs.recorder(images_path +
"/1.bag", dev)
70 sensor = rec.query_sensors()[0]
73 sensor.open(sensor.get_stream_profiles())
76 files = glob.glob1(images_path,
"gt*")
79 idx = (f.split(
'-')[1]).
split(
'.')[0]
80 index.append(int(idx))
83 left_name = images_path +
"/left-" +
str(i) +
".png"
84 depth_name = images_path +
"/gt-" +
str(i) +
".png"
85 result_name = images_path +
"/res-" +
str(i) +
".png"
86 denoised_name = images_path +
"/res_denoised-" +
str(i) +
".png"
88 img = cv2.imread(left_name)
89 img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
91 f = rs.software_video_frame()
94 f.pixels = np.asarray(img, dtype=
"byte")
95 f.timestamp = i * 0.01
97 f.profile = sensor.get_stream_profiles()[0].as_video_stream_profile()
98 depth_sensor.on_video_frame(f)
102 f3 = rs.software_video_frame()
103 img = cv2.imread(result_name, cv2.IMREAD_ANYDEPTH)
104 f3.stride = 2 * intr.width
106 px = np.asarray(img, dtype=
"ushort")
108 f3.timestamp = i * 0.01
110 f3.profile = sensor.get_stream_profiles()[1].as_video_stream_profile()
111 depth_sensor.on_video_frame(f3)
115 f4 = rs.software_video_frame()
116 img = cv2.imread(depth_name, cv2.IMREAD_ANYDEPTH)
117 f4.stride = 2 * intr.width
119 px = np.asarray(img, dtype=
"ushort")
121 f4.timestamp = i * 0.01
123 f4.profile = sensor.get_stream_profiles()[2].as_video_stream_profile()
124 depth_sensor.on_video_frame(f4)
127 f5 = rs.software_video_frame()
128 img = cv2.imread(denoised_name, cv2.IMREAD_ANYDEPTH)
129 f5.stride = 2 * intr.width
131 px = np.asarray(img, dtype=
"ushort")
133 f5.timestamp = i * 0.01
135 f5.profile = sensor.get_stream_profiles()[3].as_video_stream_profile()
136 depth_sensor.on_video_frame(f5)
142 f = q.wait_for_frame()