Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
spotter_cam.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file spotter_cam.cpp
20 * @brief Object-model decoder, detection sidecar writer and detector entry point.
21 * @details Camera/DMA/JPEG ownership belongs to imx500_camera.cpp. This application
22 * interprets retained frame metadata only as object boxes; it contains no LOOM
23 * feature processing, reference matching or waypoint policy. A structurally
24 * valid empty detection result is useful evidence and differs from missing or
25 * malformed inference; keep that distinction when extending the model contract.
26 */
27
28#include <algorithm>
29#include <array>
30#include <cerrno>
31#include <cmath>
32#include <cstdio>
33#include <cstdlib>
34#include <cstring>
35#include <chrono>
36#include <poll.h>
37#include <sys/stat.h>
38#include <unistd.h>
39
40#include "version.h"
41#include "inference_worker.h"
42#include "spotter_targets.h"
43#include "camera_profile.h"
44
45#ifndef SENSORAIA_INFERENCE_ONLY
46#include "imx500_camera.hpp"
47#include "imx500_tensor.h"
48#include "inference_capture.hpp"
49
50/** Internal implementation details documented here to make the camera and model
51 * contracts navigable. */
52namespace spottercam {
53
54/** Physical IMX500 pixel-array dimensions expected by the model's coordinate
55 * transform. */
56constexpr unsigned int sensor_width = imx500::sensor_width;
57/** @brief Sensor-space height, separate from model and encoded-image dimensions. */
58constexpr unsigned int sensor_height = imx500::sensor_height;
59/** Input dimensions of the object RPK's absolute-coordinate detection head. */
60constexpr unsigned int model_input_width = 320;
61/** @brief This detection head's input height; LOOM does not reuse its box semantics. */
62constexpr unsigned int model_input_height = 320;
63/** The model emits boxes, scores, classes, and a detection count in this order.
64 */
65constexpr uint32_t expected_output_tensor_count = 4;
66constexpr uint32_t bbox_values_per_candidate = 4; /**< Left/top/right/bottom values in each candidate. */
67constexpr uint32_t score_values_before_candidates = 4; /**< Scores follow all box coordinate values. */
68constexpr uint32_t class_values_before_candidates = 5; /**< Classes follow coordinates and scores. */
69constexpr uint32_t values_per_candidate_with_score_and_class = 6; /**< Count follows the three candidate arrays. */
70/** Maximum candidate count permitted by the model's fixed tensor scratch bound.
71 */
73/** Maximum tensor rank documented by libcamera's Raspberry Pi IMX500 controls.
74 */
76/** Metadata layout: fixed header, tensor count, then fixed-size tensor records.
77 */
79constexpr size_t tensor_count_offset =
80 IMX500_TENSOR_COUNT_OFFSET; /**< Four-byte tensor count follows the header. */
82 IMX500_TENSOR_FIRST_RECORD_OFFSET; /**< First record follows count. */
83constexpr size_t tensor_record_size =
84 IMX500_TENSOR_RECORD_BYTES; /**< Fixed fields followed by sixteen 16-bit dimensions. */
86 IMX500_TENSOR_DIMENSIONS_OFFSET; /**< Length and rank occupy the first eight bytes. */
88 IMX500_TENSOR_DIMENSION_BYTES; /**< Each shape entry is an unsigned 16-bit value. */
89constexpr size_t tensor_record_rank_offset =
90 IMX500_TENSOR_RANK_OFFSET; /**< Rank follows the four-byte element count. */
92 IMX500_TENSOR_LENGTH_OFFSET; /**< Element count starts each record. */
93/** Full IMX500 metadata structure size (16 records, each with up to 16
94 * dimensions). */
95constexpr size_t tensor_info_size =
97/** Current single-class model contract: class zero, confidence 0.6, at most
98 * five boxes. */
99constexpr size_t maximum_detections = 5;
100constexpr uint32_t object_class_index = 0; /**< Class selected by this detector's current model policy. */
101constexpr float object_confidence_threshold = 0.6f; /**< Reject low-confidence boxes without invalidating the whole head. */
102/** @brief One accepted object in final still-image coordinates.
103 * @details The crop projection has already happened; consumers must not apply
104 * the sensor-to-JPEG transform to these pixel coordinates a second time. */
106 float confidence = 0; /**< Model confidence in [0, 1]. */
107 /** @var spottercam::BasicDetection::x
108 * @brief Left edge in JPEG pixels. */
109 /** @var spottercam::BasicDetection::y
110 * @brief Top edge in JPEG pixels. */
111 /** @var spottercam::BasicDetection::width
112 * @brief Positive accepted box width in JPEG pixels. */
113 int x = 0, y = 0, width = 0, height = 0; /**< Positive accepted box height in JPEG pixels. */
114};
115
116/** Per-frame detector output; invalid metadata is distinct from a valid empty
117 * result. */
119 bool valid =
120 false; /**< True only when the complete tensor contract validates. */
121 size_t count = 0; /**< Number of accepted object boxes, capped at five. */
122 std::array<BasicDetection, maximum_detections>
123 objects{}; /**< Bounded frame results. */
124};
125
126/** Decode one little-endian 32-bit integer from the driver's tensor-info byte
127 * array.
128 * @param data At least four readable bytes.
129 * @return The unsigned value represented by @p data[0..3]. */
130uint32_t read_u32(const uint8_t* data) {
131 return uint32_t(data[0]) | uint32_t(data[1]) << 8 | uint32_t(data[2]) << 16 |
132 uint32_t(data[3]) << 24;
133}
134
135/** Validate the model's four output tensors and project object boxes into the
136 * JPEG.
137 * @param tensor Interleaved boxes followed by scores, classes, and the
138 * detection count.
139 * @param info Driver CnnOutputTensorInfo bytes for this same camera request.
140 * @param crop Sensor crop reported in that request's ScalerCrop metadata.
141 * @param image Configured still-stream dimensions.
142 * @return Invalid by default; valid with zero or more boxes only after full
143 * validation.
144 * @details This is intentionally model-specific. Raw neural arrays cannot be
145 * treated as boxes until shape, integral count and coordinate assumptions hold. */
146BasicResult decode(imx500::Span<const float> tensor,
147 imx500::Span<const uint8_t> info,
148 libcamera::Rectangle crop, libcamera::Size image) {
150 if (!info.data() || !tensor.data() || info.size() < tensor_info_size ||
151 tensor.size() > maximum_tensor_elements ||
152 read_u32(info.data() + tensor_count_offset) !=
154 crop.x < 0 || crop.y < 0 || !crop.width || !crop.height ||
155 crop.width > sensor_width || crop.height > sensor_height ||
156 uint64_t(crop.x) + crop.width > sensor_width ||
157 uint64_t(crop.y) + crop.height > sensor_height || !image.width ||
158 !image.height || image.width > sensor_width ||
159 image.height > sensor_height)
160 return result;
161 std::array<uint32_t, expected_output_tensor_count> lengths{};
162 /* Validate every shape before indexing flattened values. Divide before
163 * multiplying so a corrupt extent cannot overflow its bounded element budget. */
164 for (size_t index = 0; index < lengths.size(); ++index) {
165 const uint8_t* record =
166 info.data() + first_tensor_record_offset + index * tensor_record_size;
167 lengths[index] = read_u32(record + tensor_record_length_offset);
168 uint32_t dimensions = read_u32(record + tensor_record_rank_offset);
169 if (dimensions == 0 || dimensions > maximum_tensor_dimensions ||
170 lengths[index] > maximum_tensor_elements)
171 return result;
172 uint32_t product = 1;
173 for (uint32_t dimension = 0; dimension < dimensions; ++dimension) {
174 size_t dimension_offset = tensor_record_dimensions_offset +
176 uint32_t size = uint32_t(record[dimension_offset]) |
177 uint32_t(record[dimension_offset + 1]) << 8;
178 if (size == 0 || product > maximum_tensor_elements / size) return result;
179 product *= size;
180 }
181 if (product != lengths[index]) return result;
182 }
183 uint32_t slots = lengths[0] / bbox_values_per_candidate;
184 if (slots == 0 || lengths[0] % bbox_values_per_candidate ||
185 lengths[1] != slots || lengths[2] != slots || lengths[3] != 1 ||
186 tensor.size() != values_per_candidate_with_score_and_class * slots + 1)
187 return result;
188 // Output layout stores four box coordinates, then scores, classes, and one
189 // total count.
190 float count = tensor[values_per_candidate_with_score_and_class * slots];
191 if (!std::isfinite(count) || count < 0 || count > slots ||
192 std::floor(count) != count)
193 return result;
194 result.valid = true;
195 /* Invalid individual candidates are omitted; a valid head with no accepted
196 * candidates still produces a valid empty result, not analysis_failed. */
197 for (size_t index = 0; index < static_cast<size_t>(count); ++index) {
198 size_t box_offset = bbox_values_per_candidate * index;
199 float score = tensor[score_values_before_candidates * slots + index];
200 float category = tensor[class_values_before_candidates * slots + index];
201 float left = tensor[box_offset], top = tensor[box_offset + 1];
202 float right = tensor[box_offset + 2], bottom = tensor[box_offset + 3];
203 if (category != object_class_index || !std::isfinite(score) ||
204 score < object_confidence_threshold || score > 1 ||
205 !std::isfinite(left) || !std::isfinite(top) || !std::isfinite(right) ||
206 !std::isfinite(bottom) || left < 0 || top < 0 || right <= left ||
207 bottom <= top || right > model_input_width ||
208 bottom > model_input_height)
209 continue;
210 size_t position = 0;
211 while (position < result.count && result.objects[position].confidence >= score) ++position;
212 if (position == maximum_detections) continue;
213 // Normalize model coordinates, map to sensor pixels, remove ScalerCrop
214 // origin, then scale to the JPEG.
215 auto project = [](float coordinate, unsigned int sensor, int start,
216 unsigned int extent, unsigned int output) {
217 double offset = std::clamp(
218 double(coordinate) / model_input_width * (sensor - 1) - start, 0.0,
219 double(extent));
220 return int(std::lround(offset * output / extent));
221 };
222 int x0 = project(left, sensor_width, crop.x, crop.width, image.width);
223 int x1 = project(right, sensor_width, crop.x, crop.width, image.width);
224 int y0 = project(top, sensor_height, crop.y, crop.height, image.height);
225 int y1 = project(bottom, sensor_height, crop.y, crop.height, image.height);
226 if (x1 <= x0 || y1 <= y0) continue;
227 if (result.count < maximum_detections) ++result.count;
228 for (size_t moved = result.count - 1; moved > position; --moved)
229 result.objects[moved] = result.objects[moved - 1];
230 result.objects[position] = {score, x0, y0, x1 - x0, y1 - y0};
231 }
232 return result;
233}
234
235
236/** @brief Interpret only the detector model's outputs from this retained exposure.
237 * @param frame Borrowed same-exposure tensors, crop and configured image size.
238 * @return Invalid without crop evidence, otherwise the validated detector result.
239 * @details A guessed full-sensor crop could put correct boxes in the wrong JPEG
240 * position, so missing geometry is a failed analysis rather than a default. */
242{
243 if (!frame.crop_valid) {
244 return {};
245 }
246 return decode(frame.tensor, frame.tensor_info, frame.crop, frame.image);
247}
248
249/** @brief Qualify startup from a valid detector head, including zero detections.
250 * @param frame Retained exposure supplied by the neutral camera worker.
251 * @return True when this model's decoder contract holds; not necessarily a hit. */
253{
254 return frame_result(frame).valid;
255}
256
257/** @brief Publish detector results, never LOOM features or navigation evidence.
258 * @param frame Borrowed exposure whose image/tensor identity is retained by a lease.
259 * @param filename New analysis destination selected by the camera publication owner.
260 * @return True after exclusive-create, flush, sync and close; false retains no partial output.
261 * @details Readiness can describe an earlier warm-up frame. Decode this frame
262 * again rather than reusing a previous result for newly captured pixels. */
263bool write_detections(const imx500::FrameView &frame, const char *filename)
264{
266 if (!result.valid) {
267 return false;
268 }
269 FILE *output = std::fopen(filename, "wx");
270 if (!output) {
271 return false;
272 }
273 std::fprintf(output,
274 "schema=USHER_OBJECTS_V2\nsequence=%llu\nsensor_timestamp_ns=%llu\n"
275 "image_width=%u\nimage_height=%u\ncount=%zu\n",
276 static_cast<unsigned long long>(frame.sequence),
277 static_cast<unsigned long long>(frame.sensor_timestamp_ns),
278 frame.image.width, frame.image.height, result.count);
279 for (size_t index = 0; index < result.count; ++index) {
280 const auto &box = result.objects[index];
281 std::fprintf(output,
282 "detection.%zu.name=vehicle\ndetection.%zu.confidence=%.6f\n"
283 "detection.%zu.x=%d\ndetection.%zu.y=%d\ndetection.%zu.width=%d\ndetection.%zu.height=%d\n",
284 index, index, double(box.confidence), index, box.x, index, box.y, index, box.width, index, box.height);
285 }
286 bool written = std::fflush(output) == 0 && !std::ferror(output) && fsync(fileno(output)) == 0;
287 if (std::fclose(output) != 0) {
288 written = false;
289 }
290 if (!written) {
291 unlink(filename);
292 }
293 return written;
294}
295
296} // namespace spottercam
297
298using namespace spottercam;
299#endif
300
301#ifndef SPOTTER_CAM_TEST
302namespace {
303/** @brief Assignment-level gates, deliberately separate from immutable model preprocessing. */
304struct OnnxDetectorOptions {
305 double threshold = 0.6;
306 unsigned category = 0, limit = 5, seen = 0;
307};
308
309/** @brief Reject duplicate assignment controls rather than letting INI field order decide detection policy. */
310bool detector_setting(void *context, const char *key, const char *value)
311{
312 auto &options = *static_cast<OnnxDetectorOptions *>(context);
313 unsigned bit;
314 if (!std::strcmp(key, "score_threshold")) bit = 1;
315 else if (!std::strcmp(key, "class_index")) bit = 2;
316 else if (!std::strcmp(key, "max_detections")) bit = 4;
317 else return false;
318 if (options.seen & bit) return false;
319 options.seen |= bit;
320 if (bit == 1) return ini_real(value, &options.threshold) && options.threshold >= 0 && options.threshold <= 1;
321 uint64_t number = 0;
322 if (!ini_uint(value, &number) || number > (bit == 2 ? 65535U : 64U) || (bit == 4 && !number)) return false;
323 if (bit == 2) options.category = static_cast<unsigned>(number);
324 else options.limit = static_cast<unsigned>(number);
325 return true;
326}
327
328/** @brief Read the declared numeric representation without assuming all exporters use float class/count tensors. */
329bool tensor_number(const onnx_tensor &tensor, size_t index, double &number)
330{
331 const size_t element = tensor.type == ONNX_INT64 ? 8 : 4;
332 if (index >= tensor.bytes / element) return false;
333 if (tensor.type == ONNX_FLOAT32) number = static_cast<const float *>(tensor.data)[index];
334 else if (tensor.type == ONNX_INT64) number = static_cast<double>(static_cast<const int64_t *>(tensor.data)[index]);
335 else if (tensor.type == ONNX_INT32) number = static_cast<const int32_t *>(tensor.data)[index];
336 else return false;
337 return std::isfinite(number);
338}
339
340/** @brief Qualify output layout and label policy before readiness, not on the first aircraft request. */
341bool validate_onnx_detector(void *context, const inference_context *network, char *error, size_t capacity)
342{
343 const auto &options = *static_cast<OnnxDetectorOptions *>(context);
344 const auto &model = network->model;
345 char label[64];
346 if (model.input_count != 1 || !model.image.channels ||
347 !inference_model_label(&model, options.category, label, sizeof(label))) {
348 std::snprintf(error, capacity, "Invalid spotter_boxes_xyxy_v1 tensor or label contract");
349 return false;
350 }
351 if (model.output_count == 1) {
352 const auto &output = model.outputs[0];
353 const int64_t channels = output.rank == 3 ? output.dimensions[1] : 0;
354 const int64_t slots = output.rank == 3 ? output.dimensions[2] : 0;
355 if (output.type != ONNX_FLOAT32 || output.rank != 3 || output.dimensions[0] != 1 ||
356 channels < 5 || channels > 68 || slots <= 0 || slots > 8400 ||
357 options.category >= static_cast<unsigned>(channels - 4) ||
358 output.bytes != static_cast<size_t>(channels) * static_cast<size_t>(slots) * sizeof(float)) {
359 std::snprintf(error, capacity, "Invalid spotter_boxes_xyxy_v1 tensor or label contract");
360 return false;
361 }
362 return true;
363 }
364 const auto integer_size = [](const onnx_tensor &tensor) -> size_t {
365 return tensor.type == ONNX_INT64 ? 8 : tensor.type == ONNX_INT32 || tensor.type == ONNX_FLOAT32 ? 4 : 0;
366 };
367 const size_t slots = model.outputs[0].bytes / (4 * sizeof(float));
368 const size_t classes = integer_size(model.outputs[2]), count = integer_size(model.outputs[3]);
369 if (model.output_count != 4 ||
370 model.outputs[0].type != ONNX_FLOAT32 || model.outputs[0].bytes % (4 * sizeof(float)) ||
371 !slots || slots > 4096 || model.outputs[1].type != ONNX_FLOAT32 || model.outputs[1].bytes != slots * sizeof(float) ||
372 !classes || model.outputs[2].bytes != slots * classes || !count || model.outputs[3].bytes != count) {
373 std::snprintf(error, capacity, "Invalid spotter_boxes_xyxy_v1 tensor or label contract");
374 return false;
375 }
376 return true;
377}
378
379struct DetectionCandidate {
380 double score;
381 int x, y, width, height;
382 double center_x, center_y;
383};
384
385static double box_iou(const DetectionCandidate &first, const DetectionCandidate &second)
386{
387 const int left = std::max(first.x, second.x);
388 const int top = std::max(first.y, second.y);
389 const int right = std::min(first.x + first.width, second.x + second.width);
390 const int bottom = std::min(first.y + first.height, second.y + second.height);
391 if (right <= left || bottom <= top) return 0.0;
392 const double intersection = static_cast<double>(right - left) * static_cast<double>(bottom - top);
393 const double first_area = static_cast<double>(first.width) * static_cast<double>(first.height);
394 const double second_area = static_cast<double>(second.width) * static_cast<double>(second.height);
395 const double union_area = first_area + second_area - intersection;
396 return union_area > 0.0 ? intersection / union_area : 0.0;
397}
398
399static void insert_detection(DetectionCandidate (&detections)[64], size_t &accepted,
400 unsigned limit, const DetectionCandidate &candidate, bool suppress_overlap)
401{
402 if (suppress_overlap) {
403 for (size_t index = 0; index < accepted; ++index) {
404 if (detections[index].score >= candidate.score && box_iou(detections[index], candidate) > 0.45) return;
405 }
406 size_t retained = 0;
407 for (size_t index = 0; index < accepted; ++index) {
408 if (detections[index].score >= candidate.score || box_iou(detections[index], candidate) <= 0.45) {
409 detections[retained++] = detections[index];
410 }
411 }
412 accepted = retained;
413 }
414 size_t position = 0;
415 while (position < accepted && detections[position].score >= candidate.score) ++position;
416 if (position >= limit) return;
417 if (accepted < limit) ++accepted;
418 for (size_t moved = accepted - 1; moved > position; --moved) detections[moved] = detections[moved - 1];
419 detections[position] = candidate;
420}
421
422/** @brief Rank bounded boxes and publish source/model identity so saved-picture results cannot attach to another JPEG. */
423bool write_onnx_detections(void *context, const inference_context *network,
424 const char *image, uint32_t sequence, char *error, size_t capacity)
425{
426 const auto &options = *static_cast<OnnxDetectorOptions *>(context);
427 const auto &model = network->model;
428 char label[64];
429 if (!inference_model_label(&model, options.category, label, sizeof(label))) return false;
430 DetectionCandidate detections[64]{};
431 size_t accepted = 0;
432 if (model.input_count == 1 && model.output_count == 1 && model.image.channels &&
433 model.outputs[0].type == ONNX_FLOAT32 && model.outputs[0].rank == 3 &&
434 model.outputs[0].dimensions[0] == 1 && model.outputs[0].dimensions[1] >= 5 &&
435 model.outputs[0].dimensions[1] <= 68 && model.outputs[0].dimensions[2] > 0 &&
436 model.outputs[0].dimensions[2] <= 8400 &&
437 options.category < static_cast<unsigned>(model.outputs[0].dimensions[1] - 4)) {
438 const size_t channels = static_cast<size_t>(model.outputs[0].dimensions[1]);
439 const size_t slots = static_cast<size_t>(model.outputs[0].dimensions[2]);
440 if (model.outputs[0].bytes != channels * slots * sizeof(float)) {
441 std::snprintf(error, capacity, "Invalid ONNX detection count or score shape");
442 return false;
443 }
444 const auto *values = static_cast<const float *>(model.outputs[0].data);
445 const double min_x = network->transform.left;
446 const double max_x = network->transform.left + network->transform.content_width;
447 const double min_y = network->transform.top;
448 const double max_y = network->transform.top + network->transform.content_height;
449 const double max_box_width = 0.30 * network->transform.input_width;
450 const double max_box_height = 0.30 * network->transform.input_height;
451 for (size_t index = 0; index < slots; ++index) {
452 const double cx = values[index], cy = values[slots + index];
453 const double width = values[2 * slots + index], height = values[3 * slots + index];
454 const double score = values[(4 + options.category) * slots + index];
455 if (!std::isfinite(cx) || !std::isfinite(cy) || !std::isfinite(width) ||
456 !std::isfinite(height) || !std::isfinite(score) ||
457 score < options.threshold || score > 1.0 || width <= 0.0 || height <= 0.0 ||
458 width > max_box_width || height > max_box_height ||
459 cx < min_x || cx > max_x || cy < min_y || cy > max_y) continue;
460 bool best_class = true;
461 for (size_t category = 0; category + 4 < channels; ++category) {
462 const double other = values[(4 + category) * slots + index];
463 if (!std::isfinite(other) || other > score) { best_class = false; break; }
464 }
465 if (!best_class) continue;
466 const double left = std::clamp(cx - 0.5 * width, min_x, max_x);
467 const double top = std::clamp(cy - 0.5 * height, min_y, max_y);
468 const double right = std::clamp(cx + 0.5 * width, min_x, max_x);
469 const double bottom = std::clamp(cy + 0.5 * height, min_y, max_y);
470 double x0, y0, x1, y1, center_x, center_y;
471 if (left >= right || top >= bottom ||
472 !inference_image_point(&network->transform, left, top, &x0, &y0) ||
473 !inference_image_point(&network->transform, right, bottom, &x1, &y1) ||
474 !inference_image_point(&network->transform, cx, cy, &center_x, &center_y)) continue;
475 const int start_x = static_cast<int>(std::lround(x0)), start_y = static_cast<int>(std::lround(y0));
476 const int end_x = static_cast<int>(std::lround(x1)), end_y = static_cast<int>(std::lround(y1));
477 if (end_x <= start_x || end_y <= start_y) continue;
478 insert_detection(detections, accepted, options.limit,
479 {score, start_x, start_y, end_x - start_x, end_y - start_y,
480 std::clamp(center_x, 0.0, double(network->transform.source_width - 1)),
481 std::clamp(center_y, 0.0, double(network->transform.source_height - 1))}, true);
482 }
483 } else {
484 if (model.input_count != 1 || model.output_count != 4 || !model.image.channels ||
485 model.outputs[0].type != ONNX_FLOAT32 || model.outputs[1].type != ONNX_FLOAT32 ||
486 model.outputs[0].bytes % (4 * sizeof(float))) {
487 std::snprintf(error, capacity, "spotter_boxes_xyxy_v1 requires boxes, scores, classes and count");
488 return false;
489 }
490 const size_t slots = model.outputs[0].bytes / (4 * sizeof(float));
491 double count = 0;
492 if (!slots || slots > 4096 || model.outputs[1].bytes != slots * sizeof(float) ||
493 !tensor_number(model.outputs[3], 0, count) || count < 0 || count > slots || std::floor(count) != count) {
494 std::snprintf(error, capacity, "Invalid ONNX detection count or score shape");
495 return false;
496 }
497 const auto *boxes = static_cast<const float *>(model.outputs[0].data);
498 for (size_t index = 0; index < static_cast<size_t>(count); ++index) {
499 double score = 0, category = 0;
500 if (!tensor_number(model.outputs[1], index, score) || !tensor_number(model.outputs[2], index, category) ||
501 category != options.category || score < options.threshold || score > 1) continue;
502 const double left = boxes[4 * index], top = boxes[4 * index + 1];
503 const double right = boxes[4 * index + 2], bottom = boxes[4 * index + 3];
504 double x0, y0, x1, y1;
505 if (left >= right || top >= bottom ||
506 !inference_image_point(&network->transform, left, top, &x0, &y0) ||
507 !inference_image_point(&network->transform, right, bottom, &x1, &y1)) continue;
508 const int start_x = static_cast<int>(std::lround(x0)), start_y = static_cast<int>(std::lround(y0));
509 const int end_x = static_cast<int>(std::lround(x1)), end_y = static_cast<int>(std::lround(y1));
510 if (end_x <= start_x || end_y <= start_y) continue;
511 insert_detection(detections, accepted, options.limit,
512 {score, start_x, start_y, end_x - start_x, end_y - start_y,
513 std::clamp((x0 + x1) / 2, 0.0, double(network->transform.source_width - 1)),
514 std::clamp((y0 + y1) / 2, 0.0, double(network->transform.source_height - 1))}, false);
515 }
516 }
517 char filename[INFERENCE_PATH_CAPACITY], source_digest[65];
518 const size_t length = std::strlen(image);
519 if (length < 4 || std::strcmp(image + length - 4, ".jpg") ||
520 !inference_file_sha256(image, source_digest)) {
521 std::snprintf(error, capacity, "Cannot identify inference source JPEG");
522 return false;
523 }
524 const int size = std::snprintf(filename, sizeof(filename), "%.*s.objects.ini", static_cast<int>(length - 4), image);
525 if (size < 0 || static_cast<size_t>(size) >= sizeof(filename)) return false;
526 FILE *output = std::fopen(filename, "wx");
527 if (!output) { std::snprintf(error, capacity, "Cannot exclusively create %s", filename); return false; }
528 std::fprintf(output, "schema=USHER_OBJECTS_V2\nsequence=%llu\nsensor_timestamp_ns=%llu\n"
529 "image_width=%u\nimage_height=%u\ncount=%zu\n"
530 "model_sha256=%s\nmodel_descriptor_sha256=%s\nimage_sha256=%s\n",
531 static_cast<unsigned long long>(network->capture_identity ? network->frame_sequence : sequence),
532 static_cast<unsigned long long>(network->sensor_timestamp_ns),
533 network->transform.source_width, network->transform.source_height, accepted,
534 model.graph_sha256, model.descriptor_sha256, source_digest);
535 for (size_t index = 0; index < accepted; ++index) {
536 const auto &box = detections[index];
537 std::fprintf(output, "detection.%zu.name=%s\ndetection.%zu.confidence=%.6f\n"
538 "detection.%zu.x=%d\ndetection.%zu.y=%d\ndetection.%zu.width=%d\ndetection.%zu.height=%d\n",
539 index, label, index, box.score, index, box.x, index, box.y, index, box.width, index, box.height);
540 std::fprintf(output, "detection.%zu.center_x=%.12g\ndetection.%zu.center_y=%.12g\n",
541 index, box.center_x, index, box.center_y);
542 }
543 bool written = std::fflush(output) == 0 && !std::ferror(output) && fsync(fileno(output)) == 0;
544 if (std::fclose(output)) written = false;
545 if (!written) { unlink(filename); std::snprintf(error, capacity, "Cannot publish ONNX detections"); }
546 return written;
547}
548}
549
550/** @brief Select simulation input using the common bounded settings parser.
551 * @details Only an absent model permits fabricated spotting. A present ONNX
552 * file is qualified by the normal shared analysis worker, never by this probe. */
553static int simulation_mode(int argc, char **argv)
554{
555 if (argc != 2 && (argc != 4 || std::strcmp(argv[2], "--settings"))) return 2;
556 char filename[INFERENCE_PATH_CAPACITY], error[2048];
557 const char *path = argc == 4 ? argv[3] : nullptr;
558 if (!path) {
559 if (!inference_settings_find("spottercam", "spotter_cam", filename, sizeof(filename))) {
560 std::puts("RANDOM settings_not_found");
561 return 0;
562 }
563 path = filename;
564 }
565 inference_settings settings;
566 OnnxDetectorOptions options;
568 if (!inference_settings_read(&settings, path, detector_setting, &options, error, sizeof(error))) {
569 std::fprintf(stderr, "spottercam: %s\n", error);
570 return 1;
571 }
572 if (!settings.model[0]) {
573 std::puts("RANDOM model_not_set");
574 return 0;
575 }
576 const char *suffix = std::strrchr(settings.model, '.');
577 if (settings.backend == INFERENCE_IMX500 && suffix && !std::strcmp(suffix, ".rpk")) {
578 const char *slash = std::strrchr(settings.model, '/');
579 if (slash) {
580 static const char *const candidates[] = {"vehicle_yolo11n_int8.onnx", "vehicle_yolo11n_fp32.onnx"};
581 const int directory_length = static_cast<int>(slash - settings.model);
582 for (const char *candidate_name : candidates) {
583 char candidate_path[INFERENCE_PATH_CAPACITY];
584 const int written = std::snprintf(candidate_path, sizeof(candidate_path), "%.*s/%s",
585 directory_length, settings.model, candidate_name);
586 struct stat candidate_status;
587 if (written > 0 && static_cast<size_t>(written) < sizeof(candidate_path) &&
588 !stat(candidate_path, &candidate_status) && S_ISREG(candidate_status.st_mode) &&
589 !access(candidate_path, R_OK)) {
590 std::puts("ONNX");
591 return 0;
592 }
593 }
594 }
595 std::puts("RANDOM rpk_requires_ai_camera");
596 return 0;
597 }
598 if (settings.backend != INFERENCE_ONNX || !suffix || std::strcmp(suffix, ".onnx")) {
599 std::fprintf(stderr, "spottercam: simulation requires an automatic or ONNX .onnx model\n");
600 return 1;
601 }
602 struct stat status;
603 if (stat(settings.model, &status)) {
604 if (errno == ENOENT || errno == ENOTDIR) {
605 std::puts("RANDOM onnx_model_missing");
606 return 0;
607 }
608 std::fprintf(stderr, "spottercam: cannot inspect ONNX model: %s\n", std::strerror(errno));
609 return 1;
610 }
611 if (!S_ISREG(status.st_mode) || access(settings.model, R_OK)) {
612 std::fprintf(stderr, "spottercam: ONNX model is not a readable regular file\n");
613 return 1;
614 }
615 std::puts("ONNX");
616 return 0;
617}
618
619/** @brief Project one delivered-image point with the shared camera/coverage geometry.
620 * @details Emits east/north offsets, not a new navigation command. The caller
621 * supplies the observed pose and retains ownership of the geographic datum. */
622static int project_ground(int argc, char **argv)
623{
624 if (argc != 13) return 2;
625 double values[10];
626 for (unsigned index = 0; index < 10; ++index)
627 if (!ini_real(argv[index + 3], &values[index])) return 2;
629 if (!usher_camera_profile_read(argv[2], &profile)) {
630 std::fprintf(stderr, "spottercam: invalid ground-projection camera profile\n");
631 return 1;
632 }
633 if (values[8] < 2 || values[8] > 4096 || values[9] < 2 || values[9] > 4096 ||
634 std::floor(values[8]) != values[8] || std::floor(values[9]) != values[9]) return 2;
635 auto &camera = profile.calibration;
636 const double scale_x = values[8] / camera.width, scale_y = values[9] / camera.height;
637 camera.fx *= scale_x;
638 camera.fy *= scale_y;
639 camera.cx = (camera.cx + 0.5) * scale_x - 0.5;
640 camera.cy = (camera.cy + 0.5) * scale_y - 0.5;
641 camera.width = static_cast<unsigned>(values[8]);
642 camera.height = static_cast<unsigned>(values[9]);
643 const coverage_pose pose{values[0], values[1], values[2], values[3], values[4], values[5], 0};
644 coverage_point offset;
645 if (!coverage_project_pixel(&camera, &pose, values[6], values[7], &offset)) {
646 std::fprintf(stderr, "spottercam: image point cannot reach the configured ground plane\n");
647 return 1;
648 }
649 std::printf("GROUND %.9f %.9f\n", offset.east, offset.north);
650 return 0;
651}
652
653/** @brief Publish a proposed slot and commit only after the transport confirms it.
654 * @details Coordinates retain the USHER ellipsoid reference; the transport owns
655 * conversion to its waypoint altitude datum. An absent or negative ACK leaves
656 * the native ranking unchanged. */
658 long long sequence = 0;
659 bool channel_failed = false;
660};
661
662/** @brief Read one bounded printable protocol line.
663 * @param[out] line Buffer for the line, newline and terminator.
664 * @param capacity Total buffer bytes.
665 * @param acknowledgement True to impose a deadline on the read.
666 * @return One for a complete line, zero for clean EOF, or -1 on failure.
667 * @details Keep one deadline across all bytes of an acknowledgement so a
668 * partially responsive peer cannot prolong a pending transaction indefinitely. */
669static int target_line(char *line, size_t capacity, bool acknowledgement)
670{
671 const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(4000);
672 size_t length = 0;
673 while (length + 1 < capacity) {
674 if (acknowledgement) {
675 const auto remaining = std::chrono::duration_cast<std::chrono::milliseconds>(
676 deadline - std::chrono::steady_clock::now()).count();
677 if (remaining <= 0) return -1;
678 pollfd input{STDIN_FILENO, POLLIN, 0};
679 const int ready = poll(&input, 1, static_cast<int>(remaining));
680 if (ready < 0 && errno == EINTR) continue;
681 if (ready <= 0) return -1;
682 }
683 const int character = std::fgetc(stdin);
684 if (character == EOF) return length ? -1 : 0;
685 if (character != '\n' && (character < 32 || character >= 127)) return -1;
686 line[length++] = static_cast<char>(character);
687 if (character == '\n') { line[length] = '\0'; return 1; }
688 }
689 return -1;
690}
691
692/** @brief Propose a target update and require its matching acknowledgement.
693 * @param[in,out] context Active TargetTransaction holding the correlation sequence.
694 * @param slot Proposed target slot.
695 * @param target Borrowed ranked target observation.
696 * @return True only if the peer acknowledged this transaction.
697 * @details Flush before reading the reply. Distinguish a missing or malformed
698 * line from a complete nonmatching response so the caller can detect channel failure. */
699static bool publish_target(void *context, unsigned slot, const spotter_target *target)
700{
701 auto &transaction = *static_cast<TargetTransaction *>(context);
702 const auto sequence = transaction.sequence;
703 if (std::printf("MOVE %lld %u %d %d %d %u\n", sequence, slot,
704 target->latitude, target->longitude, target->altitude_mm,
705 static_cast<unsigned>(target->score)) < 0 || std::fflush(stdout)) return false;
706 char reply[80], expected[80];
707 std::snprintf(expected, sizeof(expected), "ACK %lld\n", sequence);
708 const int received = target_line(reply, sizeof(reply), true);
709 if (received != 1) transaction.channel_failed = true;
710 return received == 1 && !std::strcmp(reply, expected);
711}
712
713/** @brief Run a bounded, model-independent geographic target stream.
714 * @return Zero on orderly EOF, two for malformed/out-of-order input, one for I/O failure.
715 * @details OBS sequence latitude longitude ellipsoid_mm score proposes one
716 * observation. MOVE awaits ACK sequence; OK commits, SKIP retains existing slots.
717 * Restarting the worker clears all five slots without moving any FC waypoint. */
718static int target_server()
719{
720 if (std::setvbuf(stdin, nullptr, _IONBF, 0)) return 1;
721 spotter_targets targets{};
722 long long previous = 0;
724 char line[192];
725 std::puts("READY SENSORAIA_TARGETS_V1");
726 if (std::fflush(stdout)) return 1;
727 int line_status;
728 while ((line_status = target_line(line, sizeof(line), false)) > 0) {
729 if (!std::strchr(line, '\n') || std::strncmp(line, "OBS ", 4)) return 2;
730 char *cursor = line + 4;
731 long long values[5]{};
732 for (auto &value : values) {
733 char *end = nullptr;
734 errno = 0;
735 value = std::strtoll(cursor, &end, 10);
736 if (errno || end == cursor || (*end != ' ' && *end != '\n')) return 2;
737 cursor = end;
738 while (*cursor == ' ') ++cursor;
739 }
740 if (std::strcmp(cursor, "\n") || values[0] <= previous || values[0] > UINT32_MAX ||
741 values[1] < -900000000 || values[1] > 900000000 ||
742 values[2] < -1800000000 || values[2] > 1800000000 ||
743 values[3] < INT32_MIN || values[3] > INT32_MAX || values[4] < 0 || values[4] > 1000) return 2;
744 previous = values[0];
745 transaction.sequence = previous;
746 const spotter_target observation{static_cast<int32_t>(values[1]), static_cast<int32_t>(values[2]),
747 static_cast<int32_t>(values[3]), static_cast<uint16_t>(values[4]), true};
748 const int slot = spotter_targets_offer(&targets, &observation, publish_target, &transaction);
749 if (transaction.channel_failed) return 1;
750 if (slot < 0) std::printf("SKIP %lld\n", previous);
751 else std::printf("OK %lld %d\n", previous, slot);
752 if (std::fflush(stdout)) return 1;
753 }
754 return line_status < 0 ? 2 : std::ferror(stdin) ? 1 : 0;
755}
756
757/** @brief Select detector-specific policy, then run neutral capture mechanics.
758 * @param argc Command-line token count.
759 * @param argv Version or probe/capture/serve arguments.
760 * @return Zero on success, two for syntax errors, one for worker failure.
761 * @details The explicit .objects.ini callback keeps object interpretation out
762 * of the shared camera and out of LOOM's independently linked executable. */
763int main(int argc, char **argv)
764{
765 if (argc == 2 && !std::strcmp(argv[1], "--target-server")) return target_server();
766 if (argc >= 2 && !std::strcmp(argv[1], "--simulation-mode")) return simulation_mode(argc, argv);
767 if (argc >= 2 && !std::strcmp(argv[1], "--project-ground")) return project_ground(argc, argv);
768 if (argc == 2 && !std::strcmp(argv[1], "--help")) {
769 std::puts(SPOTTERCAM_BUILD_VERSION);
770 std::puts("Usage: spottercam --analyze FILE.jpg | --analyze-server | --check-model [--settings FILE]\n"
771 #ifndef SENSORAIA_INFERENCE_ONLY
772 " spottercam --capture --settings FILE /absolute/photo.jpg\n"
773 " spottercam --serve --settings FILE WIDTH HEIGHT\n"
774 " spottercam --photo-only [--probe | --capture /absolute/photo.jpg | --serve WIDTH HEIGHT]\n"
775 #endif
776 " spottercam --target-server\n"
777 " spottercam --simulation-mode [--settings FILE]\n"
778 " spottercam --project-ground PROFILE LAT LON AGL ROLL PITCH YAW X Y WIDTH HEIGHT\n"
779 " spottercam --probe MODEL.rpk | --version\n"
780 "Picture analysis accepts --sequence N; settings select the model/backend.");
781 return 0;
782 }
783 OnnxDetectorOptions options;
784 const inference_image_processor onnx_processor{"spottercam", "spotter_cam", "spotter_boxes_xyxy_v1",
785 detector_setting, &options, write_onnx_detections, validate_onnx_detector, ".objects.ini"};
786 const int analyzed = inference_worker_cli(argc, argv, &onnx_processor);
787 if (analyzed >= 0) return analyzed;
788 if (argc == 2 && std::strcmp(argv[1], "--version") == 0) {
789 std::puts(SPOTTERCAM_BUILD_VERSION);
790 return 0;
791 }
792#ifdef SENSORAIA_INFERENCE_ONLY
793 std::fprintf(stderr, "Usage: spottercam --analyze FILE.jpg | --analyze-server | --check-model [--settings FILE]\n");
794 return 2;
795#else
796 if (argc > 1 && !std::strcmp(argv[1], "--photo-only")) {
797 return imx500::run_photo_worker(argc - 1, argv + 1, "spottercam");
798 }
799 const imx500::FrameProcessor processor{".objects.ini", detector_ready, write_detections};
800 const int configured = inference_capture_cli(argc, argv, onnx_processor, processor);
801 if (configured >= 0) return configured;
802 if (argc < 3 || (std::strcmp(argv[1], "--probe") != 0
803 && std::strcmp(argv[1], "--serve") != 0
804 && std::strcmp(argv[1], "--capture") != 0)) {
805 std::fprintf(stderr,
806 "Usage: spottercam --probe MODEL.rpk\n"
807 " spottercam --serve MODEL.rpk WIDTH HEIGHT\n"
808 " spottercam --capture MODEL.rpk /absolute/photo.jpg\n"
809 " spottercam --analyze FILE.jpg --settings FILE [--sequence N]\n"
810 " spottercam --analyze-server --settings FILE\n"
811 " spottercam --check-model --settings FILE\n"
812 " spottercam --version\n");
813 return 2;
814 }
815 return imx500::run_worker(argc, argv, processor, "spottercam");
816#endif
817}
818#endif
static bool ini_uint(const char *text, uint64_t *number)
Parse digits-only uint64; overflow and signs are rejected.
Definition bounded_ini.h:52
static bool ini_real(const char *text, double *number)
Parse finite decimal/exponent notation, rejecting range errors and suffixes.
Definition bounded_ini.h:67
bool usher_camera_profile_read(const char *filename, struct usher_camera_profile *profile)
Read a bounded PANGEA_CAMERA_V1 key=value calibration file.
Public C API for reading PANGEA camera calibration profiles.
static bool project(const union dc_shot_union *shot, unsigned camera_id, double uncertainty, struct coverage_candidate *candidate)
Convert FC units and estimate geometric detail using this camera's calibration.
static unsigned capacity[COVERAGE_CAMERAS]
size_t size
Definition chdk_pipe.c:143
static bool transaction(struct transport *transport, uint16_t operation, const uint32_t *parameters, size_t parameter_count, const uint8_t *outgoing, size_t outgoing_size, uint8_t *incoming, size_t capacity, FILE *file, struct response *response)
Perform command, optional data, and response phases for one PTP operation.
Definition chdkbridge.c:329
bool coverage_project_pixel(const struct coverage_camera *camera, const struct coverage_pose *pose, double column, double row, struct coverage_point *offset)
Project an image pixel onto the same ground plane as the coverage footprint.
static bool start(uint32_t session)
Admit a nonzero session and discard correlation from the previous one.
static int record(const union dc_shot_union *shot)
Retrieve a point and admit a new observation only when its credit is free.
static bool ready
static struct inference_context network
Neutral IMX500 frame ownership, JPEG publication and worker protocol.
Shared IMX500 tensor-info wire layout and bounded decoding policy.
#define IMX500_TENSOR_RANK_OFFSET
Shape rank offset within a record.
#define IMX500_TENSOR_DIMENSION_BYTES
Each extent is a little-endian unsigned 16-bit value.
#define IMX500_TENSOR_DIMENSIONS_OFFSET
First shape extent follows the two 32-bit fields.
#define IMX500_TENSOR_COUNT_OFFSET
Little-endian 32-bit tensor count starts after the fixed header.
#define IMX500_TENSOR_ELEMENT_LIMIT
Sensoraia's accepted element budget, not a claim about every RPK model.
#define IMX500_TENSOR_INFO_BYTES
Full accessible metadata required before following record offsets.
#define IMX500_TENSOR_HEADER_BYTES
Driver metadata header preceding the tensor count; not an RPK feature schema.
#define IMX500_TENSOR_FIRST_RECORD_OFFSET
First record starts after the count, keeping offset arithmetic in one place.
#define IMX500_TENSOR_LENGTH_OFFSET
Element count offset within a record, distinct from its byte length.
#define IMX500_TENSOR_MAX_RANK
Fixed shape capacity in the driver ABI; reject greater ranks before indexing.
#define IMX500_TENSOR_RECORD_BYTES
One record contains length, rank and sixteen 16-bit shape extents.
int inference_capture_cli(int argc, char **argv, const inference_image_processor &processor, const imx500::FrameProcessor &sensor_processor)
Dispatch configured RPK/ONNX capture while preserving one physical camera owner.
Settings-driven capture bridge; neutral camera mechanics never interpret neural outputs.
bool inference_image_point(const struct inference_image_transform *transform, double input_x, double input_y, double *source_x, double *source_y)
Map a model-input point back to source pixels, rejecting letterbox-only coordinates.
bool inference_file_sha256(const char *filename, char digest[65])
Hash a stable nonempty regular file using bounded streaming scratch.
bool inference_model_label(const struct inference_model *model, unsigned category, char *label, size_t capacity)
Resolve one model-owned label without retaining a pointer into a mutable list.
bool inference_settings_find(const char *application, const char *module, char *filename, size_t capacity)
Discover application_settings.ini in adjacent, development-module, then installed-share order.
bool inference_settings_read(struct inference_settings *settings, const char *filename, ini_field_handler extra, void *context, char *error, size_t capacity)
Parse one flat INI, delegate application keys and resolve paths against the selected file.
void inference_settings_init(struct inference_settings *settings, enum inference_backend backend)
Reset storage and select conservative thread/timeout defaults.
#define INFERENCE_PATH_CAPACITY
@ INFERENCE_AUTO
@ INFERENCE_ONNX
@ INFERENCE_IMX500
int inference_worker_cli(int argc, char **argv, const struct inference_image_processor *processor)
Dispatch one-shot analysis, model checks or the persistent ANALYZE protocol.
Warm saved-picture processing without acquiring a camera or interpreting CAM results.
struct jpeg_error_mgr error
Definition lwir_image.c:60
uint8_t frame[LWIR_MAX_FRAME_BYTES]
Definition lwir_mock.c:58
static struct usher_camera_profile profile
static struct spotter_detections detections
int run_worker(int argc, char **argv, const FrameProcessor &processor, const char *application)
Run the shared probe/capture/READY-SHOT-OK worker with supplied model policy.
int run_photo_worker(int argc, char **argv, const char *application)
Run photo-only probe, capture or serve without model loading or inference.
constexpr unsigned sensor_height
Physical IMX500 array height; model input dimensions are separate policy.
constexpr unsigned sensor_width
Physical IMX500 array width, used to reject an unexpected sensor geometry.
double number(const std::string &text, const std::string &name)
Read a complete finite numeric route field.
Definition route.h:141
constexpr uint32_t bbox_values_per_candidate
constexpr size_t tensor_record_size
constexpr size_t tensor_record_dimensions_offset
constexpr uint32_t maximum_tensor_elements
constexpr size_t tensor_record_dimension_bytes
constexpr unsigned int model_input_width
constexpr uint32_t expected_output_tensor_count
constexpr size_t tensor_record_length_offset
constexpr uint32_t class_values_before_candidates
constexpr unsigned int sensor_height
Sensor-space height, separate from model and encoded-image dimensions.
constexpr uint32_t values_per_candidate_with_score_and_class
constexpr size_t tensor_info_header_size
constexpr size_t tensor_count_offset
constexpr uint32_t score_values_before_candidates
constexpr size_t tensor_record_rank_offset
bool detector_ready(const imx500::FrameView &frame)
Qualify startup from a valid detector head, including zero detections.
constexpr unsigned int model_input_height
This detection head's input height; LOOM does not reuse its box semantics.
constexpr float object_confidence_threshold
constexpr uint32_t maximum_tensor_dimensions
bool write_detections(const imx500::FrameView &frame, const char *filename)
Publish detector results, never LOOM features or navigation evidence.
constexpr uint32_t object_class_index
uint32_t read_u32(const uint8_t *data)
constexpr size_t first_tensor_record_offset
BasicResult decode(imx500::Span< const float > tensor, imx500::Span< const uint8_t > info, libcamera::Rectangle crop, libcamera::Size image)
constexpr unsigned int sensor_width
constexpr size_t tensor_info_size
constexpr size_t maximum_detections
BasicResult frame_result(const imx500::FrameView &frame)
Interpret only the detector model's outputs from this retained exposure.
@ ONNX_INT32
@ ONNX_FLOAT32
@ ONNX_INT64
static size_t count
Definition pose_log.c:79
static uint64_t accepted
Definition pose_log.c:81
static FILE * output
Definition pose_log.c:77
static int simulation_mode(int argc, char **argv)
Select simulation input using the common bounded settings parser.
static int target_server()
Run a bounded, model-independent geographic target stream.
int main(int argc, char **argv)
Select detector-specific policy, then run neutral capture mechanics.
static bool publish_target(void *context, unsigned slot, const spotter_target *target)
Propose a target update and require its matching acknowledgement.
static int project_ground(int argc, char **argv)
Project one delivered-image point with the shared camera/coverage geometry.
static int target_line(char *line, size_t capacity, bool acknowledgement)
Read one bounded printable protocol line.
int spotter_targets_offer(struct spotter_targets *targets, const struct spotter_target *observation, bool(*apply)(void *, unsigned, const struct spotter_target *), void *context)
Admit a target only after its owner's coordinate application succeeds.
Five ranked geographic targets, independent of navigation and camera transport.
#define SPOTTERCAM_BUILD_VERSION
Definition version.h:75
Publish a proposed slot and commit only after the transport confirms it.
Local ground coordinates in metres, east and north of the projection origin.
double north
Metres north of the shared local geographic reference.
double east
Metres east of the shared local geographic reference.
Pose estimate and its positional margin for a single observation.
Stack-owned model-specific operations; no dynamic plugin allocation.
Borrowed same-exposure evidence, without object or navigation semantics.
Independent, noncopyable model owner; mapped tensor buffers and session are reused between jobs.
Borrowed module callbacks; the worker serializes calls and retains no per-request pixel pointers.
Per-application configuration; all resolved paths belong to this caller-owned value.
enum inference_backend backend
char model[INFERENCE_PATH_CAPACITY]
Named concrete tensor view; its aligned backing storage must outlive the session.
enum onnx_element_type type
Validated capture and reporting policy, fixed before the sample loop.
Definition earcam.c:137
Geographic observation in the shared USHER point units.
Caller-owned fixed storage; slot indices stay stable while scores improve.
One accepted object in final still-image coordinates.
int x
Left edge in JPEG pixels.
int width
Positive accepted box width in JPEG pixels.
int y
Top edge in JPEG pixels.
std::array< BasicDetection, maximum_detections > objects
One measured camera calibration loaded from the flat PANGEA profile format.
static struct camera_backend camera
Definition usher.c:521
struct usher_control_result result
Definition usher.c:377
struct captured_image image
Definition usher.c:371