无法使用 OpenCV 绘制线条

Unable to draw lines using OpenCV

我创建了一个 per_frame 函数,它被输入到 ImageAI 的检测器中。我想在满足距离标准的质心之间画一条线(如果距离 >= 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)

这听起来可能很傻,但在你的代码中我看不出你是否真的在显示框架。如果 x 和 y 变量正确(来自 lower/upper 案例)

请参阅文档中的示例:

# 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)

Drawing functions 在文档中