Undistort camera stream
This example shows how you can use Camera node to undistort wide FOV camera stream. Camera node will automatically undistortstill, video and preview streams, while isp stream will be left as is.Demo
Pipeline
Source code
Python
Python
PythonGitHub
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 breakNeed assistance?
Head over to Discussion Forum for technical support or any other questions you might have.