ImageManip all operations
Showcases all available ImageManip operations:- Resize (
conf.setOutputSize()
) - Crop (
conf.addCrop()
) - Flip vertical (
conf.addFlipVertical()
) - Flip horizontal (
conf.addFlipHorizontal()
) - Scale (
conf.addScale()
) - Rotate (
conf.addRotateDeg()
) - Transform (
conf.addTransformAffine()
andconf.addTransformPerspective()
)
Demo

Setup
This example requires the DepthAI v3 API, see installation instructions.Pipeline
Source code
Python
C++
Python
PythonGitHub
1import depthai as dai
2import cv2
3
4pipeline = dai.Pipeline()
5
6manip_input = pipeline.create(dai.node.ImageManip)
7manip_input.initialConfig.setFrameType(dai.ImgFrame.Type.BGR888p)
8inputQueue = manip_input.inputImage.createInputQueue()
9
10manip_ops = [
11 # Resize operations. If aspect ratio isn't the same, the image will be stretched/cropped/letterboxed (depending on resize mode)
12 # Docs here: https://docs.luxonis.com/software/depthai/resolution-techniques/
13 ('resize_stretch', lambda conf: conf.setOutputSize(256, 200, dai.ImageManipConfig.ResizeMode.STRETCH)),
14 ('resize_letterbox', lambda conf: conf.setOutputSize(256, 200, dai.ImageManipConfig.ResizeMode.LETTERBOX)),
15 ('resize_center_crop', lambda conf: conf.setOutputSize(256, 200, dai.ImageManipConfig.ResizeMode.CENTER_CROP)),
16 # Crop the image topLeft (10,40) to bottomRight (310,110)
17 ('crop', lambda conf: conf.addCrop(x=50, y=50, w=150, h=200)),
18 # Flip the frame vertically/horizontally
19 ('flip_vertical', lambda conf: conf.addFlipVertical()),
20 ('flip_horizontal', lambda conf: conf.addFlipHorizontal()),
21 # Scale the image by 0.7x in x and 0.5x in y
22 ('scale', lambda conf: conf.addScale(0.7, 0.5)),
23 # Rotate. If center isn't specified, it will rotate around center (0.5, 0.5)
24 ('rotate_90_deg', lambda conf: conf.addRotateDeg(90)),
25 ('rotate_90_deg_center', lambda conf: conf.addRotateDeg(90, center=dai.Point2f(0.2, 0.3)).setOutputCenter(False)),
26 ('transform_affine', lambda conf: conf.addTransformAffine( # Shearing
27 [1, 0.5,
28 0.2, 1])),
29 ('transform_perspective', lambda conf: conf.addTransformPerspective(
30 [1.0, 0.2, 0.0, # First row
31 0.1, 1.0, 0.0, # Second row
32 0.001, 0.002, 1.0])), # Third row
33 ('frame_type', lambda conf: conf.setFrameType(dai.ImgFrame.Type.RAW8)), # to Grayscale
34]
35
36# Dynamically create ImageManip nodes, apply configurations, and set up queues
37queues = {}
38for name, config in manip_ops:
39 print(name, config)
40 manip = pipeline.create(dai.node.ImageManip)
41 config(manip.initialConfig)
42 manip_input.out.link(manip.inputImage)
43 queues[name] = manip.out.createOutputQueue(maxSize=4, blocking=False)
44
45
46imgFrame = dai.ImgFrame()
47
48input_frame = cv2.imread('../models/lenna.png') # 512x512
49# Send 256x256 image to the device
50imgFrame.setCvFrame(cv2.pyrDown(input_frame), dai.ImgFrame.Type.BGR888i)
51inputQueue.send(imgFrame)
52
53cv2.imshow('input_image', input_frame)
54
55
56pipeline.start()
57
58for name, queue in queues.items():
59 inFrame = queue.get()
60 cv2.imshow(name, inFrame.getCvFrame())
61
62key = cv2.waitKey(0)
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.