Core module
This section details some of the key behind-the-scene concepts, that make OpenCV implementation possible.
Mat object
- Output image allocation for OpenCV functions is automatic (unless specified otherwise).
- You do not need to think about memory management with OpenCV's C++ interface.
- The assignment operator and the copy constructor only copies the header.
- The underlying matrix of an image may be copied using the cv::Mat::clone() (opens in a new tab) and cv::Mat::copyTo() (opens in a new tab) functions.
Color systems
- RGB is the most common as our eyes use something similar, however keep in mind that OpenCV standard display system composes colors using the BGR color space (red and blue channels are swapped places).
- The HSV and HLS decompose colors into their hue, saturation and value/luminance components, which is a more natural way for us to describe colors. You might, for example, dismiss the last component, making your algorithm less sensible to the light conditions of the input image.
- YCrCb is used by the popular JPEG image format.
- CIE Lab* is a perceptually uniform color space, which comes in handy if you need to measure the distance of a given color to another color.
Mat mask operation
-
Fast method
dst1 = cv.filter2D(src, -1, kernel)
I/O
-
Choose channel upon reading
img = cv.imread(filename, cv.IMREAD_GRAYSCALE)
Blending 2 images
- linear blend operator:
- By varying α from 0→1 this operator can be used to perform a temporal cross-dissolve between two images or videos
dst = cv.addWeighted(src1, alpha, src2, beta, 0.0)
Brightness and contrast adjustments
- Increasing β (bias) increases the brightness, increasing α increases saturation (gain)
- Gamma transformation:
- When γ<1, the original dark regions will be brighter and the histogram will be shifted to the right whereas it will be the opposite with γ>1.
Discrete Fourier Transform
- Displaying this is possible either via a real image and a complex image or via a magnitude and a phase image.
- However, throughout the image processing algorithms only the magnitude image is interesting as this contains all the information we need about the images geometric structure