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

Function main

tests/test_pvs_point.cpp:9–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <string>
8
9int main(int argc, char ** argv) {
10 if (argc < 3) {
11 fprintf(stderr, "Usage: %s <model.ggml> <image.jpg> [x y]\n", argv[0]);
12 return 1;
13 }
14
15 const std::string model_path = argv[1];
16 const std::string image_path = argv[2];
17 float px = argc > 4 ? atof(argv[3]) : 315.0f;
18 float py = argc > 4 ? atof(argv[4]) : 250.0f;
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 fprintf(stderr, "Loading image: %s\n", image_path.c_str());
33 auto image = sam3_load_image(image_path);
34 if (image.data.empty()) { fprintf(stderr, "Failed to load image\n"); return 1; }
35 fprintf(stderr, "Image: %dx%d\n", image.width, image.height);
36
37 fprintf(stderr, "Encoding image...\n");
38 if (!sam3_encode_image(*state, *model, image)) {
39 fprintf(stderr, "Failed to encode image\n"); return 1;
40 }
41
42 fprintf(stderr, "\n═══ PVS: point at (%.1f, %.1f) ═══\n", px, py);
43
44 sam3_pvs_params pvs;
45 pvs.pos_points.push_back({px, py});
46 pvs.multimask = false;
47
48 auto result = sam3_segment_pvs(*state, *model, pvs);
49 fprintf(stderr, "Result: %zu detections\n", result.detections.size());
50
51 for (size_t i = 0; i < result.detections.size(); ++i) {
52 const auto& d = result.detections[i];
53 fprintf(stderr, " det %zu: score=%.4f iou=%.4f obj=%.4f box=[%.1f,%.1f,%.1f,%.1f] mask=%dx%d\n",
54 i, d.score, d.iou_score, d.mask.obj_score,
55 d.box.x0, d.box.y0, d.box.x1, d.box.y1,
56 d.mask.width, d.mask.height);
57
58 std::string mask_path = "/tmp/pvs_mask_" + std::to_string(i) + ".png";
59 sam3_save_mask(d.mask, mask_path);
60 fprintf(stderr, " Saved: %s\n", mask_path.c_str());
61
62 // Count mask pixels
63 int n_on = 0;
64 for (size_t j = 0; j < d.mask.data.size(); ++j)
65 if (d.mask.data[j] > 0) n_on++;
66 fprintf(stderr, " Mask: %d/%zu pixels on (%.1f%%)\n",

Callers

nothing calls this directly

Calls 7

sam3_load_modelFunction · 0.85
sam3_create_stateFunction · 0.85
sam3_load_imageFunction · 0.85
sam3_encode_imageFunction · 0.85
sam3_segment_pvsFunction · 0.85
sam3_save_maskFunction · 0.85
sam3_free_modelFunction · 0.85

Tested by

no test coverage detected