What Are Recommended Color Spaces For Detecting Orange Color In Open Cv?
Solution 1:
HSV is a good color space for color detection. This is a hsv colormap for reference:
The x-axis represents Hue in [0,180), the y-axis1 represents Saturation in [0,255], the y-axis2 represents S = 255, while keep V = 255.
To find a color, usually just look up for the range of H and S, and set v in range(20, 255).
For example:
- detect orange
Details from my another answer: Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)
To find the orange color, we look up for the map, and find the best range: H :[10, 25], S: [100, 255], and V: [20, 255]. So the mask is cv2.inRange(hsv,(10, 100, 20), (25, 255, 255) )
#!/usr/bin/python3
# 2018.01.2120:46:41 CST
import cv2
img = cv2.imread("test.jpg")
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv,(10, 100, 20), (25, 255, 255) )
cv2.imshow("orange", mask);cv2.waitKey();cv2.destroyAllWindows()
The result:
- detect green / yellow/ blue
How to define a threshold value to detect only green colour objects in an image :Opencv
- detect two different colors
How to detect two different colors using `cv2.inRange` in Python-OpenCV?
Solution 2:
Randomly choosing a color system might not be the best approach.
A more systematic approach could be by looking at a color histogram such as below, which shows all image pixels in the RGB cube.
Then you populate this histogram with orange color samples taken from various images, in such a way to cover all the "oranges" you are thinking of.
This will delimit a region in RGB space and the shape of the region will tell you the most suitable color system, knowing how the other color systems map to to the cube. For example, HLS can be represented as a bicone or bipyramid with it axs along the main diagonal of the cube.
Admittedly, this is a difficult task.
Post a Comment for "What Are Recommended Color Spaces For Detecting Orange Color In Open Cv?"