Loading...
Searching...
No Matches
lwir_analysis.c
Go to the documentation of this file.
165 while (offset < description.size && description.data[offset] != ';' && description.data[offset] != 0) ++offset;
175 while (key_start < key_end && (description.data[key_start] == ' ' || description.data[key_start] == '\t')) ++key_start;
176 while (key_end > key_start && (description.data[key_end - 1] == ' ' || description.data[key_end - 1] == '\t')) --key_end;
182 while (value_length && (value[value_length - 1] == ' ' || value[value_length - 1] == '\t')) --value_length;
183 static const char *const names[] = {"lat_deg", "lon_deg", "alt_m", "roll_deg", "pitch_deg", "yaw_deg",
184 "altitude_agl_m", "groundalt_m", "pose_uncertainty_m", "capture_pose_synchronized", "observation_time_kind"};
201 fields.exposure_interval = (value_length == 24 && !memcmp(value, "sensor_exposure_interval", 24))
223 const unsigned required = (1U << 0) | (1U << 1) | (1U << 2) | (1U << 3) | (1U << 4) | (1U << 5);
277 if (exif_document_get(&geolocation_exif_document, EXIF_PRIMARY, EXIF_IMAGE_DESCRIPTION, &description)) {
278 if (description.format != EXIF_ASCII || description.size > sizeof(geolocation_description)) return false;
295 for (size_t index = 0; index < description_length; ++index) comment[offset++] = geolocation_description[index];
297 for (size_t index = 0; index < tag_length; ++index) comment[offset++] = (unsigned char)separator[index];
328 if (fstat(input_fd, &original) != 0 || !S_ISREG(original.st_mode)) { close(input_fd); return -1; }
400 const int layer = lwir_read_temperature_layer(filename, temperature_plane, sizeof(temperature_plane),
405 return publish_hotspot_comment(filename, "status=invalid_native_frame; count=0; coordinates_omitted=true");
410 "temperature_surface_correction=not_applied; absolute_accuracy_m=unknown; temperature_kind=%s; ",
413 if (!append_record(record, sizeof(record), &used, "status=no_temperature_plane; count=0")) return -1;
434 "capture_pose_synchronized=%s; capture_pose_uncertainty_m=%.6f; status=%s; calibration_verified=%s; "
460 if (!strcmp(status, "estimated") && lwir_geolocation_project(hotspot->center_x, hotspot->center_y, &geometry, &pose, &point)) {
464 point.latitude_deg, point.longitude_deg, point.altitude_ellipsoid_m, point.slant_range_m)) return -1;
466 const char *location_status = !strcmp(status, "estimated") ? "invalid_geometry_or_horizon" : status;
467 if (!append_record(record, sizeof(record), &used, "; location_status=%s\n", location_status)) return -1;
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
int exif_serialize(const struct exif_document *document, unsigned char *payload, size_t capacity, size_t *size)
Serialize a document into one complete EXIF APP1 payload.
Definition exifite.c:736
void exif_document_init(struct exif_document *document)
Start a fresh upright sRGB/Y-Cb-Cr document with EXIF 2.32 defaults.
Definition exifite.c:412
unsigned char * exif_document_reserve(struct exif_document *document, enum exif_directory directory, uint16_t tag, enum exif_format format, uint32_t count)
Create or replace a field with zeroed, bounded value storage.
Definition exifite.c:508
int exif_parse(struct exif_view *view, const unsigned char *payload, size_t size)
Validate an EXIF APP1 payload and create a borrowed view.
Definition exifite.c:257
bool exif_get(const struct exif_view *view, enum exif_directory directory, uint16_t tag, struct exif_value *value)
Look up a directory-local tag without copying its bytes.
Definition exifite.c:310
int exif_read_jpeg(const char *filename, unsigned char *payload, size_t capacity, size_t *size)
Read the single EXIF APP1 segment before the first JPEG scan.
Definition exifite.c:1022
bool exif_document_get(const struct exif_document *document, enum exif_directory directory, uint16_t tag, struct exif_value *value)
Borrow a field from the current writable document.
Definition exifite.c:447
#define EXIF_MAX_PAYLOAD
APP1 payload ceiling: the JPEG length includes its own two bytes.
Definition exifite.h:51
int exif_read_stream(FILE *input, unsigned char *payload, size_t capacity, size_t *size)
Read capture EXIF from an already-open JPEG without reopening its path.
Definition exifite.c:1013
int exif_rewrite_jpeg(FILE *input, FILE *output, const unsigned char *payload, size_t size)
Stream a JPEG with one new EXIF segment instead of its old EXIF records.
Definition exifite.c:1518
size_t exif_text_length(const struct exif_value *value)
Count text bytes after trimming trailing NUL padding only.
Definition exifite.c:399
int exif_update_jpeg(FILE *file, const unsigned char *payload, size_t size)
Replace EXIF in a regular JPEG file without a temporary file.
Definition exifite.c:1649
Flight, timing, and thermal-analysis metadata writing for captured JPEGs.
static int image_exif_import(struct exif_document *document, const struct exif_view *view)
Import standard metadata plus the application's approved capture evidence.
Definition image_exif.h:58
static struct lwir_detection_workspace detection_workspace
Definition lwir_analysis.c:59
static unsigned char geolocation_exif_payload[EXIF_MAX_PAYLOAD]
Definition lwir_analysis.c:54
static int publish_hotspot_comment(const char *filename, const char *information)
Rewrite a JPEG's EXIF with the analysis record, keeping image data intact.
Definition lwir_analysis.c:322
static uint8_t temperature_plane[LWIR_MAX_WIDTH *LWIR_MAX_HEIGHT *2]
Definition lwir_analysis.c:58
static bool read_pose(const char *filename, struct lwir_camera_pose *pose)
Read the observation pose recorded in a saved image's EXIF ImageDescription.
Definition lwir_analysis.c:151
static bool set_hotspot_comment(const char *information)
Store the analysis record in the in-memory EXIF document's UserComment.
Definition lwir_analysis.c:273
static bool parse_description_number(const char *value, size_t length, double *number)
Parse a finite decimal number from a non-NUL-terminated slice.
Definition lwir_analysis.c:110
static uint16_t read_u16_le(const uint8_t *bytes)
Decode one unsigned 16-bit little-endian value.
Definition lwir_analysis.c:68
static struct exif_document geolocation_exif_document
Definition lwir_analysis.c:53
static bool append_record(char *record, size_t capacity, size_t *used, const char *format,...)
Append printf-formatted text to a fixed record buffer.
Definition lwir_analysis.c:247
static uint16_t temperature_at(size_t pixel)
Raw Kelvin*64 code of one pixel in the static temperature plane.
Definition lwir_analysis.c:79
int lwir_geolocate_image(const char *filename, const char *calibration_path)
Detect, optionally geolocate and record hotspots for one saved JPEG.
Definition lwir_analysis.c:395
static unsigned char geolocation_description[8192]
Definition lwir_analysis.c:56
Optional saved-image adapter combining thermal detection, pose and projection.
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.
bool lwir_detect_hotspots(const uint8_t *temperature, size_t bytes, unsigned width, unsigned height, struct lwir_detection_workspace *workspace, struct lwir_hotspot_set *result)
Detect and rank hot connected components in a native temperature plane.
Definition lwir_detection.c:172
Optional thermal candidate detection, independent of pose and image files.
Native frame arithmetic and camera measurements; no codec or flight dependencies.
bool lwir_geolocation_project(double pixel_x, double pixel_y, const struct lwir_camera_geometry *camera, const struct lwir_camera_pose *pose, struct lwir_ground_point *point)
Project a native subpixel location onto the local ground plane.
Definition lwir_geolocation.c:275
bool lwir_geolocation_load_calibration(const char *path, unsigned width, unsigned height, struct lwir_camera_geometry *geometry)
Load a calibration profile for one native image size.
Definition lwir_geolocation.c:137
Optional camera calibration and native pixel-to-ground geometry only.
Borrowed bytes plus enough type information for safe interpretation.
Definition exifite.h:119
Projection calibration in native coordinates, never display coordinates.
Definition lwir_geolocation.h:56
bool verified
Operator verification claim; loading coefficients does not establish it.
Definition lwir_geolocation.h:63
Observation pose; geographic angles are degrees, attitude angles radians.
Definition lwir_geolocation.h:111
bool synchronized
Timing qualification retained for caller policy, not inferred by geometry.
Definition lwir_geolocation.h:115
double uncertainty_m
Observation uncertainty retained for caller qualification, not applied by projection.
Definition lwir_geolocation.h:114
Caller-owned scratch storage; never reserved by an imagery-only build.
Definition lwir_detection.h:127
WGS84 estimate on a local horizontal plane, not a surveyed accuracy claim.
Definition lwir_geolocation.h:151
Bounded ranking, retaining the existing two-candidate mission policy.
Definition lwir_detection.h:93
bool tray_pass_selected
True when candidates came from the tray ranking.
Definition lwir_detection.h:96
struct lwir_hotspot candidates[2]
Best first; only the first count entries are valid.
Definition lwir_detection.h:94
size_t generic_count
All components that passed the contrast check, not only retained ones.
Definition lwir_detection.h:95
double threshold_celsius
Frame threshold actually applied; NaN when the plane has no valid codes.
Definition lwir_detection.h:97
A thermal component expressed only in native sensor coordinates.
Definition lwir_detection.h:39
double center_x
Subpixel centroid column weighted by excess over local background; center_y likewise.
Definition lwir_detection.h:43
One timestamped geographic position for a replay annotation.
Definition ear_heatmap_overlay.c:79
Intermediate pose values parsed from the ImageDescription key=value list.
Definition lwir_analysis.c:92