python-tutorial-1-depth.py
Go to the documentation of this file.
1 ## License: Apache 2.0. See LICENSE file in root directory.
2 ## Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.
3 
4 #####################################################
5 ## librealsense tutorial #1 - Accessing depth data ##
6 #####################################################
7 
8 # First import the library
9 import pyrealsense2 as rs
10 
11 try:
12  # Create a context object. This object owns the handles to all connected realsense devices
13  pipeline = rs.pipeline()
14 
15  # Configure streams
16  config = rs.config()
17  config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
18 
19  # Start streaming
20  pipeline.start(config)
21 
22  while True:
23  # This call waits until a new coherent set of frames is available on a device
24  # Calls to get_frame_data(...) and get_frame_timestamp(...) on a device will return stable values until wait_for_frames(...) is called
25  frames = pipeline.wait_for_frames()
26  depth = frames.get_depth_frame()
27  if not depth: continue
28 
29  # 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
30  coverage = [0]*64
31  for y in range(480):
32  for x in range(640):
33  dist = depth.get_distance(x, y)
34  if 0 < dist and dist < 1:
35  coverage[x//10] += 1
36 
37  if y%20 is 19:
38  line = ""
39  for c in coverage:
40  line += " .:nhBXWW"[c//25]
41  coverage = [0]*64
42  print(line)
43  exit(0)
44 #except rs.error as e:
45 # # Method calls agaisnt librealsense objects may throw exceptions of type pylibrs.error
46 # print("pylibrs.error was thrown when calling %s(%s):\n", % (e.get_failed_function(), e.get_failed_args()))
47 # print(" %s\n", e.what())
48 # exit(1)
49 except Exception as e:
50  print(e)
51  pass
static std::string print(const transformation &tf)
static const textual_icon exit
Definition: model-views.h:254


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39