下面的代码遍历出队(双端队列)中存储的一组点。
import numpy as np
pts1_blue=[(230,50),(100,200),.....] #this is just example values of the centroids
for i in range(1, len(pts1_blue)):
# if either of the tracked points are None, ignore
# them
if pts1_blue[i - 1] is None or pts1_blue[i] is None:
continue
# # otherwise, compute the thickness of the line and
# draw the connecting lines
if len(pts1_blue)>=10:
if counter_blue_1 >= 10 and i == 1 and pts1_blue[-10] is not None:
# compute the difference between the x and y
# coordinates and re-initialize the direction
# text variables
dX_blue = pts1_blue[-10][0] - pts1_blue[i][0]
dY_blue = pts1_blue[-10][1] - pts1_blue[i][1]
# print('DXX',dX_blue)
(dirX_blue, dirY_blue) = ("", "")
# ensure there is significant movement in the
# x-direction
if np.abs(dX_blue) > 20:
# print('DXXXX_blue',dX_blue)
dirX_blue = "North" if np.sign(dX_blue) == 1 else "South"
# ensure there is significant movement in the
# y-direction
if np.abs(dY_blue) > 20:
dirY_blue = "East" if np.sign(dY_blue) == 1 else "West"
# handle when both directions are non-empty
if dirX_blue != "" and dirY_blue != "":
# direction_blue = "{}-{}".format(dirY_blue, dirX_blue)
# otherwise, only one direction is non-empty
# else:
direction_blue = dirX_blue if np.abs(dirX_blue) > np.abs(dirY_blue) else dirY_blue
这些点代表不同帧中检测到的小型汽车的质心。我正在使用这些中心坐标来计算当前帧的y和y坐标与缓冲区后面的帧(它们之间的10帧距离)之间的差,并根据增量的符号对方向进行分类。但是,我需要我的代码通过选择大于另一个的增量来处理dx和dy都不为零的情况。当我运行代码时,它返回以下错误:
direction_blue = dirX_blue if np.abs(dirX_blue) > np.abs(dirY_blue) else dirY_blue
UFuncTypeError: ufunc 'absolute' did not contain a loop with signature matching types dtype('<U5') -
> dtype('<U5')
我在帖子中发现了相同的错误,但是无法解释我的情况,因此,我将感谢您的帮助。
注意:方向为南北西向和东向。 dx和dy都不为零的情况是汽车在对角线行驶时,但是我想根据最大变化量对该方向进行分类
预先感谢 哈立德