65 lines
2.2 KiB
C
65 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "stereo_bolt/c_api.h"
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc != 5) {
|
|
fprintf(stderr,
|
|
"usage: c_example_centerline <config.yaml> <left_image> <right_image> <expected_count>\n");
|
|
return 2;
|
|
}
|
|
|
|
const int expected_count = atoi(argv[4]);
|
|
StereoBoltCtx* ctx = sb_create(argv[1]);
|
|
if (ctx == NULL) {
|
|
fprintf(stderr, "sb_create failed: %s\n", sb_last_error(NULL));
|
|
return 1;
|
|
}
|
|
|
|
StereoBoltModuleResultC result;
|
|
const sb_status_t status =
|
|
sb_process_bolt_module_files(ctx, argv[2], argv[3], expected_count, &result);
|
|
|
|
if (status != SB_OK && status != SB_ERR_ALGORITHM_REJECTED) {
|
|
fprintf(stderr, "sb_process_bolt_module_files failed (%d): %s\n",
|
|
(int)status, sb_last_error(ctx));
|
|
sb_free_bolt_module_result(&result);
|
|
sb_destroy(ctx);
|
|
return 1;
|
|
}
|
|
|
|
printf("success=%d", result.success);
|
|
if (!result.success) {
|
|
printf(" failure_reason=%s left_rois=%d right_rois=%d pairs=%d\n",
|
|
result.failure.reason,
|
|
result.failure.n_left_rois,
|
|
result.failure.n_right_rois,
|
|
result.failure.n_pairs);
|
|
} else {
|
|
printf(" bolts=%d distances=%d\n",
|
|
result.data.n_bolts,
|
|
result.data.n_adjacent_distances);
|
|
}
|
|
|
|
for (int i = 0; i < result.data.n_bolts; ++i) {
|
|
const StereoBoltModuleBoltC* b = &result.data.bolts[i];
|
|
printf(" bolt_id=%d height=%.3f conf=%s status=%s foot=(%.3f,%.3f,%.3f) top=(%.3f,%.3f,%.3f)\n",
|
|
b->bolt_id, b->height_mm,
|
|
b->confidence == 0 ? "trusted" : "suspect", b->status,
|
|
b->foot_xyz.x, b->foot_xyz.y, b->foot_xyz.z,
|
|
b->top_xyz.x, b->top_xyz.y, b->top_xyz.z);
|
|
}
|
|
|
|
for (int i = 0; i < result.data.n_adjacent_distances; ++i) {
|
|
const StereoBoltModuleDistanceC* d = &result.data.adjacent_distances[i];
|
|
printf(" dist %d-%d %.3f mm\n",
|
|
d->bolt_id_i, d->bolt_id_j, d->distance_mm);
|
|
}
|
|
|
|
const int rc = result.success ? 0 : 3;
|
|
sb_free_bolt_module_result(&result);
|
|
sb_destroy(ctx);
|
|
return rc;
|
|
}
|