Overview
Color spaces represent colors in different ways for various purposes:- BGR/RGB: Standard color representation for displays
- HSV: Hue, Saturation, Value - intuitive for color filtering
- Grayscale: Single channel intensity values
- LAB: Perceptually uniform color space
- YCrCb: Luminance and chrominance separation
BGR to RGB Conversion
OpenCV reads images in BGR format by default, but many libraries expect RGB.- Python
- C++
OpenCV uses BGR format by default for historical reasons related to early camera standards. Always convert to RGB when interfacing with other libraries like Matplotlib, PIL, or TensorFlow.
BGR to Grayscale Conversion
Convert color images to grayscale for simplified processing.- Python
- C++
BGR to HSV Conversion
HSV (Hue, Saturation, Value) is ideal for color-based object detection and filtering.- Python
- C++
Color Range Detection with HSV
Detect specific colors by defining HSV ranges.- Python
- C++
Common HSV Color Ranges
In OpenCV, Hue values range from 0-179 (not 0-359) to fit in a single byte. Adjust your ranges accordingly.
Thresholding
Thresholding converts grayscale images to binary images by applying a threshold value.Basic Thresholding
- Python
- C++
Adaptive Thresholding
Adaptive thresholding calculates different thresholds for different regions, useful for varying lighting conditions.- Python
- C++
Other Color Space Conversions
- Python
- C++
