我创建了一个输入到 ImageAI 检测器的 per_frame 函数。我想在满足距离标准的质心之间画一条线(如果距离> = find_dist_ratio(x1,y1))。应该在符合标准的所有对象的质心之间绘制线条,我尝试更改它并最终没有错误地得到它,但线条没有出现在输出视频中。谢谢您的帮助!
def dist_func(counting, output_objects_array,output_objects_count):
a =[]
ret, frame = camera.read()
for d in output_objects_array:
x1 = d['box_points'][0]
y1 = d['box_points'][1]
x2 = d['box_points'][2]
y2 = d['box_points'][3]
centroid = (int((x1 + x2) / 2), int((y1 + y2) / 2))
a.append(centroid)
for i in range(len(a)):
for j in range(i+1, len(a)):
distance = euc_dist(a[i],a[j])
if distance >= find_dist_ratio(x1, y1):
print('close enough')
x, y = a[i]
X, Y = a[j]
cv2.line(frame, (x, y), (X, Y), (255, 0, 0), 5)