cv2.cvtColor(src, cv2.COLOR_BGR2RGB): Converts image from BGR to RGB format for correct color display in Matplotlib.
plt.imshow(rgb_image): Displays the RGB image using Matplotlib.
plt.axis('off'): Hides the axis for a cleaner view.
Common Conversion Codes
Let’s see some of the most commonly used OpenCV color conversion codes:
cv2.COLOR_BGR2GRAY BGR: Grayscale
cv2.COLOR_BGR2RGB BGR: RGB
cv2.COLOR_BGR2HSV BGR: HSV
cv2.COLOR_BGR2LAB BGR: LAB color space
cv2.COLOR_BGR2YCrCb BGR: YCrCb (used in compression & skin detection)
Real-World Applications
Different color spaces are preferred for specific computer vision tasks because they highlight certain image features better. Let’s see some real-world applications of these conversions:
Grayscale: Face detection, OCR (text recognition)
HSV: Object tracking (e.g., detecting a colored ball)