#include "Rect.h" #include template ByteTrack::Rect::Rect(const T &x, const T &y, const T &width, const T &height) : tlwh({x, y, width, height}) { } template ByteTrack::Rect::~Rect() { } template const T& ByteTrack::Rect::x() const { return tlwh[0]; } template const T& ByteTrack::Rect::y() const { return tlwh[1]; } template const T& ByteTrack::Rect::width() const { return tlwh[2]; } template const T& ByteTrack::Rect::height() const { return tlwh[3]; } template T& ByteTrack::Rect::x() { return tlwh[0]; } template T& ByteTrack::Rect::y() { return tlwh[1]; } template T& ByteTrack::Rect::width() { return tlwh[2]; } template T& ByteTrack::Rect::height() { return tlwh[3]; } template const T& ByteTrack::Rect::tl_x() const { return tlwh[0]; } template const T& ByteTrack::Rect::tl_y() const { return tlwh[1]; } template T ByteTrack::Rect::br_x() const { return tlwh[0] + tlwh[2]; } template T ByteTrack::Rect::br_y() const { return tlwh[1] + tlwh[3]; } template ByteTrack::Tlbr ByteTrack::Rect::getTlbr() const { return { tlwh[0], tlwh[1], tlwh[0] + tlwh[2], tlwh[1] + tlwh[3], }; } template ByteTrack::Xyah ByteTrack::Rect::getXyah() const { return { tlwh[0] + tlwh[2] / 2, tlwh[1] + tlwh[3] / 2, tlwh[2] / tlwh[3], tlwh[3], }; } template float ByteTrack::Rect::calcIoU(const Rect& other) const { const float box_area = (other.tlwh[2] + 1) * (other.tlwh[3] + 1); const float iw = std::min(tlwh[0] + tlwh[2], other.tlwh[0] + other.tlwh[2]) - std::max(tlwh[0], other.tlwh[0]) + 1; float iou = 0; if (iw > 0) { const float ih = std::min(tlwh[1] + tlwh[3], other.tlwh[1] + other.tlwh[3]) - std::max(tlwh[1], other.tlwh[1]) + 1; if (ih > 0) { const float ua = (tlwh[0] + tlwh[2] - tlwh[0] + 1) * (tlwh[1] + tlwh[3] - tlwh[1] + 1) + box_area - iw * ih; iou = iw * ih / ua; } } return iou; } template ByteTrack::Rect ByteTrack::generate_rect_by_tlbr(const ByteTrack::Tlbr& tlbr) { return ByteTrack::Rect(tlbr[0], tlbr[1], tlbr[2] - tlbr[0], tlbr[3] - tlbr[1]); } template ByteTrack::Rect ByteTrack::generate_rect_by_xyah(const ByteTrack::Xyah& xyah) { const auto width = xyah[2] * xyah[3]; return ByteTrack::Rect(xyah[0] - width / 2, xyah[1] - xyah[3] / 2, width, xyah[3]); } // explicit instantiation template class ByteTrack::Rect; template class ByteTrack::Rect; template ByteTrack::Rect ByteTrack::generate_rect_by_tlbr(const ByteTrack::Tlbr&); template ByteTrack::Rect ByteTrack::generate_rect_by_tlbr(const ByteTrack::Tlbr&); template ByteTrack::Rect ByteTrack::generate_rect_by_xyah(const ByteTrack::Xyah&); template ByteTrack::Rect ByteTrack::generate_rect_by_xyah(const ByteTrack::Xyah&);