OpenCV Basic Modules
OpenCV is a powerful computer vision library that contains multiple modules, each focusing on different functions.
OpenCV is composed of multiple modules, each providing different functions.
The following are some of the most commonly used modules in OpenCV:
- cv2.core: Core module, containing basic image processing functions (such as representation and manipulation of image arrays).
- cv2.imgproc: Image processing module, providing various image operations such as filtering, image transformations, morphological operations, etc.
- cv2.highgui: Graphical user interface module, providing functions for displaying images and videos.
- cv2.video: Provides video processing functions, such as video capture, video stream processing, etc.
- cv2.features2d: Feature detection and matching module, including corner, edge, and keypoint detection, etc.
- cv2.ml: Machine learning module, providing various machine learning algorithms for image classification, regression, clustering, etc.
- **cv2.calib3d **: Camera calibration and 3D reconstruction module.
- **cv2.objdetect **: Object detection module.
- **cv2.dnn **: Deep learning module.
1. Core Module
Functions: Provides OpenCV's core functions, including basic data structures, matrix operations, drawing functions, etc.
Main Classes and Functions:
-
Mat: The basic data structure in OpenCV used to store images and matrices.
-
Scalar: Used to represent colors or pixel values.
-
Point、Size、Rect: Used to represent points, sizes, and rectangles.
-
Basic Drawing Functions:
cv.line()、cv.circle()、cv.rectangle()、cv.putText(), etc.
Application Scenarios:
-
Basic image operations (such as creation, copying, cropping).
-
Drawing geometric shapes and text.
2. Imgproc Module
Functions: Provides image processing functions, including image filtering, geometric transformations, color space conversion, etc.
Main Classes and Functions:
-
Image Filtering:
cv.blur()、cv.GaussianBlur()、cv.medianBlur(), etc. -
Geometric Transformations:
cv.resize()、cv.warpAffine()、cv.warpPerspective(), etc. -
Color Space Conversion:
cv.cvtColor()(Such as BGR to grayscale, BGR to HSV). -
Thresholding:
cv.threshold()、cv.adaptiveThreshold()。 -
Edge Detection:
cv.Canny()、cv.Sobel()、cv.Laplacian()。
Application Scenarios:
-
Image smoothing, sharpening, edge detection.
-
Image scaling, rotation, affine transformations.
-
Image binarization, color space conversion.
3. HighGUI Module
Functions: Provides high-level GUI and media I/O functions for image display and interaction.
Main Classes and Functions:
-
Image Display:
cv.imshow()、cv.waitKey()、cv.destroyAllWindows()。 -
Video Capture:
cv.VideoCapture()、cv.VideoWriter()。 -
Mouse and Keyboard Events:
cv.setMouseCallback()。
Application Scenarios:
-
Display images and videos.
-
Capture from a camera or video file.
-
Handle user interactions (such as mouse clicks, keyboard input).
4. Video Module
Functions: Provides video analysis functions, including motion detection, object tracking, etc.
Main Classes and Functions:
-
Background Subtraction:
cv.createBackgroundSubtractorMOG2()、cv.createBackgroundSubtractorKNN()。 -
Optical Flow Method:
cv.calcOpticalFlowPyrLK()。 -
Object Tracking:
cv.TrackerKCF_create()、cv.TrackerMOSSE_create()。
Application Scenarios:
-
Motion detection in videos.
-
Object tracking (such as pedestrian and vehicle tracking).
5. Calib3d Module
Functions: Provides camera calibration and 3D reconstruction functions.
Main Classes and Functions:
-
Camera Calibration:
cv.calibrateCamera()、cv.findChessboardCorners()。 -
3D Reconstruction:
cv.solvePnP()、cv.reprojectImageTo3D()。
Application Scenarios:
-
Camera calibration (used to remove lens distortion).
-
3D reconstruction (such as recovering 3D information from 2D images).
6. Features2d Module
Functions: Provides feature detection and description functions.
Main Classes and Functions:
-
Feature Detection:
cv.SIFT_create()、cv.ORB_create()、cv.SURF_create()。 -
Feature Matching:
cv.BFMatcher()、cv.FlannBasedMatcher()。 -
Keypoint Drawing:
cv.drawKeypoints()。
Application Scenarios:
-
Image feature extraction and matching.
-
Image stitching, object recognition.
7. Objdetect Module
Functions: Provides object detection functions.
Main Classes and Functions:
-
Haar Feature Classifier:
cv.CascadeClassifier()(Used for face detection). -
HOG Feature Classifier: Used for pedestrian detection.
Application Scenarios:
-
Face detection, pedestrian detection.
8. ML Module
Functions: Provides machine learning algorithms.
Main Classes and Functions:
-
Support Vector Machine (SVM):
cv.ml.SVM_create()。 -
K-Means Clustering (K-Means):
cv.kmeans()。 -
Neural Network (ANN):
cv.ml.ANN_MLP_create()。
Application Scenarios:
-
Image classification, cluster analysis.
9. DNN Module
Functions: Provides deep learning functions, supporting loading and running pre-trained deep learning models.
Main Classes and Functions:
-
Model Loading:
cv.dnn.readNetFromCaffe()、cv.dnn.readNetFromTensorflow()。 -
Forward Propagation:
net.forward()。
Application Scenarios:
-
Image classification, object detection, semantic segmentation.
10. Other Modules
-
Flann: Fast approximate nearest neighbor search.
-
Photo: Image restoration and denoising.
-
Stitching: Image stitching.
-
Shape: Shape matching and distance computation.