简体   繁体   English

使用 cv2.imread:“<built-in function imread> 没有设置错误就返回NULL”,好像无法打开图片或获取数据</built-in>

[英]Using cv2.imread: “<built-in function imread> returned NULL without setting an error”, as if it can't open the picture or get the data

This is the part of my code that gives the problem.这是我的代码中出现问题的部分。 It is supposed to count the amount of green pixels in a picture:它应该计算图片中绿色像素的数量:

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))

Image is already readed using PIL.Now the img is in array format so you cannot able to read it again.Read your file in any one kind of format either pil or cv2图像已使用 PIL 读取。现在 img 为数组格式,因此您无法再次读取它。以 pil 或 cv2 的任何一种格式读取文件

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

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

imgg = cv2.imread('path.tif', 1)

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

no_black = cv2.countNonZero(dst)

print('The number of black pixels is: ' + str(no_black))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cv2.imread 错误:img = cv2.imread(0) 系统错误:<built-in function imread> 返回 NULL 没有设置错误</built-in> - cv2.imread error:img = cv2.imread(0) SystemError: <built-in function imread> returned NULL without setting an error <built-in function imread>返回 NULL 没有设置错误</built-in> - <built-in function imread> returned NULL without setting an error 对象检测图像文件夹读取返回<built-in function imread>返回 NULL 而不设置错误 - Object Detection Images folder read return <built-in function imread> returned NULL without setting an error 系统错误:<built-in function imread> 返回 NULL 没有设置错误(tkinter)</built-in> - SystemError: <built-in function imread> returned NULL without setting an error (tkinter) 比较使用 ImageDataGenerator() 和 cv2.imread() 加载的数据 - Comparing Data loaded using ImageDataGenerator() and cv2.imread() 使用 cv2.imread() 时出现 Python openCV 错误 - Python openCV error while using cv2.imread() 使用cv2.imread的屏幕截图和语法错误 - screen capture and syntax error using cv2.imread 无法使用cv2.imread()读取图像 - Cannot read image using cv2.imread() 使用 cv2.imread() 在 Jupyter 笔记本上上传图像时出错 function - Error while uploading an image on Jupyter notebook using cv2.imread() function cv2.imwrite() 系统错误:<built-in function imwrite> 返回 NULL 没有设置错误</built-in> - cv2.imwrite() SystemError: <built-in function imwrite> returned NULL without setting an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM