Color Spaces
Color spaces are a way to represent the color channels present in the image that gives the image that particular hue. There are several different color spaces and each has its own significance. Some of the popular color spaces are RGB (Red, Green, Blue), CMYK (Cyan, Magenta, Yellow, Black), HSV (Hue, Saturation, Value), etc.
cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV.
Example: Python OpenCV Color Spaces
Python3
# Python program to explain cv2.cvtColor() method # importing cv2 import cv2 # path path = 'geeks.png' # Reading an image in default mode src = cv2.imread(path) # Window name in which image is displayed window_name = 'w3wiki' # Using cv2.cvtColor() method # Using cv2.COLOR_BGR2GRAY color space # conversion code image = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY ) # Displaying the image cv2.imshow(window_name, image) cv2.waitKey( 0 ) cv2.destroyAllWindows() |
Output:
Getting Started with Python OpenCV
Computer Vision is one of the techniques from which we can understand images and videos and can extract information from them. It is a subset of artificial intelligence that collects information from digital images or videos.
Python OpenCV is the most popular computer vision library. By using it, one can process images and videos to identify objects, faces, or even handwriting of a human. When it is integrated with various libraries, such as NumPy, python is capable of processing the OpenCV array structure for analysis.
In this article, we will discuss Python OpenCV in detail along with some common operations like resizing, cropping, reading, saving images, etc with the help of good examples.