【发布时间】:2021-06-30 15:01:52
【问题描述】:
我有一个项目来检测人与人之间的距离。当质心和绘图线在人的中心时,项目运行顺利。但是,我想将质心和绘图线移动到人们的脚上,我已经成功地移动了质心,但绘图线没有沿着质心移动。这是代码:
utils.py(默认距离)
def distancing(people_coords, img, dist_thres_lim=(200,250)):
# Plot lines connecting people
already_red = dict() # dictionary to store if a plotted rectangle has already been labelled as high risk
centers = []
for i in people_coords:
centers.append(((int(i[0])+int(i[2]))//2, (int(max(i[3]), (i[1])))))
for j in centers:
already_red[j] = 0
x_combs = list(itertools.combinations(people_coords,2))
radius = 10
thickness = 5
for x in x_combs:
xyxy1, xyxy2 = x[0],x[1]
cntr1 = ((int(xyxy1[2])+int(xyxy1[0]))//2,(int(xyxy1[3])+int(xyxy1[1]))//2)
cntr2 = ((int(xyxy2[2])+int(xyxy2[0]))//2,(int(xyxy2[3])+int(xyxy2[1]))//2)
dist = ((cntr2[0]-cntr1[0])**2 + (cntr2[1]-cntr1[1])**2)**0.5
问题在于 people_coords(循环)xy 坐标。我试图用 (int(max(i[3]), (i[1]))))) 更改代码,但是当我运行它时,我得到一个错误(TypeError:迭代 0-d 张量) .我应该怎么做才能将绘图线与质心一起移动?
这是质心代码
def plot_dots_on_people(x, img):
# Plotting centers of people with green dot.
thickness = -1;
color = [0, 255, 0] # green
center = ((int(x[0])+int(x[2]))//2, (int(max(x[3], x[1]))))
radius = 10
cv2.circle(img, center, radius, color, thickness)
希望有人能帮助我,谢谢。
【问题讨论】:
标签: python tensorflow pytorch centroid