ON THIS PAGE

  • ImageManip
  • How to place it
  • Inputs and Outputs
  • Usage
  • Image formats supported
  • Operations order
  • Resizing and Aspect Ratio Handling
  • Limitations
  • Examples of functionality
  • Reference

ImageManip

ImageManip node can be used to crop, rotate, flip, resize, scale, convert (type) and transform ImgFrames.It's an updated version of ImageManip (v1) with a cleaner/clearer API and more features.

How to place it

Python
C++

Python

Python
1with dai.Pipeline() as pipeline:
2    manip = pipeline.create(dai.node.ImageManip)

Inputs and Outputs

Usage

Python
C++

Python

Python
1pipeline = dai.Pipeline()
2manip = pipeline.create(dai.node.ImageManip)
3
4manip.initialConfig.setResize(300, 300, dai.ImageManipConfig.ResizeMode.STRETCH)
5manip.initialConfig.setFrameType(dai.ImgFrame.Type.BGR888p)

Image formats supported

ImageManip node supports the following image formats (more info in PR here):
  • Input formats supported: RGB/BGR, planar/interleaved, YUV/NV12, RAW8 and GRAY8
  • Convert format to any other format mentioned above
  • RAW16 (uint16, depth output) supported, but without color conversion capability
Note that planar formats are faster to process, so interleaved images should be avoided (eg. NV12 input).

Operations order

Operations order is important, as operations are applied in the order they are set, eg. example below (from ImageManip Multiple operations) will first crop the image and then flip it vertically:
Python
1manip = pipeline.create(dai.node.ImageManip)
2manip.initialConfig.addCrop(50, 100, 500, 500)
3manip.initialConfig.addFlipVertical()

Resizing and Aspect Ratio Handling

When your neural network expects a different aspect ratio than the camera sensor (e.g., NN expects 1:1 but the sensor outputs 4:3), you have three main options: crop the image, stretch it, or letterbox it.To resize images for neural network input or other processing with ImageManip, use:
Python
1manip = pipeline.create(dai.node.ImageManip)
2manip.initialConfig.setOutputSize(width, height, dai.ImageManipConfig.ResizeMode)
Available Resize Modes
ModePreserves ARFull FOVProsCons
CENTER_CROPYesNoBest for NN accuracy; preserves ARCrops image; reduces field of view
LETTERBOXYesYesPreserves AR and full FOVAdds padding; smaller image area for NN; may reduce NN accuracy
STRETCHNoYesPreserves full field of viewAspect ratio not preserved; may reduce NN accuracy
These modes are useful for handling cases where your NN input shape differs from your sensor's native aspect ratio. See more in Resolution Techniques for NNs.

Limitations

Besides limitations mentioned above (unsupported frame formats), there are other limitations:
  • Due to HW warp constraint, rotating/warping can be done only on frames whose width values are multiples of 16
  • Maximum output width of a frame is 4056 pixels

Examples of functionality

Reference

class

dai::node::ImageManip

#include ImageManip.hpp
variable
std::shared_ptr< ImageManipConfig > initialConfig
Initial config to use when manipulating frames
variable
Input inputConfig
Input ImageManipConfig message with ability to modify parameters in runtime
variable
Input inputImage
Input image to be modified
variable
Output out
Outputs ImgFrame message that carries modified image.
function
ImageManip()
function
ImageManip(std::unique_ptr< Properties > props)
inline function
std::shared_ptr< ImageManip > build()
function
void setNumFramesPool(int numFramesPool)
Specify number of frames in pool.
Parameters
  • numFramesPool: How many frames should the pool have
function
void setMaxOutputFrameSize(int maxFrameSize)
Specify maximum size of output image.
Parameters
  • maxFrameSize: Maximum frame size in bytes
function
ImageManip & setRunOnHost(bool runOnHost)
Specify whether to run on host or device
Parameters
  • runOnHost: Run node on host
function
ImageManip & setBackend(Backend backend)
Set CPU as backend preference
Parameters
  • backend: Backend preference
function
ImageManip & setPerformanceMode(PerformanceMode performanceMode)
Set performance mode
Parameters
  • performanceMode: Performance mode
function
bool runOnHost()
Check if the node is set to run on host
function
void run()
inline function
DeviceNodeCRTP()
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Need assistance?

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