12 #ifndef MLPACK_CORE_METRICS_IOU_IMPL_HPP 13 #define MLPACK_CORE_METRICS_IOU_IMPL_HPP 21 template<
bool UseCoordinates>
22 template <
typename VecTypeA,
typename VecTypeB>
27 Log::Assert(a.n_elem == b.n_elem && a.n_elem == 4,
"Incorrect \ 28 shape for bounding boxes. They must contain 4 elements either be \ 29 {x0, y0, x1, y1} or {x0, y0, h, w}. Refer to the documentation \ 30 for more information.");
36 if (a(0) >= a(2) || a(1) >= a(3) || b(0) >= b(2) || b(1) >= b(3))
38 Log::Fatal <<
"Check the correctness of bounding boxes i.e. " <<
39 "{x0, y0} must represent lower left coordinates and " <<
40 "{x1, y1} must represent upper right coordinates of bounding" <<
44 typename VecTypeA::elem_type interSectionArea = std::max(0.0,
45 std::min(a(2), b(2)) - std::max(a(0), b(0)) + 1) * std::max(0.0,
46 std::min(a(3), b(3)) - std::max(a(1), b(1)) + 1);
50 return interSectionArea / (1.0 * ((a(2) - a(0) + 1) * (a(3) - a(1) + 1) +
51 (b(2) - b(0) + 1) * (b(3) - b(1) + 1) - interSectionArea));
56 Log::Assert(a(2) > 0 && b(2) > 0 && a(3) > 0 && b(3) > 0,
"Height and width \ 57 of bounding boxes must be greater than zero.");
59 typename VecTypeA::elem_type interSectionArea = std::max(0.0,
60 std::min(a(0) + a(2), b(0) + b(2)) - std::max(a(0), b(0)) + 1)
61 * std::max(0.0, std::min(a(1) + a(3), b(1) + b(3)) - std::max(a(1),
64 return interSectionArea / (1.0 * ((a(2) + 1) * (a(3) + 1) + (b(2) + 1) *
65 (b(3) + 1) - interSectionArea));
67 template<
bool UseCoordinates>
68 template<
typename Archive>
static VecTypeA::elem_type Evaluate(const VecTypeA &a, const VecTypeB &b)
Computes the Intersection over Union metric between of two bounding boxes having pattern bx...
Definition: iou_metric_impl.hpp:23
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void serialize(Archive &ar, const uint32_t)
Serialize the metric.
Definition: iou_metric_impl.hpp:69
static void Assert(bool condition, const std::string &message="Assert Failed.")
Checks if the specified condition is true.
Definition: log.cpp:38