pybackend_example_1_general.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 ## pybackend example #1 - A general overview ##
6 ###############################################
7 
8 # First import the library
9 import pybackend2 as rs
10 import time
11 
12 def on_frame(profile, f):
13  print ("Received %d bytes" % f.frame_size)
14 
15  # Accessing image pixels
16  p = f.pixels
17  print ("First 10 bytes are: ")
18  for i in range(10):
19  print (hex(p[i]))
20  print
21 
22 try:
23  # Building a device
24  backend = rs.create_backend()
25  infos = backend.query_uvc_devices()
26  print("There are %d connected UVC devices" % len(infos))
27  if len(infos) is 0: exit(1)
28  info = infos[2]
29  dev = backend.create_uvc_device(info)
30 
31  print ("VID=%d, PID=%d, MI=%d, UID=%s" % (info.vid, info.pid, info.mi, info.unique_id))
32 
33  # Turn on power
34  print ("Move device to D0 power state...")
35  dev.set_power_state(rs.D0)
36 
37  # Configure streaming
38  print ("Print list of UVC profiles supported by the device...")
39  profiles = dev.get_profiles()
40  for p in profiles:
41  print (p)
42  # save IR VGA setting for later
43  if p.width == 640 and p.height == 480 and p.fps == 30 and p.format == 1196574041:
44  vga = p
45  first = profiles[0]
46 
47  print ("Negotiate Probe-Commit for first profile")
48  dev.probe_and_commit(first, on_frame)
49 
50  # XU controls
51  xu = rs.extension_unit(0, 3, 2, rs.guid("C9606CCB-594C-4D25-af47-ccc496435995")) # Define the Depth XU
52  dev.init_xu(xu) # initialize depth XU
53  ae = dev.get_xu(xu, 0xB, 1) # get XU value. args: XU, control #, # of bytes
54  print ("Auto Exposure option is:", ae)
55  print ("Setting Auto Exposure option to new value")
56  dev.set_xu(xu, 0x0B, [0x00]) # set XU value. args: XU, control #, list of bytes
57  ae = dev.get_xu(xu, 0xB, 1)
58  print ("New Auto Exposure setting is:", ae)
59 
60  # PU controls
61  gain = dev.get_pu(rs.option.gain)
62  print ("Gain = %d" % gain)
63  print ("Setting gain to new value")
64  dev.set_pu(rs.option.gain, 32)
65  gain = dev.get_pu(rs.option.gain)
66  print ("New gain = %d" % gain)
67 
68  # Start streaming
69  print ("Start listening for callbacks (for all pins)...")
70  dev.start_callbacks()
71 
72  print ("Start streaming (from all pins)...")
73  dev.stream_on()
74 
75  print ("Wait for 5 seconds while frames are expected:")
76  time.sleep(5)
77 
78  # Close device
79  print ("Stop listening for new callbacks...")
80  dev.stop_callbacks()
81 
82  print ("Close the specific pin...")
83  dev.close(first)
84 
85  # saving frames to disk
86  def save_frame(profile, f):
87  f.save_png("pybackend_example_1_general_depth_frame.png", 640, 480, f.frame_size / (640*480))
88 
89  print ("Saving an IR VGA frame using profile:", vga)
90  dev.probe_and_commit(vga, save_frame)
91 
92  dev.set_xu(xu, 0x0B, [0x01]) # turn autoexposure back on
93  dev.start_callbacks()
94  dev.stream_on()
95  time.sleep(1)
96  dev.close(vga)
97 
98  print ("Move device to D3")
99  dev.set_power_state(rs.D3)
100  pass
101 except Exception as e:
102  print (e)
103  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