Loading...
Searching...
No Matches
lwir_inference.c
Go to the documentation of this file.
20 * @details A class probability is neither a temperature correction nor a geographic hotspot result.
35static struct inference_context network; ///< The single open classifier; storage != NULL means open.
36static unsigned char thermal_plane[LWIR_MAX_WIDTH * LWIR_MAX_HEIGHT * 2]; ///< Kelvin*64 samples for radiometric models.
49bool lwir_inference_open(const struct inference_settings *settings, double threshold, unsigned category,
57 if (!inference_context_open(&network, settings, "lwir_classifier_v1", error, capacity)) return false;
58 if (network.model.input_count != 1 || network.model.output_count != 1 || !network.model.image.channels ||
59 network.model.outputs[0].type != ONNX_FLOAT32 || network.model.outputs[0].bytes / sizeof(float) > 4096 ||
83bool lwir_inference_image(const char *filename, unsigned long long sequence, char *error, size_t capacity)
97 /* A display JPEG cannot replace missing physical temperature samples, even if it looks thermal. */
99 if (lwir_read_temperature_layer(filename, thermal_plane, sizeof(thermal_plane), &width, &height, &synthetic) != 1) {
100 snprintf(error, capacity, "Model requires a valid radiometric temperature plane; display pixels are not temperatures");
103 const struct inference_image image = {.planes = {thermal_plane}, .lengths = {(size_t)width * height * 2},
104 .strides = {(size_t)width * 2}, .width = width, .height = height, .format = INFERENCE_KELVIN64};
119 const int count = snprintf(output_path, sizeof(output_path), "%.*s.lwir.ini", (int)(length - 4), filename);
121 /* Exclusive creation prevents a retry from silently replacing evidence for an earlier input. */
123 if (!output) { snprintf(error, capacity, "Cannot exclusively create LWIR classifier evidence: %s", output_path); return false; }
138/** @brief Release the classifier; harmless when not open. Threshold/category are reset by the next open. */
bool inference_jpeg_prepare(struct inference_context *context, const char *filename, char *error, size_t capacity)
Stream a JPEG into an open context's single declared image input.
Definition inference_jpeg.c:167
Bounded JPEG-to-tensor preparation without running the graph or modifying the input file.
bool inference_context_run(struct inference_context *context, char *error, size_t capacity)
Run the currently prepared tensors using the context's timeout policy.
Definition inference_model.c:346
bool inference_context_open(struct inference_context *context, const struct inference_settings *settings, const char *adapter, char *error, size_t capacity)
Verify a bundle, map bounded tensors and bind one warm session.
Definition inference_model.c:277
bool inference_context_prepare_image(struct inference_context *context, const struct inference_image *image, char *error, size_t capacity)
Prepare a single image input without running the model, so camera leases can be released first.
Definition inference_model.c:361
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
void inference_context_close(struct inference_context *context)
Release the session before unmapping its borrowed tensor storage.
Definition inference_model.c:373
int lwir_read_temperature_layer(const char *filename, uint8_t *destination, size_t capacity, unsigned *width, unsigned *height, bool *synthetic)
Open filename safely and read the layer only; see lwir_container.h.
Definition lwir_container.c:272
Exact thermal evidence in JPEG containers, independent of analysis.
Native frame arithmetic and camera measurements; no codec or flight dependencies.
static unsigned char thermal_plane[LWIR_MAX_WIDTH *LWIR_MAX_HEIGHT *2]
Kelvin*64 samples for radiometric models.
Definition lwir_inference.c:36
void lwir_inference_close(void)
Release the classifier; harmless when not open. Threshold/category are reset by the next open.
Definition lwir_inference.c:139
bool lwir_inference_image(const char *filename, unsigned long long sequence, char *error, size_t capacity)
Classify one saved photo and publish its evidence sidecar.
Definition lwir_inference.c:83
bool lwir_inference_open(const struct inference_settings *settings, double threshold, unsigned category, char *error, size_t capacity)
Open and qualify the LWIR classifier (see lwir_inference.h).
Definition lwir_inference.c:49
Optional serialized LWIR model adapter, separate from USB capture and calibration.
Independent, noncopyable model owner; mapped tensor buffers and session are reused between jobs.
Definition inference_model.h:43
Borrowed immutable planes; lengths/strides prove all addressed rows are available.
Definition inference_image.h:37
Per-application configuration; all resolved paths belong to this caller-owned value.
Definition inference_settings.h:39