Check if a click position lands on any tracked instance mask. Returns the instance_id or -1.
| 275 | // Check if a click position lands on any tracked instance mask. |
| 276 | // Returns the instance_id or -1. |
| 277 | static int find_instance_at(const vapp_state& app, float ix, float iy) { |
| 278 | int px = (int)ix, py = (int)iy; |
| 279 | for (const auto& det : app.result.detections) { |
| 280 | if (det.mask.data.empty()) continue; |
| 281 | if (px >= 0 && px < det.mask.width && |
| 282 | py >= 0 && py < det.mask.height && |
| 283 | det.mask.data[py * det.mask.width + px] > 127) { |
| 284 | return det.instance_id; |
| 285 | } |
| 286 | } |
| 287 | return -1; |
| 288 | } |
| 289 | |
| 290 | static void add_instance_from_prompts(vapp_state& app) { |
| 291 | if (!app.tracker_created || !app.frame_encoded) return; |