matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.66k stars 11.71k forks source link

Convert ROI inputs to MOT Challenge format #327

Closed haroonchoudery closed 6 years ago

haroonchoudery commented 6 years ago

I understand that the ROI outputs for each detected object correspond to [y1, x1, y2, x2]. I would like to convert the outputs to MOT Challenge format so that I can use the detections for an object detection task (using DeepSORT). The MOT Challenge format is described here: https://motchallenge.net/instructions/

<frame>, <id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <conf>, <x>, <y>, <z>

haroonchoudery commented 6 years ago

I accomplished this by using the following function:

def to_mot_format(frame_idx, coord):
    """
    Input coordinates:
    (y1, x1, y2, x2)

    Output coordinates:
    (frame, id, bb_left, bb_top, bb_width, bb_height, -1, -1, -1, -1)
    """
    padding = np.array([-1, -1, -1, -1])

    coord = np.insert(coord, 0, frame_idx)
    coord = np.insert(coord, 1, -1)
    coord = np.append(coord, padding)

    width = coord[5] - coord[3]
    height = coord[4] - coord[2]

    coord[4] = width
    coord[5] = height

    # Rearrange coordinates
    coord = coord[[0, 1, 3, 2, 4, 5, 6, 7, 8, 9]]
waleedka commented 6 years ago

Thanks for sharing. Closing the issue.