Skip to content

Discrepancy in input output format #13

@YannLepoittevin

Description

@YannLepoittevin

Hi,

First of all, thanks for the nice package.

It seems there is a discrepancy in the input / output format where input is expected as [left, top, right, bottom] as per lines:

xywh = xyxy2ltwh(xyxys)

and comment:
# Convert nx4 boxes from [x1, y1, x2, y2] to [x, y, w, h] where xy1=top-left, xy2=bottom-right

But outputs are send back as [center left, center top, right, bottom] as per line:

xyxy = xywh2xyxy(tlwh)

and definition of:

Steps to reproduce:

import numpy as np
from bytetracker import BYTETracker

h, w, n = 480, 640, 10
boxes = np.hstack([np.random.randint(0, w, n)[..., np.newaxis],
                   np.random.randint(0, h, n)[..., np.newaxis],
                   np.random.randint(0, w, n)[..., np.newaxis],
                   np.random.randint(0, h, n)[..., np.newaxis]])
scores = 0.8 + 0.2 * np.random.random(n)[..., np.newaxis]
classes = np.zeros((n, 1))
dets = np.hstack([boxes, scores, classes])

tracker = BYTETracker()
online_targets = tracker.update(dets)

np.allclose(boxes, online_targets[:, :4])

results in >> False with the actual code.

Potential fix, if [left, top, right, bottom] is the way to go with:

def xywh2xyxy(x):
    # Convert nx4 boxes from [x, y, w, h] to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right
    try:
        y = x.clone()
    except:
        y = np.copy(x)
    y[:, 0] = x[:, 0]   # top left x
    y[:, 1] = x[:, 1]   # top left y
    y[:, 2] = x[:, 0] + x[:, 2]  # bottom right x
    y[:, 3] = x[:, 1] + x[:, 3]  # bottom right y
    return y

Again, thanks for the package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions