12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include "dl_api.h"
- #define EUCLIDEAN_DISTANCE(x1, y1, x2, y2) (sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2)))
- // >0 -> Clockwise orientation || <0 -> Counterclockwise orientation || =0 -> Collinear orientation
- #define POINT_ON_SIDE(p1, p2, p3) ((p2.y - p1.y) * (p3.x - p2.x) - (p2.x - p1.x) * (p3.y - p2.y))
- #define CALC_ANGLE(p1, p2, p3) (std::acos(((p2.x - p1.x) * (p3.x - p1.x) + (p2.y - p1.y) * (p3.y - p1.y)) / (std::sqrt((std::pow(p2.x - p1.x, 2) + std::pow(p2.y - p1.y, 2))) * std::sqrt((std::pow(p3.x - p1.x, 2) + std::pow(p3.y - p1.y, 2))))) * 180 / M_PI)
- #define LINE_ANGLE(point1, point2) (std::atan2((point2.y) - (point1.y), (point2.x) - (point1.x)) * 180 / M_PI)
- #define IOU(rect1, rect2) \
- ({ \
- float xmin1 = rect1.x; \
- float ymin1 = rect1.y; \
- float xmax1 = rect1.x + rect1.w; \
- float ymax1 = rect1.y + rect1.h; \
- float xmin2 = rect2.x; \
- float ymin2 = rect2.y; \
- float xmax2 = rect2.x + rect2.w; \
- float ymax2 = rect2.y + rect2.h; \
- float interArea = \
- (std::min(xmax1, xmax2) - std::max(xmin1, xmin2)) * \
- (std::min(ymax1, ymax2) - std::max(ymin1, ymin2)); \
- float rect1Area = rect1.w * rect1.h; \
- float rect2Area = rect2.w * rect2.h; \
- float iou = interArea / (rect1Area + rect2Area - interArea); \
- iou; \
- })
- static bool isPointInRect(sampleRunJoint_POINT_S p, sampleRunJoint_RECT_S r) {
- return (p.x >= r.x && p.x <= r.x + r.w && p.y >= r.y && p.y <= r.y + r.h);
- }
-
- static bool isLineIntersectRect(sampleRunJoint_POINT_S l1, sampleRunJoint_POINT_S l2, sampleRunJoint_RECT_S r) {
- if (isPointInRect(l1, r) || isPointInRect(l2, r)) {
- return true;
- }
- if (l1.x > r.x + r.w && l2.x > r.x + r.w) {
- return false;
- }
- if (l1.x < r.x && l2.x < r.x) {
- return false;
- }
- if (l1.y > r.y + r.h && l2.y > r.y + r.h) {
- return false;
- }
- if (l1.y < r.y && l2.y < r.y) {
- return false;
- }
- return true;
- }
- static sampleRunJoint_POINT_S calculateCentroid(const sampleRunJoint_POINT_S& p1, const sampleRunJoint_POINT_S& p2) {
- sampleRunJoint_POINT_S centroid;
- centroid.x = (p1.x + p2.x) / 2;
- centroid.y = (p1.y + p2.y) / 2;
- return centroid;
- }
|