我将检测图像中的绿色,完整代码如下所示
import numpy as np
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help = "path to the image")
args = vars(ap.parse_args())
# load the image
image = cv2.imread(args["image"])
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# define the list of boundaries
boundaries = [
( [ 146, 0, 0 ],[146, 100, 100 ]) # hsv
]
for (lower, upper) in boundaries:
lower = np.array(lower, dtype = "uint8")
upper = np.array(upper, dtype = "uint8")
mask = cv2.inRange(image, lower, upper)
output = cv2.bitwise_and(image, image, mask = mask)
cv2.imshow("images", np.hstack([image, output]))
cv2.waitKey(0)
这是图片
所以hsv [146,40,40] =深绿色
hsv [146, 80, 80] = light green
http://www.rapidtables.com/web/color/RGB_Color.htm可以验证颜色
但为什么程序不输出绿色掩码?