Eli*_*ias 0 python opencv numpy
我正在尝试在运行 Raspbian GNU/Linux 11(牛眼)的 Raspberry Pi 3B+ 上使用 OpenCV 并使用以下代码裁剪相机拍摄的图像,我得到以下输出:
Traceback (most recent call last):
File "/home/pi/Desktop/test-code-elias/camquali.py", line 141, in <module>
right_wall = img[1:1944, 1:1000]
TypeError: tuple indices must be integers or slices, not tuple
Run Code Online (Sandbox Code Playgroud)
我的代码:
img = cam.read()
right_wall = img[0:1944, 0:1000]
Run Code Online (Sandbox Code Playgroud)
小智 5
img是一个元组。显然cam.read()返回一个元组,而不是您期望的任何内容。元组中的元素之一可能是您正在查找的图像数组,因此您必须首先提取它。元组是一维的,您提供二维索引,这就是错误消息的来源。
如果,正如/sf/users/1154153031/善意添加的那样,输出是(success, img),您需要像这样更改代码:
success, img = cam.read()
assert success
right_wall = img[0:1944, 0:1000]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1647 次 |
| 最近记录: |