old_contents: import logging
  logging.basicConfig(level=logging.INFO)
  
  import time
  import numpy as np
  import cv2
  import pyrealsense as pyrs
  from pyrealsense.constants import rs_option
  
  
  color_stream = pyrs.stream.ColorStream(color_format='bgr')
  depth_stream = pyrs.stream.DepthStream()
  
  
  def convert_z16_to_bgr(frame):
      hist = np.histogram(frame, bins=0x10000)[0]
      hist = np.cumsum(hist)
      hist -= hist[0]
      rgb_frame = np.empty(frame.shape[:2] + (3,), dtype=np.uint8)
  
      zeros = frame == 0
      non_zeros = frame != 0
  
      f = hist[frame[non_zeros]] * 255 / hist[0xFFFF]
      rgb_frame[non_zeros, 0] = 255 - f
      rgb_frame[non_zeros, 1] = 0
      rgb_frame[non_zeros, 2] = f
      rgb_frame[zeros, 0] = 20
      rgb_frame[zeros, 1] = 5
      rgb_frame[zeros, 2] = 0
      return rgb_frame
  
  
  with pyrs.Service() as serv:
      with serv.Device(streams=(color_stream, depth_stream)) as dev:
  
          dev.apply_ivcam_preset(0)
  
          try:  # set custom gain/exposure values to obtain good depth image
              custom_options = [(rs_option.RS_OPTION_R200_LR_EXPOSURE, 30.0),
                                (rs_option.RS_OPTION_R200_LR_GAIN, 100.0)]
              dev.set_device_options(*zip(*custom_options))
          except pyrs.RealsenseError:
              pass  # options are not available on all devices
  
  
          cnt = 0
          last = time.time()
          smoothing = 0.9
          fps_smooth = 30
  
          while True:
  
              cnt += 1
              if (cnt % 10) == 0:
                  now = time.time()
                  dt = now - last
                  fps = 10/dt
                  fps_smooth = (fps_smooth * smoothing) + (fps * (1.0-smoothing))
                  last = now
  
              dev.wait_for_frames()
              c = dev.color  # set to bgr
              d = dev.depth  # * dev.depth_scale * 1000
              # d = cv2.applyColorMap(d.astype(np.uint8), cv2.COLORMAP_RAINBOW)
              d = convert_z16_to_bgr(d)
  
              cd = np.concatenate((c, d), axis=1)
  
              cv2.putText(cd, str(fps_smooth)[:4], (0, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 0))
  
              cv2.imshow('', cd)
              if cv2.waitKey(1) & 0xFF == ord('q'):
                  break
  
new_contents: import logging
  logging.basicConfig(level=logging.INFO)
  
  import time
  import numpy as np
  import cv2
  import pyrealsense as pyrs
  from pyrealsense.constants import rs_option
  
  
  with pyrs.Service() as serv:
      with serv.Device() as dev:
  
          dev.apply_ivcam_preset(0)
  
          try:  # set custom gain/exposure values to obtain good depth image
              custom_options = [(rs_option.RS_OPTION_R200_LR_EXPOSURE, 30.0),
                                (rs_option.RS_OPTION_R200_LR_GAIN, 100.0)]
              dev.set_device_options(*zip(*custom_options))
          except pyrs.RealsenseError:
              pass  # options are not available on all devices
  
          cnt = 0
          last = time.time()
          smoothing = 0.9
          fps_smooth = 30
  
          while True:
  
              cnt += 1
              if (cnt % 10) == 0:
                  now = time.time()
                  dt = now - last
                  fps = 10/dt
                  fps_smooth = (fps_smooth * smoothing) + (fps * (1.0-smoothing))
                  last = now
  
              dev.wait_for_frames()
              c = dev.color
              c = cv2.cvtColor(c, cv2.COLOR_RGB2BGR)
              d = dev.depth * dev.depth_scale * 1000
              d = cv2.applyColorMap(d.astype(np.uint8), cv2.COLORMAP_RAINBOW)
  
              cd = np.concatenate((c, d), axis=1)
  
              cv2.putText(cd, str(fps_smooth)[:4], (0, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 0))
  
              cv2.imshow('', cd)
              if cv2.waitKey(1) & 0xFF == ord('q'):
                  break
  
subject: Revert show_cv2 example