【发布时间】:2021-03-05 06:01:13
【问题描述】:
我正在使用对象跟踪代码。 https://www.pyimagesearch.com/2015/09/21/opencv-track-object-movement/。有几次它工作得很好。它跟踪球很好。然后,打开相机没有问题,但是当我在相机的视野范围内移动网球时,我得到了以下错误
if counter >= 10 and i == 1 and pts[-10] is not None:IndexError: deque index out of range
dX = pts[-10][0] - pts[i][0]
dY = pts[-10][1] - pts[i][1]
(dirX, dirY) = ("", "")
如果我删除if counter >= 10 and i == 1 and pts[-10] is not None:
代码可以在不显示 x 和 y 的位置的情况下工作,但这不是我想要的。可能是什么问题?
【问题讨论】:
-
你试过用括号括住和的两个参数吗?我认为 and 首先被评估,所以你先做
10 and i然后剩下的......所以:if (counter >= 10) and (i == 1) and (pts[-10] is not None): -
它没有用。相机打开没有问题,但是当我将网球移到相机的视野范围内时,窗户就关闭了。