使用cv2.imread:“ 返回NULL且未设置错误”,好像无法打开图片或获取数据

问题描述 投票:0回答:1

这是我的代码中出现问题的部分。应该计算图片中绿色像素的数量:

img = Image.open('path.tif')

BLACK_MIN = np.array([0, 20, 20], np.uint8)

BLACK_MAX = np.array([120, 255, 255], np.uint8)

imgg = cv2.imread(img, 1)

dst = cv2.inRange(imgg, BLACK_MIN, BLACK_MAX)

no_black = cv2.countNonZero(dst)

print('The number of black pixels is: ' + str(no_black))
python cv2 imread
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.