【发布时间】:2019-11-28 20:08:20
【问题描述】:
我一直在尝试解决这个问题并陷入困境。我将不胜感激。
ret,thresh = cv2.threshold(res_gray,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# something to notify us of black or white (after threshold application)
flag = 255
#for loop to find white pixel (scanning columns first - after 100)
for j in range (100, thresh.shape[1]):
if flag == 0: # check for 'found'
break
for i in range (0, thresh.shape[0]):
if thresh[i,j] == 255:
# once black is found, log starting coordinates
starting_Y, starting_X = j, i
# now we are looking for white
flag = 0
break
lower_blue = np.array([70,50,50])
upper_blue = np.array([130,255,255])
上面是我编写的用于在二进制图像中查找白色像素的代码示例。它返回j,i,它们是扫描列(然后是行)(从第 100 列开始)找到的第一个白色像素的坐标。我想在 HSV 图像中找到特定范围内的单元格。该范围是lower_blue 和upper_blue。
【问题讨论】:
-
使用
cv2.inRange -
另外,使用
numpy.argwhere查找白色像素的坐标,即np.argwhere(thresh == 255)。
标签: python numpy opencv image-processing