| 10 | #include <string> |
| 11 | |
| 12 | int main(int argc, char ** argv) { |
| 13 | if (argc < 3) { |
| 14 | fprintf(stderr, "Usage: %s <model.ggml> <image.jpg> [x y]\n", argv[0]); |
| 15 | return 1; |
| 16 | } |
| 17 | |
| 18 | const std::string model_path = argv[1]; |
| 19 | const std::string image_path = argv[2]; |
| 20 | float px = argc > 4 ? atof(argv[3]) : 315.0f; |
| 21 | float py = argc > 4 ? atof(argv[4]) : 250.0f; |
| 22 | |
| 23 | sam3_params params; |
| 24 | params.model_path = model_path; |
| 25 | params.use_gpu = false; |
| 26 | params.n_threads = 4; |
| 27 | |
| 28 | fprintf(stderr, "Loading model...\n"); |
| 29 | auto model = sam3_load_model(params); |
| 30 | if (!model) { fprintf(stderr, "Failed to load model\n"); return 1; } |
| 31 | |
| 32 | // Create tracker (no text prompt → propagation only, no PCS detection) |
| 33 | sam3_video_params vp; |
| 34 | vp.hotstart_delay = 0; // instant confirmation (no warmup) |
| 35 | vp.max_keep_alive = 100; |
| 36 | auto tracker = sam3_create_tracker(*model, vp); |
| 37 | if (!tracker) { fprintf(stderr, "Failed to create tracker\n"); return 1; } |
| 38 | |
| 39 | auto state = sam3_create_state(*model, params); |
| 40 | if (!state) { fprintf(stderr, "Failed to create state\n"); return 1; } |
| 41 | |
| 42 | // Load image (use same image for both frames for simplicity) |
| 43 | auto image = sam3_load_image(image_path); |
| 44 | if (image.data.empty()) { fprintf(stderr, "Failed to load image\n"); return 1; } |
| 45 | fprintf(stderr, "Image: %dx%d\n", image.width, image.height); |
| 46 | |
| 47 | // ════════════════════════════════════════════════════════════════ |
| 48 | // Frame 0: Encode + add instance via point |
| 49 | // ════════════════════════════════════════════════════════════════ |
| 50 | fprintf(stderr, "\n═══ Frame 0: Encode + Add Instance ═══\n"); |
| 51 | |
| 52 | // Encode image |
| 53 | if (!sam3_encode_image(*state, *model, image)) { |
| 54 | fprintf(stderr, "Failed to encode frame 0\n"); return 1; |
| 55 | } |
| 56 | |
| 57 | // Add instance at the clicked point |
| 58 | sam3_pvs_params pvs; |
| 59 | pvs.pos_points.push_back({px, py}); |
| 60 | pvs.multimask = false; |
| 61 | |
| 62 | int inst_id = sam3_tracker_add_instance(*tracker, *state, *model, pvs); |
| 63 | fprintf(stderr, "Added instance %d at (%.1f, %.1f)\n", inst_id, px, py); |
| 64 | |
| 65 | if (inst_id < 0) { |
| 66 | fprintf(stderr, "Failed to add instance\n"); |
| 67 | return 1; |
| 68 | } |
| 69 |
nothing calls this directly
no test coverage detected