Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import cv2
  2. import depthai as dai
  3. from depthai_sdk.fps import FPSHandler
  4.  
  5.  
  6. # Create pipeline
  7. pipeline = dai.Pipeline()
  8. pipeline.setXLinkChunkSize(0)
  9.  
  10. # Define sources and outputs
  11. camRgb = pipeline.create(dai.node.ColorCamera)
  12. monoLeft = pipeline.create(dai.node.MonoCamera)
  13. monoRight = pipeline.create(dai.node.MonoCamera)
  14. stereo = pipeline.create(dai.node.StereoDepth)
  15.  
  16. xoutRgb = pipeline.create(dai.node.XLinkOut)
  17. xoutDepth = pipeline.create(dai.node.XLinkOut)
  18.  
  19. xoutRgb.setStreamName("rgb")
  20. xoutDepth.setStreamName("depth")
  21.  
  22. # mono and rgb properties
  23. set_fps = 30
  24. camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP)
  25. camRgb.setFps(set_fps)
  26.  
  27. monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
  28. monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
  29. monoLeft.setFps(set_fps)
  30.  
  31. monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
  32. monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
  33. monoRight.setFps(set_fps)
  34.  
  35. # stereoConfig
  36. stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
  37. stereo.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_7x7)
  38.  
  39. stereoConfig = stereo.initialConfig.get()
  40. stereoConfig.postProcessing.speckleFilter.enable = True
  41. stereoConfig.postProcessing.speckleFilter.speckleRange = 50
  42. stereoConfig.postProcessing.spatialFilter.enable = True
  43. stereoConfig.postProcessing.spatialFilter.holeFillingRadius = 2
  44. stereoConfig.postProcessing.spatialFilter.numIterations = 1
  45. stereoConfig.postProcessing.thresholdFilter.minRange = 150
  46. stereoConfig.postProcessing.thresholdFilter.maxRange = 1000
  47. stereoConfig.postProcessing.decimationFilter.decimationFactor = 2
  48. stereo.initialConfig.set(stereoConfig)
  49.  
  50. stereo.setLeftRightCheck(True)
  51. stereo.setExtendedDisparity(True)
  52.  
  53. # Align depth map to rgb
  54. stereo.setDepthAlign(dai.CameraBoardSocket.RGB)
  55. stereo.setOutputSize(800, 599)
  56. # Linking
  57. monoLeft.out.link(stereo.left)
  58. monoRight.out.link(stereo.right)
  59.  
  60. camRgb.isp.link(xoutRgb.input)
  61. stereo.depth.link(xoutDepth.input)
  62.  
  63. with dai.Device(version=dai.OpenVINO.Version.VERSION_2021_4, maxUsbSpeed=dai.UsbSpeed.SUPER_PLUS) as device:
  64.  
  65.     # try:
  66.     #     calibData = device.readCalibration2()
  67.     #     lensPosition = calibData.getLensPosition(dai.CameraBoardSocket.RGB)
  68.     #     if lensPosition:
  69.     #         camRgb.initialControl.setManualFocus(lensPosition)
  70.     # except:
  71.     #     raise
  72.     print('USB SPEED', device.getUsbSpeed())
  73.  
  74.     device.startPipeline(pipeline)
  75.  
  76.     rgbQ = device.getOutputQueue('rgb', maxSize=4, blocking=False)
  77.     depthQ = device.getOutputQueue('depth', maxSize=4, blocking=False)
  78.  
  79.     fps = FPSHandler()
  80.     fps2 = FPSHandler()
  81.  
  82.     synced_msgs = None
  83.     while True:
  84.  
  85.         if rgbQ.has():
  86.             rgbQ.get()
  87.             fps.nextIter()
  88.             print('RGB FPS', fps.fps())
  89.  
  90.  
  91.         if depthQ.has():
  92.             depthQ.get()
  93.             fps2.nextIter()
  94.             print('DEPTH FPS', fps2.fps())
  95.  
  96.         if cv2.waitKey(1) == ord('q'):
  97.             break
  98.