0

I have created a per_frame function that is fed into ImageAI's detector. I want to draw a line between centroid that meet the distance criteria (if distance >= find_dist_ratio(x1, y1)). Lines should be drawn between the centroids of all objects that meet the criteria, I tried changing it and finally got it without errors but the line does not show up in the output video. Thanks for the help!

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)
  • Try printing out the bbox coordinates and make sure they are in the format you expect. Many libraries will normalize the bounding box by the size of the image, so you may need to scale the x's by the image width and scale the y's by the image height. You could also try drawing a line from (0,0) to (frame.shape[1], frame.shape[0]) to make sure your line drawing works as expected – shortcipher3 May 20 '20 at 12:30

1 Answers1

0

It may sound silly, but in your piece of code I can't see if you are really showing the frame. And if the x and y variables are correct (from lower/upper case)

See this example from the docs:

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

For displaying the line drawn here you should also place (after drawing)

cv2.imshow("Line draw", img)

Drawing functions in the docs