#include #include "NCNNRect.h" template ByteTrackNCNN::Rect::Rect(const T& x, const T& y, const T& width, const T& height) : tlwh({ x, y, width, height }) { } template ByteTrackNCNN::Rect::~Rect() { } template const T& ByteTrackNCNN::Rect::x() const { return tlwh[0]; } template const T& ByteTrackNCNN::Rect::y() const { return tlwh[1]; } template const T& ByteTrackNCNN::Rect::width() const { return tlwh[2]; } template const T& ByteTrackNCNN::Rect::height() const { return tlwh[3]; } template T& ByteTrackNCNN::Rect::x() { return tlwh[0]; } template T& ByteTrackNCNN::Rect::y() { return tlwh[1]; } template T& ByteTrackNCNN::Rect::width() { return tlwh[2]; } template T& ByteTrackNCNN::Rect::height() { return tlwh[3]; } template const T& ByteTrackNCNN::Rect::tl_x() const { return tlwh[0]; } template const T& ByteTrackNCNN::Rect::tl_y() const { return tlwh[1]; } template T ByteTrackNCNN::Rect::br_x() const { return tlwh[0] + tlwh[2]; } template T ByteTrackNCNN::Rect::br_y() const { return tlwh[1] + tlwh[3]; } template ByteTrackNCNN::Tlbr ByteTrackNCNN::Rect::getTlbr() const { return { tlwh[0], tlwh[1], tlwh[0] + tlwh[2], tlwh[1] + tlwh[3], }; } template ByteTrackNCNN::Xyah ByteTrackNCNN::Rect::getXyah() const { return { tlwh[0] + tlwh[2] / 2, tlwh[1] + tlwh[3] / 2, tlwh[2] / tlwh[3], tlwh[3], }; } template float ByteTrackNCNN::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 ByteTrackNCNN::Rect generate_rect_by_tlbr(const ByteTrackNCNN::Tlbr& tlbr) { return ByteTrackNCNN::Rect(tlbr[0], tlbr[1], tlbr[2] - tlbr[0], tlbr[3] - tlbr[1]); } template ByteTrackNCNN::Rect generate_rect_by_xyah(const ByteTrackNCNN::Xyah& xyah) { const auto width = xyah[2] * xyah[3]; return ByteTrackNCNN::Rect(xyah[0] - width / 2, xyah[1] - xyah[3] / 2, width, xyah[3]); } // explicit instantiation template class ByteTrackNCNN::Rect; template class ByteTrackNCNN::Rect; template ByteTrackNCNN::Rect ByteTrackNCNN::generate_rect_by_tlbr(const ByteTrackNCNN::Tlbr&); template ByteTrackNCNN::Rect ByteTrackNCNN::generate_rect_by_tlbr(const ByteTrackNCNN::Tlbr&); template ByteTrackNCNN::Rect ByteTrackNCNN::generate_rect_by_xyah(const ByteTrackNCNN::Xyah&); template ByteTrackNCNN::Rect ByteTrackNCNN::generate_rect_by_xyah(const ByteTrackNCNN::Xyah&);