Software Stack
DepthAI

ON THIS PAGE

  • Undistort camera stream
  • Demo
  • Pipeline
  • Source code

Undistort camera stream

Supported on:RVC2RVC4
This example shows how to undistort a wide FOV camera stream using the Camera node. Undistortion is not automatic; it is enabled per output with requestOutput(..., enableUndistortion=True) (or requestFullResolutionOutput). Any requested output can be undistorted this way.Notes:
  • Undistortion does not change the stored camera intrinsics, and there is no exposed "alpha" or equivalent to tune the undistortion crop.
  • Undistortion does change the effective FOV; depending on your requested output size and resize mode, you may see less FOV after undistortion.

Demo

This example requires the DepthAI v3 API, see installation instructions.

Pipeline

Source code

Python

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6# Create pipeline
7with dai.Pipeline() as pipeline:
8    # Define source and output
9    cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
10    croppedQueue = cam.requestOutput((300,300), resizeMode=dai.ImgResizeMode.CROP, enableUndistortion=True).createOutputQueue()
11    stretchedQueue = cam.requestOutput((300,300), resizeMode=dai.ImgResizeMode.STRETCH, enableUndistortion=True).createOutputQueue()
12    letterBoxedQueue = cam.requestOutput((300,300), resizeMode=dai.ImgResizeMode.LETTERBOX, enableUndistortion=True).createOutputQueue()
13
14    # Connect to device and start pipeline
15    pipeline.start()
16    while pipeline.isRunning():
17        croppedIn = croppedQueue.get()
18        assert isinstance(croppedIn, dai.ImgFrame)
19        cv2.imshow("cropped undistorted", croppedIn.getCvFrame())
20
21        stretchedIn = stretchedQueue.get()
22        assert isinstance(stretchedIn, dai.ImgFrame)
23        cv2.imshow("stretched undistorted", stretchedIn.getCvFrame())
24
25        letterBoxedIn = letterBoxedQueue.get()
26        assert isinstance(letterBoxedIn, dai.ImgFrame)
27        cv2.imshow("letterboxed undistorted", letterBoxedIn.getCvFrame())
28
29        if cv2.waitKey(1) == ord("q"):
30            break

Need assistance?

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