Return intersection-over-union overlap between boxes i and j
| 28 | |
| 29 | // Return intersection-over-union overlap between boxes i and j |
| 30 | static inline float IOU(const float* boxes, int i, int j) { |
| 31 | const float yMinI = std::min<float>(boxes[i * 4 + 0], boxes[i * 4 + 2]); |
| 32 | const float xMinI = std::min<float>(boxes[i * 4 + 1], boxes[i * 4 + 3]); |
| 33 | const float yMaxI = std::max<float>(boxes[i * 4 + 0], boxes[i * 4 + 2]); |
| 34 | const float xMaxI = std::max<float>(boxes[i * 4 + 1], boxes[i * 4 + 3]); |
| 35 | const float yMinJ = std::min<float>(boxes[j * 4 + 0], boxes[j * 4 + 2]); |
| 36 | const float xMinJ = std::min<float>(boxes[j * 4 + 1], boxes[j * 4 + 3]); |
| 37 | const float yMaxJ = std::max<float>(boxes[j * 4 + 0], boxes[j * 4 + 2]); |
| 38 | const float xMaxJ = std::max<float>(boxes[j * 4 + 1], boxes[j * 4 + 3]); |
| 39 | const float areaI = (yMaxI - yMinI) * (xMaxI - xMinI); |
| 40 | const float areaJ = (yMaxJ - yMinJ) * (xMaxJ - xMinJ); |
| 41 | if (areaI <= 0 || areaJ <= 0) |
| 42 | return 0.0; |
| 43 | const float intersectionYMin = std::max<float>(yMinI, yMinJ); |
| 44 | const float intersectionXMin = std::max<float>(xMinI, xMinJ); |
| 45 | const float intersectionYMax = std::min<float>(yMaxI, yMaxJ); |
| 46 | const float intersectionXMax = std::min<float>(xMaxI, xMaxJ); |
| 47 | const float intersectionArea = std::max<float>(intersectionYMax - intersectionYMin, 0.0) * |
| 48 | std::max<float>(intersectionXMax - intersectionXMin, 0.0); |
| 49 | return intersectionArea / (areaI + areaJ - intersectionArea); |
| 50 | } |
| 51 | |
| 52 | static void NonMaxSuppressionSingleClasssImpl(const float* boxesPtr, const float* scores, int numBoxes, int maxDetections, |
| 53 | float iouThreshold, float scoreThreshold, std::vector<int32_t>* selected) { |
no outgoing calls
no test coverage detected