In this tutorial, I will show you the Basic Color Spaces OpenCV RaspberryPi Step By step Complet Process.
There are many other color spaces that we can use. The Hue-Saturation-Value (HSV) color space is more similar to how humans think and conceive of color. Then there is the L*a*b* color space, which is more tuned to how humans perceive color.
OpenCV gives support for many, several different color spaces. And knowing how color is seen by humans and represented by computers occupies an entire library of literature itself.
≡ Color Spaces OpenCV RaspberryPi Code:
This theory is better explained through some code for writing code with raspberry pi, Fast open your command terminal on your Raspberry Pi then write this Commend:
nano
you can see like this interface

Now we can start writing This code on GNU nano:
import numpy as np import argparse import cv2 ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required = True, help = "Path to the image") args = vars(ap.parse_args()) image = cv2.imread(args["image"]) cv2.imshow("Original", image) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow("Gray", gray) hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) cv2.imshow("HSV", hsv) lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB) cv2.imshow("L*a*b*", lab) cv2.waitKey(0)
Now save this file named colorspaces.py and exit using ctrl + x, y, enter. we simply open up a raspberry terminal window and execute the following command:
python colorspaces.py --image bay.jpg
see like this interface

≡ Analysis
import numpy as np import argparse import cv2
We’ll apply argparse to handle parsing our command-line arguments. Then, cv2 is imported – cv2 our OpenCV library and contains our image processing functions.
# Construct the argument parser and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required = True, help = "Path to the image") args = vars(ap.parse_args()) # Load the image and show it image = cv2.imread(args["image"]) cv2.imshow("Original", image)
In this section we have the necessary packages imported, we construct our argument parser and load our image. We only require one argument: the path to the image we are going to work. We then load our image off disk and present it.
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
In this line, we convert our image from the RGB color space to grayscale by specifying the cv2.COLOR_BGR2GRAY flag.
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
Now Converting our image to the HSV color space is made by specifying the cv2.COLOR_BGR2HSV flag.
lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
we convert to the L*a*b* color space by using the cv2.COLOR_BGR2LAB flag.
More Computer vision tutorial on raspberry pi click COMPUTER VISION BEGINNER
Visit My Blog
151 total views, 1 views today