def load_detrac_mat(fname):
    """Loads UA-DETRAC annotations data from mat files

    Competition Site: http://detrac-db.rit.albany.edu/download

    File contains a nested structure of 2d arrays for indexed by frame id
    and Object ID. Separate arrays for top, left, width and height are given.

    Params
    ------
    fname : str
        Filename to load data from

    Kwargs
    ------
    Currently none of these arguments used.

    Returns
    ------
    df : pandas.DataFrame
        The returned dataframe has the following columns
            'X', 'Y', 'Width', 'Height', 'Confidence', 'ClassId', 'Visibility'
        The dataframe is indexed by ('FrameId', 'Id')   
    """

    matData = scipy.io.loadmat(fname)

    frameList = matData['gtInfo'][0][0][4][0]
    leftArray = matData['gtInfo'][0][0][0].astype(np.float32)
    topArray = matData['gtInfo'][0][0][1].astype(np.float32)
    widthArray = matData['gtInfo'][0][0][3].astype(np.float32)
    heightArray = matData['gtInfo'][0][0][2].astype(np.float32)

    parsedGT = []
    for f in frameList:
        ids = [i + 1 for i, v in enumerate(leftArray[f - 1]) if v > 0]
        for i in ids:
            row = []
            row.append(f)
            row.append(i)
            row.append(leftArray[f - 1, i - 1] - widthArray[f - 1, i - 1] / 2)
            row.append(topArray[f - 1, i - 1] - heightArray[f - 1, i - 1])
            row.append(widthArray[f - 1, i - 1])
            row.append(heightArray[f - 1, i - 1])
            row.append(1)
            row.append(-1)
            row.append(-1)
            row.append(-1)
            parsedGT.append(row)

    df = pd.DataFrame(parsedGT,
                      columns=['FrameId', 'Id', 'X', 'Y', 'Width', 'Height', 'Confidence', 'ClassId', 'Visibility', 'unused'])
    df.set_index(['FrameId', 'Id'], inplace=True)

    # Account for matlab convention.
    df[['X', 'Y']] -= (1, 1)

    # Removed trailing column
    del df['unused']

    return df
Loads UA-DETRAC annotations data from mat files

    Competition Site: http://detrac-db.rit.albany.edu/download

    File contains a nested structure of 2d arrays for indexed by frame id
    and Object ID. Separate arrays for top, left, width and height are given.

    Params
    ------
    fname : str
        Filename to load data from

    Kwargs
    ------
    Currently none of these arguments used.

    Returns
    ------
    df : pandas.DataFrame
        The returned dataframe has the following columns
            'X', 'Y', 'Width', 'Height', 'Confidence', 'ClassId', 'Visibility'
        The dataframe is indexed by ('FrameId', 'Id')   
    
motmetrics/io.py