我用python编写了一个关于颜色检测的程序.但是'Erode'句子总是出现错误.这是我的计划的一部分.谢谢.
# Convert the image to a Numpy array since most cv2 functions
# require Numpy arrays.
frame = np.array(frame, dtype=np.uint8)
threshold = 0.05
#blur the image
frame=cv2.blur(frame, (5,5))
#Convert from BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
#split into 3
h, s, v= cv2.split(hsv)
#red color
s = cv2.threshold(h, 15, 1, cv2.THRESH_BINARY_INV)#1-15,x>15 y=0
h = cv2.threshold(h, 245, 1, cv2.THRESH_BINARY)#245-255 x>245 y=1
h = h + s
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3, 3))
h = cv2.erode(h, kernel)
v = cv2.sumElems(h)
Run Code Online (Sandbox Code Playgroud)