文本更暗,饱和度更低。正如@J.D.所建议的那样。 HSV 色彩空间很好。但是他的范围是错误的。
在 OpenCV 中,H 的范围在 [0, 180],而 S/V 的范围在 [0, 255]
这是我去年做的一张色彩图,我觉得很有帮助。
(1) 使用cv2.inRange
(2) 只需设置V(HSV) 频道的阈值:
th, threshed = cv2.threshold(v, 150, 255, cv2.THRESH_BINARY_INV)
(3) 只需设置S(HSV) 频道的阈值:
th, threshed2 = cv2.threshold(s, 30, 255, cv2.THRESH_BINARY_INV)
结果:
演示代码:
# 2018/12/30 22:21
# 2018/12/30 23:25
import cv2
img = cv2.imread("test.png")
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(hsv)
mask = cv2.inRange(hsv, (0,0,0), (180, 50, 130))
dst1 = cv2.bitwise_and(img, img, mask=mask)
th, threshed = cv2.threshold(v, 150, 255, cv2.THRESH_BINARY_INV)
dst2 = cv2.bitwise_and(img, img, mask=threshed)
th, threshed2 = cv2.threshold(s, 30, 255, cv2.THRESH_BINARY_INV)
dst3 = cv2.bitwise_and(img, img, mask=threshed2)
cv2.imwrite("dst1.png", dst1)
cv2.imwrite("dst2.png", dst2)
cv2.imwrite("dst3.png", dst3)
How to detect colored patches in an image using OpenCV?
How to define a threshold value to detect only green colour objects in an image :Opencv