Resolve overlapping masks: higher-scoring instances take priority.
| 9548 | |
| 9549 | // Resolve overlapping masks: higher-scoring instances take priority. |
| 9550 | static void sam3_resolve_overlaps(std::vector<sam3_detection>& dets) { |
| 9551 | if (dets.size() <= 1) return; |
| 9552 | const int w = dets[0].mask.width; |
| 9553 | const int h = dets[0].mask.height; |
| 9554 | if (w == 0 || h == 0) return; |
| 9555 | std::sort(dets.begin(), dets.end(), [](const sam3_detection& a, const sam3_detection& b) { |
| 9556 | return a.score > b.score; |
| 9557 | }); |
| 9558 | const int n = w * h; |
| 9559 | for (int i = 0; i < n; ++i) { |
| 9560 | bool claimed = false; |
| 9561 | for (auto& det : dets) { |
| 9562 | if (det.mask.data.empty()) continue; |
| 9563 | if (claimed) { |
| 9564 | det.mask.data[i] = 0; |
| 9565 | } else if (det.mask.data[i] > 127) { |
| 9566 | claimed = true; |
| 9567 | } |
| 9568 | } |
| 9569 | } |
| 9570 | } |
| 9571 | |
| 9572 | /***************************************************************************** |
| 9573 | ** Post-processing: NMS, bilinear interpolation, mask binarization |
no outgoing calls
no test coverage detected