Changing the Colorspace of Images
We can change the colorspace of images using OpenCV. Let’s discuss different ways to visualize images where we will represent images in different formats like grayscale, RGB scale, Hot_map, edge map, Spectral map, etc.
cv2.cvtColor(image, conversion_scale) |
Some of the commonly used ways in which color coding of the images are changed is as shown below:
|
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) lower_blue = np.array([110,50,50]) upper_blue = np.array([130,255,255]) cv2.inRange(hsv, lower_blue, upper_blue) |
OpenCV provides functions for the in live-stream video content. A video is composed of infinite frames at different time instants. |
green = np.uint8([[[0, 255, 0]]]) hsv_green = cv2.cvtColor(green, cv2.COLOR_BGR2HSV) | OpenCV lets you find out the HSV color code from the RGB color code. |
Convert to Gray
Grayscale image contains only a single channel.
cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Convert to HSV
Hue(H) represents the dominant wavelength. Saturation(S) represents shades of color. Value(V) represents Intensity.
cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
Convert to LAB color
L represents Lightness. A represents color components ranging from Green to Magenta. B represents color components ranging from Blue to Yellow.
cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
Convert to YCrCb Color
Y represents Luminance or Luma component, and Cb and Cr are Chroma components. Cb represents the blue difference (difference between the blue component and Luma Component). Cr represents the red difference (difference between the red component and Luma Component).
cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
Track Blue (color) Object
OpenCV provides functions for the detection of a specific color in live-stream video content. A video is composed of infinite frames at different time instants.
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
cv2.inRange(hsv, lower_blue, upper_blue)
Find HSV Color
OpenCV lets you find out the HSV color code from the RGB color code.
green = np.uint8([[[0, 255, 0]]])
hsv_green = cv2.cvtColor(green, cv2.COLOR_BGR2HSV)
Python OpenCV Cheat Sheet
The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It’s designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you’re an experienced developer needing a quick reminder or a newcomer excited to start, this cheat sheet has got you covered.
In this article, we’ve gathered all the vital OpenCV concepts and explained them in simple terms. We’ve also provided practical examples to make things even clearer. You’ll learn everything from how to handle images to using advanced filters, spotting objects, and even exploring facial recognition. It’s all here to help you on your journey of discovering the amazing world of computer vision.
Table of Content
- Python OpenCV Cheat Sheet 2023
- Core Operations
- Drawing Shapes and Text on Images
- Arithmetic Operations on Images
- Morphological Operations on Images
- Geometric Transformations on Image
- Image Thresholding
- Edge/Line Detection (Features)
- Image Pyramids
- Changing the Colorspace of Images
- Smoothing Images
- Working With Videos
- Camera Calibration and 3D Reconstruction