Supported Models
The following classification models are commonly used:- ResNet - Deep residual networks with skip connections
- MobileNet - Lightweight models optimized for mobile devices
- GoogLeNet - Inception architecture from Google
- SqueezeNet - Compact model with high accuracy
- VGG - Very deep convolutional networks
Python Implementation
Prepare Input Image
The
blobFromImage function performs:- Mean subtraction
- Scaling
- Optional channel swapping (BGR to RGB)
- Resizing to target dimensions
C++ Implementation
- Basic Usage
- Video Processing
Model Download and Configuration
GoogLeNet (Caffe)
SqueezeNet (Caffe)
Preprocessing Parameters
Different models require different preprocessing parameters:
| Model | Input Size | Mean | Scale | RGB Order |
|---|---|---|---|---|
| GoogLeNet | 224x224 | [104, 117, 123] | 1.0 | BGR |
| SqueezeNet | 227x227 | [0, 0, 0] | 1.0 | BGR |
| ResNet | 224x224 | [103.94, 116.78, 123.68] | 1.0 | BGR |
| MobileNet | 224x224 | [127.5, 127.5, 127.5] | 0.007843 | RGB |
Backend and Target Options
Available Backends
Available Targets
Complete Example
Here’s a complete classification example that processes video frames:Source Code
The complete source code for classification examples can be found in the OpenCV repository:- Python:
samples/dnn/classification.py - C++:
samples/dnn/classification.cpp
