color-camera.py 962 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import cv2
  2. import depthai as dai
  3. # Create pipeline
  4. pipeline = dai.Pipeline()
  5. # Define source and output
  6. camRgb = pipeline.create(dai.node.ColorCamera)
  7. xoutVideo = pipeline.create(dai.node.XLinkOut)
  8. xoutVideo.setStreamName("video")
  9. # Properties
  10. camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
  11. camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
  12. camRgb.setVideoSize(1280, 720)
  13. xoutVideo.input.setBlocking(False)
  14. xoutVideo.input.setQueueSize(1)
  15. # Linking
  16. camRgb.video.link(xoutVideo.input)
  17. # Connect to device and start pipeline
  18. with dai.Device(pipeline) as device:
  19. video = device.getOutputQueue(name="video", maxSize=1, blocking=False)
  20. while True:
  21. videoIn = video.get()
  22. # Get BGR frame from NV12 encoded video frame to show with opencv
  23. # Visualizing the frame on slower hosts might have overhead
  24. cv2.imshow("video", videoIn.getCvFrame())
  25. if cv2.waitKey(1) == 27:
  26. break