Loading...
Searching...
No Matches
spotter_cam.cpp
Go to the documentation of this file.
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. */
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. */
309/** @brief Reject duplicate assignment controls rather than letting INI field order decide detection policy. */
320 if (bit == 1) return ini_real(value, &options.threshold) && options.threshold >= 0 && options.threshold <= 1;
322 if (!ini_uint(value, &number) || number > (bit == 2 ? 65535U : 64U) || (bit == 4 && !number)) return false;
328/** @brief Read the declared numeric representation without assuming all exporters use float class/count tensors. */
334 else if (tensor.type == ONNX_INT64) number = static_cast<double>(static_cast<const int64_t *>(tensor.data)[index]);
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)
365 return tensor.type == ONNX_INT64 ? 8 : tensor.type == ONNX_INT32 || tensor.type == ONNX_FLOAT32 ? 4 : 0;
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) {
392 const double intersection = static_cast<double>(right - left) * static_cast<double>(bottom - top);
394 const double second_area = static_cast<double>(second.width) * static_cast<double>(second.height);
404 if (detections[index].score >= candidate.score && box_iou(detections[index], candidate) > 0.45) return;
408 if (detections[index].score >= candidate.score || box_iou(detections[index], candidate) <= 0.45) {
418 for (size_t moved = accepted - 1; moved > position; --moved) detections[moved] = detections[moved - 1];
422/** @brief Rank bounded boxes and publish source/model identity so saved-picture results cannot attach to another JPEG. */
475 const int start_x = static_cast<int>(std::lround(x0)), start_y = static_cast<int>(std::lround(y0));
487 std::snprintf(error, capacity, "spotter_boxes_xyxy_v1 requires boxes, scores, classes and count");
493 !tensor_number(model.outputs[3], 0, count) || count < 0 || count > slots || std::floor(count) != count) {
500 if (!tensor_number(model.outputs[1], index, score) || !tensor_number(model.outputs[2], index, category) ||
508 const int start_x = static_cast<int>(std::lround(x0)), start_y = static_cast<int>(std::lround(y0));
524 const int size = std::snprintf(filename, sizeof(filename), "%.*s.objects.ini", static_cast<int>(length - 4), image);
527 if (!output) { std::snprintf(error, capacity, "Cannot exclusively create %s", filename); return false; }
531 static_cast<unsigned long long>(network->capture_identity ? network->frame_sequence : sequence),
539 index, label, index, box.score, index, box.x, index, box.y, index, box.width, index, box.height);
545 if (!written) { unlink(filename); std::snprintf(error, capacity, "Cannot publish ONNX detections"); }
568 if (!inference_settings_read(&settings, path, detector_setting, &options, error, sizeof(error))) {
746 const spotter_target observation{static_cast<int32_t>(values[1]), static_cast<int32_t>(values[2]),
766 if (argc >= 2 && !std::strcmp(argv[1], "--simulation-mode")) return simulation_mode(argc, argv);
770 std::puts("Usage: spottercam --analyze FILE.jpg | --analyze-server | --check-model [--settings FILE]\n"
784 const inference_image_processor onnx_processor{"spottercam", "spotter_cam", "spotter_boxes_xyxy_v1",
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.
Definition camera_profile.c:132
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.
Definition capture_arbiter.c:173
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.
Definition coverage_scheduler.c:88
static bool start(uint32_t session)
Admit a nonzero session and discard correlation from the previous one.
Definition dipla_camera_backend.c:170
static int record(const union dc_shot_union *shot)
Retrieve a point and admit a new observation only when its credit is free.
Definition dipla_camera_backend.c:206
Neutral IMX500 frame ownership, JPEG publication and worker protocol.
Shared IMX500 tensor-info wire layout and bounded decoding policy.
#define IMX500_TENSOR_DIMENSION_BYTES
Each extent is a little-endian unsigned 16-bit value.
Definition imx500_tensor.h:43
#define IMX500_TENSOR_DIMENSIONS_OFFSET
First shape extent follows the two 32-bit fields.
Definition imx500_tensor.h:41
#define IMX500_TENSOR_COUNT_OFFSET
Little-endian 32-bit tensor count starts after the fixed header.
Definition imx500_tensor.h:31
#define IMX500_TENSOR_ELEMENT_LIMIT
Sensoraia's accepted element budget, not a claim about every RPK model.
Definition imx500_tensor.h:52
#define IMX500_TENSOR_INFO_BYTES
Full accessible metadata required before following record offsets.
Definition imx500_tensor.h:49
#define IMX500_TENSOR_HEADER_BYTES
Driver metadata header preceding the tensor count; not an RPK feature schema.
Definition imx500_tensor.h:29
#define IMX500_TENSOR_FIRST_RECORD_OFFSET
First record starts after the count, keeping offset arithmetic in one place.
Definition imx500_tensor.h:33
#define IMX500_TENSOR_LENGTH_OFFSET
Element count offset within a record, distinct from its byte length.
Definition imx500_tensor.h:37
#define IMX500_TENSOR_MAX_RANK
Fixed shape capacity in the driver ABI; reject greater ranks before indexing.
Definition imx500_tensor.h:45
#define IMX500_TENSOR_RECORD_BYTES
One record contains length, rank and sixteen 16-bit shape extents.
Definition imx500_tensor.h:35
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.
Definition inference_capture.cpp:110
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.
Definition inference_image.c:154
bool inference_file_sha256(const char *filename, char digest[65])
Hash a stable nonempty regular file using bounded streaming scratch.
Definition inference_model.c:41
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.
Definition inference_model.c:237
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.
Definition inference_settings.c:202
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.
Definition inference_settings.c:158
void inference_settings_init(struct inference_settings *settings, enum inference_backend backend)
Reset storage and select conservative thread/timeout defaults.
Definition inference_settings.c:28
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.
Definition inference_worker.c:75
Warm saved-picture processing without acquiring a camera or interpreting CAM results.
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.
Definition imx500_camera.cpp:817
int run_photo_worker(int argc, char **argv, const char *application)
Run photo-only probe, capture or serve without model loading or inference.
Definition imx500_camera.cpp:931
constexpr unsigned sensor_height
Physical IMX500 array height; model input dimensions are separate policy.
Definition imx500_camera.hpp:60
constexpr unsigned sensor_width
Physical IMX500 array width, used to reject an unexpected sensor geometry.
Definition imx500_camera.hpp:58
double number(const std::string &text, const std::string &name)
Read a complete finite numeric route field.
Definition route.h:141
Definition spotter_cam.cpp:52
constexpr uint32_t bbox_values_per_candidate
Definition spotter_cam.cpp:66
constexpr size_t tensor_record_dimensions_offset
Definition spotter_cam.cpp:85
constexpr uint32_t maximum_tensor_elements
Definition spotter_cam.cpp:72
constexpr size_t tensor_record_dimension_bytes
Definition spotter_cam.cpp:87
constexpr uint32_t expected_output_tensor_count
Definition spotter_cam.cpp:65
constexpr size_t tensor_record_length_offset
Definition spotter_cam.cpp:91
constexpr uint32_t class_values_before_candidates
Definition spotter_cam.cpp:68
constexpr unsigned int sensor_height
Sensor-space height, separate from model and encoded-image dimensions.
Definition spotter_cam.cpp:58
constexpr uint32_t values_per_candidate_with_score_and_class
Definition spotter_cam.cpp:69
constexpr size_t tensor_info_header_size
Definition spotter_cam.cpp:78
constexpr uint32_t score_values_before_candidates
Definition spotter_cam.cpp:67
constexpr size_t tensor_record_rank_offset
Definition spotter_cam.cpp:89
bool detector_ready(const imx500::FrameView &frame)
Qualify startup from a valid detector head, including zero detections.
Definition spotter_cam.cpp:252
constexpr unsigned int model_input_height
This detection head's input height; LOOM does not reuse its box semantics.
Definition spotter_cam.cpp:62
constexpr float object_confidence_threshold
Definition spotter_cam.cpp:101
constexpr uint32_t maximum_tensor_dimensions
Definition spotter_cam.cpp:75
bool write_detections(const imx500::FrameView &frame, const char *filename)
Publish detector results, never LOOM features or navigation evidence.
Definition spotter_cam.cpp:263
constexpr size_t first_tensor_record_offset
Definition spotter_cam.cpp:81
BasicResult decode(imx500::Span< const float > tensor, imx500::Span< const uint8_t > info, libcamera::Rectangle crop, libcamera::Size image)
Definition spotter_cam.cpp:146
BasicResult frame_result(const imx500::FrameView &frame)
Interpret only the detector model's outputs from this retained exposure.
Definition spotter_cam.cpp:241
static int simulation_mode(int argc, char **argv)
Select simulation input using the common bounded settings parser.
Definition spotter_cam.cpp:553
static int target_server()
Run a bounded, model-independent geographic target stream.
Definition spotter_cam.cpp:718
int main(int argc, char **argv)
Select detector-specific policy, then run neutral capture mechanics.
Definition spotter_cam.cpp:763
static bool publish_target(void *context, unsigned slot, const spotter_target *target)
Propose a target update and require its matching acknowledgement.
Definition spotter_cam.cpp:699
static int project_ground(int argc, char **argv)
Project one delivered-image point with the shared camera/coverage geometry.
Definition spotter_cam.cpp:622
static int target_line(char *line, size_t capacity, bool acknowledgement)
Read one bounded printable protocol line.
Definition spotter_cam.cpp:669
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.
Definition spotter_targets.c:31
Five ranked geographic targets, independent of navigation and camera transport.
Publish a proposed slot and commit only after the transport confirms it.
Definition spotter_cam.cpp:657
Local ground coordinates in metres, east and north of the projection origin.
Definition coverage_scheduler.h:73
double north
Metres north of the shared local geographic reference.
Definition coverage_scheduler.h:73
Pose estimate and its positional margin for a single observation.
Definition coverage_scheduler.h:59
Stack-owned model-specific operations; no dynamic plugin allocation.
Definition imx500_camera.hpp:109
Borrowed same-exposure evidence, without object or navigation semantics.
Definition imx500_camera.hpp:77
Independent, noncopyable model owner; mapped tensor buffers and session are reused between jobs.
Definition inference_model.h:43
Borrowed module callbacks; the worker serializes calls and retains no per-request pixel pointers.
Definition inference_worker.h:32
Per-application configuration; all resolved paths belong to this caller-owned value.
Definition inference_settings.h:39
Named concrete tensor view; its aligned backing storage must outlive the session.
Definition onnx_session.h:44
Geographic observation in the shared USHER point units.
Definition spotter_targets.h:33
Caller-owned fixed storage; slot indices stay stable while scores improve.
Definition spotter_targets.h:41
One accepted object in final still-image coordinates.
Definition spotter_cam.cpp:105
Definition spotter_cam.cpp:118
std::array< BasicDetection, maximum_detections > objects
Definition spotter_cam.cpp:123
One measured camera calibration loaded from the flat PANGEA profile format.
Definition camera_profile.h:41