【发布时间】:2020-05-19 16:26:45
【问题描述】:
我创建了一个输入到 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)
【问题讨论】:
-
尝试打印出 bbox 坐标并确保它们是您期望的格式。许多库会按图像大小对边界框进行归一化,因此您可能需要按图像宽度缩放 x 并按图像高度缩放 y。您也可以尝试从 (0,0) 到 (frame.shape[1], frame.shape[0]) 画一条线,以确保您的线图按预期工作
标签: python opencv object-detection video-processing imageai