Cookie-cutter template app
1
Install
Get up and running in under 5 minutes:This will download the template / cookie-cutter app to your current directory.
Command Line
1# Install core packages
2pip install depthai --force-reinstall
3# Clone the template app
4git clone https://github.com/luxonis/oak-template.git
5# Change directory to the template app
6cd oak-template
7# Install requirements
8pip install -r requirements.txtText
1template-app/
2├── main.py
3├── oakapp.toml
4├── requirements.txt
5├── media/ # Optional media files
6└── utils/ # Optional helper functions2
main.py
This is where your main logic resides. The downloaded script will use "Camera + NN + Hub" as a default pipeline. Feel free to swap it with any of the other examples below if you don't need the NN or Hub functionality.
Camera + NN + HUB (default)
Camera stream
Depth
Python
1import os
2from pathlib import Path
3
4import depthai as dai
5from utils.snaps_producer import SnapsProducer
6from depthai_nodes.node import ParsingNeuralNetwork
7
8
9visualizer = dai.RemoteConnection(httpPort=8082)
10device = dai.Device()
11
12with dai.Pipeline(device) as pipeline:
13 print("Creating pipeline...")
14 platform = device.getPlatform()
15 model_description = dai.NNModelDescription.fromYamlFile(
16 f"yolov6_nano_r2_coco.{platform.name}.yaml"
17 )
18 nn_archive = dai.NNArchive(dai.getModelFromZoo(modelDescription=model_description))
19
20 input_node = pipeline.create(dai.node.Camera).build()
21
22 nn_with_parser = pipeline.create(ParsingNeuralNetwork).build(input_node, nn_archive)
23
24 visualizer.addTopic("Video", nn_with_parser.passthrough, "images")
25 visualizer.addTopic("Visualizations", nn_with_parser.out, "images")
26
27 snaps_producer = pipeline.create(SnapsProducer).build(
28 nn_with_parser.passthrough,
29 nn_with_parser.out,
30 label_map=nn_archive.getConfigV1().model.heads[0].metadata.classes,
31 )
32
33 print("Pipeline created.")
34
35 pipeline.start()
36 visualizer.registerPipeline(pipeline)
37
38 while pipeline.isRunning():
39 key = visualizer.waitKey(1)
40 if key == ord("q"):
41 print("Got q key from the remote connection!")
42 breakDepthAI Examples
If you wish to use a different pipeline, you can find a list of available nodes and their examples
3
oakapp.toml
This is where you define the build process for your container. For the purposes of this example, it can remain unchanged. You can find more information here.
Toml
1identifier = "custom.oakapp"
2app_version = "1.0.0"
3
4prepare_container = [
5 { type = "RUN", command = "apt-get update" },
6 { type = "RUN", command = "apt-get install -y python3 python3-pip wget git" },
7]
8
9prepare_build_container = []
10
11build_steps = ["pip3 install -r /app/requirements.txt --break-system-packages"]
12
13depthai_models = { yaml_path = "./depthai_models" }
14
15entrypoint = ["bash", "-c", "python3 /app/main.py"]4
Deploy
Now that you have your main.py and oakapp.toml, you can deploy your application to the OAK device. You have two options:This will containerize your application and deploy it to the OAK device. Results can be viewed with the visualizer webapp at Results can be viewed with the visualizer webapp at
- Standalone: This is the simplest option. Just run the following command in the same directory as your main.py and oakapp.toml files:
Command Line
1oakctl app run .http://<device-ip>:8082.- Peripheral: This option is for when you want to run your application from your host machine. No containerization is needed in this mode, but you need a steady connection to the device. To run your application in peripheral mode, run the following command:
Command Line
1python3 main.pyhttp://<host-ip>:8082.