| 7 | #include <string> |
| 8 | |
| 9 | int main(int argc, char ** argv) { |
| 10 | if (argc < 3) { |
| 11 | fprintf(stderr, "Usage: %s <model.ggml> <video.mp4> [prompt] [n_frames]\n", argv[0]); |
| 12 | return 1; |
| 13 | } |
| 14 | |
| 15 | const std::string model_path = argv[1]; |
| 16 | const std::string video_path = argv[2]; |
| 17 | const std::string prompt = argc > 3 ? argv[3] : "car"; |
| 18 | const int n_frames = argc > 4 ? atoi(argv[4]) : 5; |
| 19 | |
| 20 | sam3_params params; |
| 21 | params.model_path = model_path; |
| 22 | params.use_gpu = false; |
| 23 | params.n_threads = 4; |
| 24 | |
| 25 | fprintf(stderr, "Loading model...\n"); |
| 26 | auto model = sam3_load_model(params); |
| 27 | if (!model) { fprintf(stderr, "Failed to load model\n"); return 1; } |
| 28 | |
| 29 | auto state = sam3_create_state(*model, params); |
| 30 | if (!state) { fprintf(stderr, "Failed to create state\n"); return 1; } |
| 31 | |
| 32 | auto vi = sam3_get_video_info(video_path); |
| 33 | fprintf(stderr, "Video: %dx%d, %d frames, %.1f fps\n", |
| 34 | vi.width, vi.height, vi.n_frames, vi.fps); |
| 35 | |
| 36 | // Create tracker with text prompt |
| 37 | sam3_video_params vp; |
| 38 | vp.text_prompt = prompt; |
| 39 | vp.score_threshold = 0.3f; |
| 40 | vp.hotstart_delay = 3; // Quick confirmation for testing |
| 41 | auto tracker = sam3_create_tracker(*model, vp); |
| 42 | if (!tracker) { fprintf(stderr, "Failed to create tracker\n"); return 1; } |
| 43 | |
| 44 | int total_tracked = 0; |
| 45 | for (int fi = 0; fi < std::min(n_frames, vi.n_frames); ++fi) { |
| 46 | fprintf(stderr, "\n════════════════════════════════════════\n"); |
| 47 | fprintf(stderr, " Frame %d/%d\n", fi, n_frames); |
| 48 | fprintf(stderr, "════════════════════════════════════════\n"); |
| 49 | |
| 50 | auto frame = sam3_decode_video_frame(video_path, fi); |
| 51 | if (frame.data.empty()) { |
| 52 | fprintf(stderr, "Failed to decode frame %d\n", fi); |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | auto result = sam3_track_frame(*tracker, *state, *model, frame); |
| 57 | fprintf(stderr, " Result: %zu detections\n", result.detections.size()); |
| 58 | |
| 59 | for (size_t i = 0; i < result.detections.size(); ++i) { |
| 60 | const auto& d = result.detections[i]; |
| 61 | int n_on = 0; |
| 62 | for (size_t j = 0; j < d.mask.data.size(); ++j) |
| 63 | if (d.mask.data[j] > 0) n_on++; |
| 64 | fprintf(stderr, " det %zu: inst=%d score=%.3f box=[%.0f,%.0f,%.0f,%.0f] mask=%.1f%%\n", |
| 65 | i, d.instance_id, d.score, |
| 66 | d.box.x0, d.box.y0, d.box.x1, d.box.y1, |
nothing calls this directly
no test coverage detected