0

我创建了一个输入到 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)
4

1 回答 1

0

听起来可能很傻,但是在您的代码中,我看不到您是否真的在显示框架。如果 x 和 y 变量是正确的(从小写/大写)

请参阅文档中的此示例:

# Create a black image
img = np.zeros((512,512,3), np.uint8)
# Draw a diagonal blue line with thickness of 5 px
cv.line(img,(0,0),(511,511),(255,0,0),5)

为了显示此处绘制的线,您还应该放置(绘制后)

cv2.imshow("Line draw", img)

文档中的绘图函数

于 2020-05-19T16:59:18.367 回答