我有一张图片,里面有几盏红灯。我需要在数组中保存其点的坐标:
这是我的代码:
red, green, blue = cv2.split(frame)
rbin, thresholdImg = cv2.threshold(red, 240, 255, cv2.THRESH_BINARY)
new = np.argwhere(thresholdImg == 255) #Get only RED pixels
if len(new) != 0:
xs = []
ys = []
n, m = new.shape
counter = 0
for (x,y) in new: #Extract red pixels positions
xs = np.append(xs,y)
ys = np.append(ys,x)
现在在数组XS和YS中,我分别具有所有“白色”像素的(x,y)坐标。我需要计算红灯的数量,如果它们是2,检查它们之间的距离是否正确。所以我试着这样做:
if ((np.any(new[counter+1] - new[counter] >= minSeamLength)) and (np.any(new[counter+1] - new[counter] <= maxSeamLength))):
...
这样我试着检查阵列中间隙的大小是否适合我。 但这不起作用。
任何帮助?