MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / main

Function main

tests/test_sam2_video_debug.cpp:51–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51int main(int argc, char** argv) {
52 if (argc < 3) {
53 fprintf(stderr, "Usage: %s <model.ggml> <video_frames_dir> [point_x point_y]\n", argv[0]);
54 return 1;
55 }
56
57 const char* model_path = argv[1];
58 const char* frames_dir = argv[2];
59 float point_x = (argc > 3) ? atof(argv[3]) : 210.0f;
60 float point_y = (argc > 4) ? atof(argv[4]) : 350.0f;
61
62 const char* dump_dir = "/tmp/debug_sam2_cpp";
63 mkdir(dump_dir, 0755);
64
65 const int N_FRAMES = argc > 5 ? atoi(argv[5]) : 5;
66 int encode_img_size = (argc > 6) ? atoi(argv[6]) : 0;
67
68 // Load model
69 fprintf(stderr, "Loading model: %s\n", model_path);
70 sam3_params params;
71 params.model_path = model_path;
72 params.use_gpu = false; // CPU for reproducibility
73 params.encode_img_size = encode_img_size;
74 auto model = sam3_load_model(params);
75 if (!model) {
76 fprintf(stderr, "Failed to load model\n");
77 return 1;
78 }
79
80 // Create state
81 auto state = sam3_create_state(*model, params);
82 if (!state) {
83 fprintf(stderr, "Failed to create state\n");
84 return 1;
85 }
86
87 // Load frames as JPEG images
88 std::vector<sam3_image> frames;
89 for (int i = 0; i < N_FRAMES + 1; ++i) {
90 char path[512];
91 snprintf(path, sizeof(path), "%s/%05d.jpg", frames_dir, i);
92 sam3_image img = sam3_load_image(path);
93 if (img.data.empty()) {
94 fprintf(stderr, "Failed to load frame %d: %s\n", i, path);
95 return 1;
96 }
97 fprintf(stderr, "Loaded frame %d: %dx%d\n", i, img.width, img.height);
98 frames.push_back(std::move(img));
99 }
100
101 // Create visual tracker
102 sam3_visual_track_params vtp;
103 vtp.max_keep_alive = 100;
104 vtp.recondition_every = 16;
105 auto tracker = sam3_create_visual_tracker(*model, vtp);
106 if (!tracker) {
107 fprintf(stderr, "Failed to create tracker\n");
108 return 1;

Callers

nothing calls this directly

Calls 9

sam3_load_modelFunction · 0.85
sam3_create_stateFunction · 0.85
sam3_load_imageFunction · 0.85
sam3_encode_imageFunction · 0.85
sam3_dump_state_tensorFunction · 0.85
sam3_propagate_frameFunction · 0.85
dump_tensor_f32Function · 0.85

Tested by

no test coverage detected