DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Mono Full Resolution Saver
  • Similar samples:
  • Demo
  • Setup
  • Source code

Mono Full Resolution Saver

This example does its best to save 1280x720 .png files as fast at it can from the Mono sensor. It serves as an example of recording mono pictures to disk.Be careful, this example saves pictures to your host storage. So if you leave it running, you could fill up your storage on your host.

Similar samples:

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
C++
Python
GitHub
1#!/usr/bin/env python3
2
3from pathlib import Path
4import cv2
5import depthai as dai
6import time
7
8# Create pipeline
9pipeline = dai.Pipeline()
10
11# Define source and output
12monoRight = pipeline.create(dai.node.MonoCamera)
13xoutRight = pipeline.create(dai.node.XLinkOut)
14
15xoutRight.setStreamName("right")
16
17# Properties
18monoRight.setCamera("right")
19monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
20
21# Linking
22monoRight.out.link(xoutRight.input)
23
24# Connect to device and start pipeline
25with dai.Device(pipeline) as device:
26
27    # Output queue will be used to get the grayscale frames from the output defined above
28    qRight = device.getOutputQueue(name="right", maxSize=4, blocking=False)
29
30    dirName = "mono_data"
31    Path(dirName).mkdir(parents=True, exist_ok=True)
32
33    while True:
34        inRight = qRight.get()  # Blocking call, will wait until a new data has arrived
35        # Data is originally represented as a flat 1D array, it needs to be converted into HxW form
36        # Frame is transformed and ready to be shown
37        cv2.imshow("right", inRight.getCvFrame())
38
39        # After showing the frame, it's being stored inside a target directory as a PNG image
40        cv2.imwrite(f"{dirName}/{int(time.time() * 1000)}.png", inRight.getFrame())
41
42        if cv2.waitKey(1) == ord('q'):
43            break

Need assistance?

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