Overview
OpenCV DNN provides utility functions for preparing inputs, processing outputs, and managing inference workflows.Blob Creation
blobFromImage
Convert single image to 4D blob:image: Input image (any size, any channels)scalefactor: Multiplier for pixel valuessize: Target spatial dimensionsmean: Values to subtract from channelsswapRB: Swap red and blue channels (BGR to RGB)crop: Crop image after resizeddepth: Output depth (typically CV_32F)
blobFromImages
Convert multiple images to single blob (batching):imagesFromBlob
Convert blob back to images:Blob Utilities
getPlane
Extract single plane from blob:m: 4D blob [N, C, H, W]n: Batch indexcn: Channel index
getMatFromNet
Get layer activations:NMS (Non-Maximum Suppression)
NMSBoxes
Filter overlapping bounding boxes:bboxes: Bounding boxesscores: Confidence scoresscore_threshold: Minimum score to keepnms_threshold: IoU threshold (typically 0.4-0.5)indices: Output indices of kept boxeseta: Adaptive NMS parametertop_k: Keep top K boxes (0 = all)
NMSBoxesBatched
NMS for batched detections:Softmax
softmax
Apply softmax activation:Backend Queries
getAvailableBackends
Query available backends:getAvailableTargets
Query targets for backend:Model Diagnostics
enableModelDiagnostics
Enable verbose model loading:Complete Examples
Image Classification
Object Detection (YOLO)
Best Practices
Normalize Inputs
Match preprocessing used during training
Batch Processing
Use blobFromImages for multiple images
Apply NMS
Remove overlapping detections
Check Backend Support
Query available backends for optimization
See Also
- Net Class - Network operations
- DNN Module - Module overview
- DNN Layers - Layer types
