python - 我正在尝试使用 QR 码扫描仪,但出现此错误:像素、宽度、高度 = 图像 TypeError: cannot unpack non-iterable NoneType object
问题描述
几周前我尝试了相同的代码,它运行良好,但现在我收到了这个错误
像素、宽度、高度 = 图像类型错误:无法解压不可迭代的 NoneType 对象
编辑:问题已解决。代码很好,问题是我的内置网络摄像头。当我连接一个新的网络摄像头时,它工作正常。
非常感谢你的帮助。这是我在堆栈中的第一个问题
解决方案
看起来你很可能read()
失败了。您必须先检查您的读取是否成功,然后继续迭代:
while True:
success, image = capture.read()
if success:
for eachcode in decode(image):
...
else:
print('Capture failed')
如果您仍然遇到相同的错误,您也可以检查是否decode()
没有返回None
:
while True:
success, image = capture.read()
decoded_image = decode(image)
if success and decoded_image is not None:
for eachcode in decoded_image:
...
else:
print('Capture failed')
推荐阅读
- javascript - asp.net core 下载 excel 文件和消息
- ssh.net - SSH.Net,在启动命令时识别shell何时要求用户输入。BeginExecute()
- python - 如何在不启动应用程序的情况下在 django 应用程序中使用 Django 导入
- c# - 如何将 Infrastructure.DbQuery 转换为 ViewModel 类型?
- angular - 如何用角度颜色突出显示选定的mat-list-item?
- asp.net-core - ASP.NET Core - 如何创建一个长寿的 RabbitMQ 连接对象?
- python - 具有类、产量支持和 z3py 的 Numba 替代方案
- spring - @Bean List 在实现类中不起作用
- python - 熊猫在时间表中跳过停止
- vue.js - Vue.js 构建并部署到单个文件