python - opencv lib 错误:AttributeError: 'NoneType' 对象没有属性 'shape'
问题描述
我将图像的引用作为参数传递给函数。应该可以将引用列表传递给图像,因此使用列表。代码看起来像这样
def cleanOCR(borders):
detectedOCR = []
print(f'Borders = {borders}')
for i, image in enumerate(borders):
image = cv2.imread(image)
assert not isinstance(image,type(None)), 'image not found'
edges = cv2.Canny(image, 50, 150, apertureSize=3)
lines = cv2.HoughLinesP(image=edges, rho=1, theta=np.pi / 180, threshold=100, lines=np.array([]), minLineLength=100, maxLineGap=80)
a, b, c = lines.shape
但我得到一个错误
File "platesOCR.py", line 66, in cleanOCR
a, b, c = lines.shape
AttributeError: 'NoneType' object has no attribute 'shape'
我使用 cv2 版本 '4.1.1' 代码不是我的,我刚刚开始处理 OpenCV。
print(f'Borders = {borders}') give me right file path
解决方案
这本质上意味着在图像中没有检测到线条。
要检查这一点,只需打印行。我猜它会是空的。
要不得到一个空的 np 数组,请尝试减少 minLineLength 值。图像中短于该值的线段将被拒绝。所以我建议减少这个值。
还有maxLineGap。连接它们的同一条线上的点之间允许的最大间隙。所以你的价值似乎更高。
推荐阅读
- python - 如何从大量文章(维基百科)中训练短语模型?
- laravel - Laravel not add foreign key in PostgreSQL
- python - How to shoot bullets at the same time as another player and easier method on creating boundaries between rectangles and players?
- c - 我无法用 c 语言读取另一个结构
- python - convert list of element to int and not the string in python
- javascript - 在调用 JSON.stringify() 之前,Vue 数据不可用
- python-3.x - python selenium "Timed out receiving message from renderer" when getting screenshot
- laravel - Laravel get a empty variable from axios.post from vuie.js module
- python-3.x - 我想在 python 中使用 openpyxl 模块在 Excel 单元格中绘制对角线
- java - 如何从 apache POI dataValidators 正确转换 ExplicitListValues 进行测试?