script-example.py 799 B

1234567891011121314151617181920212223242526272829303132333435
  1. import cv2
  2. import depthai as dai
  3. # Start defining a pipeline
  4. pipeline = dai.Pipeline()
  5. # Define a source - color camera
  6. cam = pipeline.create(dai.node.ColorCamera)
  7. # Script node
  8. script = pipeline.create(dai.node.Script)
  9. script.setScript("""
  10. import time
  11. ctrl = CameraControl()
  12. ctrl.setCaptureStill(True)
  13. while True:
  14. time.sleep(1)
  15. node.io['out'].send(ctrl)
  16. """)
  17. # XLinkOut
  18. xout = pipeline.create(dai.node.XLinkOut)
  19. xout.setStreamName('still')
  20. # Connections
  21. script.outputs['out'].link(cam.inputControl)
  22. cam.still.link(xout.input)
  23. # Connect to device with pipeline
  24. with dai.Device(pipeline) as device:
  25. while True:
  26. img = device.getOutputQueue("still").get()
  27. cv2.imshow('still', img.getCvFrame())
  28. if cv2.waitKey(1) == 27:
  29. break