python - TypeError:“NoneType”对象不可迭代崩溃
问题描述
代码是:
lines = cv2.HoughLinesP(masked_image, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap)
# Create an empty black image
line_image = np.zeros((masked_image.shape[0], masked_image.shape[1], 3), dtype=np.uint8)
for line in lines: #where the error is happing
for x1,y1,x2,y2 in line:
cv2.line(line_image, (x1, y1), (x2, y2), [0, 0, 255], 20)
出现此错误:
Traceback (most recent call last):
File "linefindinginvideo.py", line 48, in <module>
for line in lines:
TypeError: 'NoneType' object is not iterable
有关完整代码,请访问我的 GitHub https://github.com/jimhoggey/SelfdrivingcarForza/blob/main/lanemarkinginvideo.py
解决方案
这意味着这一行:
cv2.HoughLinesP(masked_image, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap)
返回None
,其原因是它无法检测到任何行。您将需要调整一些值以使检测正常工作,或者可能是图像中确实没有线条的情况。
推荐阅读
- node.js - 如何在 DiscordJS 中的两个字符串之间隔离一个字符串?
- python - 从解耦导入配置出错
- deep-learning - 如何在 GPU 上运行 ONNX 模型?
- r - 保留在该列表中没有适当子集的元素(来自向量列表)(在 R 中)
- python - 输出字典,其中每个元素都是带有索引的字符串字符
- android - BillingClient.queryPurchases 与 IInAppBillingService.getPurchases 有什么区别(用于帐户保留和恢复实施)
- javascript - 为什么它返回null?
- javascript - 键入“npx webpack”命令后,可能导致此“写入 EOF”错误的原因是什么?
- css - 如何准确打印页面在屏幕上的外观?
- excel - 如何使用 vba 匹配列并计算匹配项