VisDrone / VisDrone-Dataset

The dataset for drone based detection and tracking is released, including both image/video, and annotations.
1.22k stars 157 forks source link

How to visualise VisDrone target ID and bounding box? #34

Open fatbringer opened 1 year ago

fatbringer commented 1 year ago

I notice that the annotation files looked like that

1,0,19,783,60,91,1,1,0,0
2,0,16,782,60,91,1,1,0,0
3,0,13,781,60,91,1,1,0,0
4,0,11,780,60,91,1,1,0,0

How should i understand the annotation? Is it something like that? <Target ID>, <frame number>, <bbox_left>,<bbox_top>,<bbox_width>,<bbox_height>,<score>,<object_category>,<truncation>,<occlusion>

How may i display the bounding boxes such that it look like that? I do not need the class, but i just need the ID and the bounding box. track_all_seg_1280_025conf

Or something like that image

KyriakosChris commented 10 months ago

The only thing that you need is the class ID and the boxes, so you could edit the annotations files and keep only the important information, and then manually draw the boxes per image with the opencv. You could try something like this,(adjust it to your problem). The key lines are the cv2.rectangle and cv2.putText.

for i in range(detections.shape[2]):
    confidence = detections[0, 0, i, 2]
    if confidence > 0.5:
        class_id = int(detections[0, 0, i, 1])
        class_name = classes[class_id]
        box = detections[0, 0, i, 3:7] * np.array([image.shape[1], image.shape[0], image.shape[1], image.shape[0]])
        (startX, startY, endX, endY) = box.astype('int')
        cv2.rectangle(image, (startX, startY), (endX, endY), (0, 255, 0), 2)
        label = '{}: {:.2f}%'.format(class_name, confidence * 100)
        cv2.putText(image, label, (startX, startY - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imshow('Object Detection', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
fatbringer commented 10 months ago

@KyriakosChris hey! Thanks for the code. I forgot to close the issue as i solved it awhile back using cv2 methods too. Your implementation is neater :)