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
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 withImageManip
, use:Python
1manip = pipeline.create(dai.node.ImageManip)
2manip.initialConfig.setOutputSize(width, height, dai.ImageManipConfig.ResizeMode)
Mode | Preserves AR | Full FOV | Pros | Cons |
---|---|---|---|---|
CENTER_CROP | Yes | No | Best for NN accuracy; preserves AR | Crops image; reduces field of view |
LETTERBOX | Yes | Yes | Preserves AR and full FOV | Adds padding; smaller image area for NN; may reduce NN accuracy |
STRETCH | No | Yes | Preserves full field of view | Aspect ratio not preserved; may reduce NN accuracy |
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
- ImageManip Multiple operations - Uses multiple operations one after another (order matters)
- ImageManip All operations - Showcases all available operations
- ImageManip resize - Resizes the input image to 300x300 frame
Reference
class
dai::node::ImageManip
variable
std::shared_ptr< ImageManipConfig > initialConfig
Initial config to use when manipulating frames
variable
Input inputConfig
variable
Input inputImage
Input image to be modified
variable
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)
enum
ImageManipProperties::Backend Backend
enum
ImageManipProperties::PerformanceMode PerformanceMode
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.