-
Notifications
You must be signed in to change notification settings - Fork 5
/
lidar_realsense.py
47 lines (40 loc) · 1.43 KB
/
lidar_realsense.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# First import the library
import cv2
import pyrealsense2 as rs
import numpy as np
# Create a context object. This object owns the handles to all connected realsense devices
pipeline = rs.pipeline()
pipeline.start()
cnt = 1
while True:
# Create a pipeline object. This object configures the streaming camera and owns it's handle
frames = pipeline.wait_for_frames()
print(dir(frames)) # see all the data fields
depth = frames.get_depth_frame()
# Print a simple text-based representation of the image, by breaking it into 10x20 pixel regions and
# approximating the coverage of pixels within one meter
# coverage = np.zeros(64)
# for y in range(480):
# for x in range(640):
# dist = depth.get_distance(x, y)
# if 0 < dist and dist < 1:
# coverage[int(x/10)] += 1
#
# if y % 20 == 19:
# line = ""
# for c in coverage:
# line += " .:nhBXWW" + str(c/25)
# coverage = [0]*64
# # print(line)
depth_data = depth.as_frame().get_data()
np_image = np.asanyarray(depth_data)
# print('Frame:', cnt)
print('Frame:', frames.frame_number)
cv2.imshow("Lidar Image", np_image)
# If the 'c' key is pressed, break the while loop
key = cv2.waitKey(1) & 0xFF
if key == ord("c"):
break
cnt += 1
pipeline.stop()
cv2.destroyAllWindows()