DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • RGB scene
  • Demo
  • Setup
  • Source code
  • Pipeline

RGB scene

This example shows how to select ColorCamera scene and effect.
  • s will switch between available scenes
  • e will switch between available effects (currently not available)

Demo

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python

Python

Python
GitHub
1import cv2
2import depthai as dai
3from itertools import cycle
4
5scenes = cycle([item for name, item in vars(dai.RawCameraControl.SceneMode).items() if name != "UNSUPPORTED" and name.isupper()])
6effects = cycle([item for name, item in vars(dai.RawCameraControl.EffectMode).items() if name.isupper()])
7curr_scene = "OFF"
8curr_effect = "OFF"
9
10# Create pipeline
11pipeline = dai.Pipeline()
12
13camRgb = pipeline.create(dai.node.ColorCamera)
14camRgb.setIspScale(1,3)
15
16xoutRgb = pipeline.create(dai.node.XLinkOut)
17xoutRgb.setStreamName("video")
18camRgb.video.link(xoutRgb.input)
19
20camControlIn = pipeline.create(dai.node.XLinkIn)
21camControlIn.setStreamName("camControl")
22camControlIn.out.link(camRgb.inputControl)
23
24# Connect to device and start pipeline
25with dai.Device(pipeline) as device:
26    videoQ = device.getOutputQueue(name="video", maxSize=4, blocking=False)
27    ctrlQ = device.getInputQueue(name="camControl")
28
29    def putText(frame, text, coords):
30        cv2.putText(frame, text, coords, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 4)
31        cv2.putText(frame, text, coords, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
32
33    while True:
34        videoIn = videoQ.tryGet()
35        if videoIn is not None:
36            frame = videoIn.getCvFrame()
37            putText(frame, f"[E] Effect: {curr_effect}", (10, 20))
38            putText(frame, f"[S] Scene: {curr_scene}", (10, 40))
39            cv2.imshow("video", frame)
40
41        key = cv2.waitKey(1)
42        if key == ord('e') or key == ord('E'):
43            effect = next(effects)
44            print("Switching colorCamera effect:", str(effect))
45            curr_effect = str(effect).lstrip("EffectMode.")
46            cfg = dai.CameraControl()
47            cfg.setEffectMode(effect)
48            ctrlQ.send(cfg)
49        # Scene currently doesn't work
50        elif key == ord('s') or key == ord('S'):
51            scene = next(scenes)
52            print("Currently doesn't work! Switching colorCamera Scene:", str(scene))
53            curr_scene = str(scene).lstrip("SceneMode.")
54            cfg = dai.CameraControl()
55            cfg.setSceneMode(scene)
56            ctrlQ.send(cfg)
57        elif key == ord('q'):
58            break

Pipeline

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.