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
lwir_geolocation.c
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/** @file
19 * @brief Native calibration and projection; no detector, JPEG codec or flight parser.
20 *
21 * @details Analysis builds only (`LWIR_ENABLE_ANALYSIS=1`). Provides a bounded,
22 * line-oriented calibration reader and a pixel-to-ground projection used on
23 * hotspots found in saved LWIR JPEG temperature planes. Fixed-size buffers only;
24 * no heap allocation. See lwir_geolocation.h for frame conventions and model limits.
25 */
26#include "lwir_geolocation.h"
27#include "lwir_frame.h"
28
29#include <errno.h>
30#include <limits.h>
31#include <math.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <unistd.h>
38
39/* Upper bound on calibration file size, keeping parsing bounded and cheap. */
40enum { lwir_calibration_max = 8192 };
41
42/** @brief Axis identities for rays and lever arms after rotation into NED. */
44
45/**
46 * @brief Parse one finite number at a cursor, skipping surrounding blanks.
47 * @details Rejects an empty field or a leading list/comment delimiter before
48 * calling strtod(), and requires the whole parsed value to be finite.
49 * @param[in,out] cursor Advanced past the number and trailing blanks on success.
50 * @param[out] value Written only on success.
51 * @return False for empty, unparsable, ERANGE, NaN or infinite input.
52 */
53static bool parse_number(const char **cursor, double *value)
54{
55 while (**cursor == ' ' || **cursor == '\t') ++*cursor;
56 if (**cursor == '\0' || **cursor == ',' || **cursor == ']' || **cursor == '#') return false;
57 errno = 0;
58 char *end = NULL;
59 const double parsed = strtod(*cursor, &end);
60 if (errno != 0 || end == *cursor || !isfinite(parsed)) return false;
61 *cursor = end;
62 while (**cursor == ' ' || **cursor == '\t') ++*cursor;
63 *value = parsed;
64 return true;
65}
66
67/**
68 * @brief Parse a value that must be exactly one number, optionally followed by a comment.
69 * @param text NUL-terminated value text after the key's colon.
70 * @param[out] value Parsed number; may be written even when trailing text fails.
71 * @return True when only blanks or a '#' comment follow the number.
72 */
73static bool parse_scalar(const char *text, double *value)
74{
75 const char *cursor = text;
76 if (!parse_number(&cursor, value)) return false;
77 if (*cursor == '#') return true;
78 return *cursor == '\0';
79}
80
81/**
82 * @brief Parse a nonnegative decimal integer that fits in unsigned int.
83 * @details Requires a leading digit so strtoul() cannot accept a sign ("-1"
84 * would otherwise wrap to a huge value).
85 * @param text NUL-terminated value text.
86 * @param[out] value Written only on success.
87 * @return True for a complete in-range integer, optionally followed by a comment.
88 */
89static bool parse_unsigned_scalar(const char *text, unsigned *value)
90{
91 const char *cursor = text;
92 while (*cursor == ' ' || *cursor == '\t') ++cursor;
93 if (*cursor < '0' || *cursor > '9') return false;
94 errno = 0;
95 char *end = NULL;
96 const unsigned long parsed = strtoul(cursor, &end, 10);
97 if (errno != 0 || end == cursor || parsed > UINT_MAX) return false;
98 while (*end == ' ' || *end == '\t') ++end;
99 if (*end && *end != '#') return false;
100 *value = (unsigned)parsed;
101 return true;
102}
103
104/**
105 * @brief Parse a single-line flow array `[a, b, ...]` with exactly @p count numbers.
106 * @param text NUL-terminated value text.
107 * @param[out] values Receives @p count numbers; may be partially written on failure.
108 * @param count Required element count; more or fewer elements fail.
109 * @return True for a well-formed array optionally followed by a comment.
110 */
111static bool parse_array(const char *text, double *values, size_t count)
112{
113 const char *cursor = text;
114 while (*cursor == ' ' || *cursor == '\t') ++cursor;
115 if (*cursor++ != '[') return false;
116 for (size_t index = 0; index < count; ++index) {
117 if (!parse_number(&cursor, &values[index])) return false;
118 if (index + 1 < count) {
119 if (*cursor++ != ',') return false;
120 } else if (*cursor++ != ']') {
121 return false;
122 }
123 }
124 while (*cursor == ' ' || *cursor == '\t') ++cursor;
125 return *cursor == '\0' || *cursor == '#';
126}
127
128/**
129 * @brief Load a calibration profile for one native image size.
130 * @details Reads `key: value` lines (a YAML-like subset) into a local copy and
131 * publishes it only after all checks pass, so @p geometry is never half-written.
132 * A bitmask of seen keys detects duplicates and missing required keys.
133 * @return True for a structurally valid profile; false for I/O errors, a
134 * non-regular/empty/oversized file, syntax errors, duplicates, missing keys or
135 * out-of-range values.
136 */
137bool lwir_geolocation_load_calibration(const char *path, unsigned width, unsigned height,
138 struct lwir_camera_geometry *geometry)
139{
140 if (!path || !*path || !geometry || !width || !height ||
141 width > LWIR_MAX_WIDTH || height > LWIR_MAX_HEIGHT) return false;
142 FILE *input = fopen(path, "rb");
143 if (!input) return false;
144 /* Size is checked on the opened descriptor, so the file cannot be swapped
145 * between the check and the read. */
146 struct stat status;
147 bool valid = fstat(fileno(input), &status) == 0 && S_ISREG(status.st_mode)
148 && status.st_size > 0 && status.st_size <= lwir_calibration_max;
149 struct lwir_camera_geometry parsed = {
150 .camera_to_body = {0, -1, 0, 1, 0, 0, 0, 0, 1},
151 .minimum_ground_cosine = 0.2,
152 .image_width = width,
153 .image_height = height
154 };
155 enum { key_width = 0, key_height, key_fx, key_fy, key_cx, key_cy,
156 key_k1, key_k2, key_p1, key_p2, key_k3, key_verified,
157 key_rotation, key_lever_arm, key_minimum_cosine };
158 unsigned seen = 0;
159 char line[512];
160 size_t total = 0;
161 while (valid && fgets(line, sizeof(line), input)) {
162 size_t line_length = strlen(line);
163 total += line_length;
164 /* The running total also bounds files that grew after fstat(); a line
165 * filling the buffer without a newline (and not at EOF) is too long. */
166 if (total > lwir_calibration_max || (line_length && line[line_length - 1] != '\n' && !feof(input))) {
167 valid = false;
168 break;
169 }
170 while (line_length && (line[line_length - 1] == '\n' || line[line_length - 1] == '\r'))
171 line[--line_length] = '\0';
172 char *cursor = line;
173 while (*cursor == ' ' || *cursor == '\t' || *cursor == '\r' || *cursor == '\n') ++cursor;
174 /* Skip blanks, comments, YAML directives ('%') and the document marker. */
175 if (!*cursor || *cursor == '#' || *cursor == '%' || !strcmp(cursor, "---")) continue;
176 char *colon = strchr(cursor, ':');
177 if (!colon) { valid = false; break; }
178 char *key_end = colon;
179 while (key_end > cursor && (key_end[-1] == ' ' || key_end[-1] == '\t')) --key_end;
180 *key_end = '\0';
181 const char *value = colon + 1;
182 while (*value == ' ' || *value == '\t') ++value;
183 unsigned field = 0;
184 const char *const names[] = {"image_width", "image_height", "fx", "fy", "cx", "cy",
185 "k1", "k2", "p1", "p2", "k3", "verified", "camera_to_body",
186 "lever_arm_body_m", "minimum_ground_cosine"};
187 while (field < sizeof(names) / sizeof(names[0]) && strcmp(cursor, names[field])) ++field;
188 /* Unknown keys are tolerated, presumably so profiles can carry extra
189 * metadata (e.g. from other calibration tools). */
190 if (field == sizeof(names) / sizeof(names[0])) continue;
191 if (seen & (1U << field)) { valid = false; break; }
192 seen |= 1U << field;
193 if (field == key_width || field == key_height) {
194 /* Intrinsics are only valid for the resolution they were measured at. */
195 unsigned dimension;
196 valid = parse_unsigned_scalar(value, &dimension) &&
197 dimension == (field == key_width ? width : height);
198 } else if (field == key_rotation || field == key_lever_arm) {
199 double values[9];
200 const size_t number_count = field == key_rotation ? 9 : 3;
201 valid = parse_array(value, values, number_count);
202 if (valid && field == key_rotation)
203 for (size_t index = 0; index < 9; ++index) parsed.camera_to_body[index] = values[index];
204 if (valid && field == key_lever_arm)
205 for (size_t index = 0; index < 3; ++index) parsed.lever_arm_body_m[index] = values[index];
206 } else {
207 double number;
208 valid = parse_scalar(value, &number);
209 if (!valid) break;
210 switch (field) {
211 case key_fx: parsed.fx = number; break;
212 case key_fy: parsed.fy = number; break;
213 case key_cx: parsed.cx = number; break;
214 case key_cy: parsed.cy = number; break;
215 case key_k1: parsed.k1 = number; break;
216 case key_k2: parsed.k2 = number; break;
217 case key_p1: parsed.p1 = number; break;
218 case key_p2: parsed.p2 = number; break;
219 case key_k3: parsed.k3 = number; break;
220 case key_verified:
221 if (number != 0 && number != 1) valid = false;
222 else parsed.verified = number == 1;
223 break;
224 case key_minimum_cosine: parsed.minimum_ground_cosine = number; break;
225 default: valid = false; break;
226 }
227 }
228 if (!valid) break;
229 }
230 if (ferror(input)) valid = false;
231 if (fclose(input) != 0) valid = false;
232 /* Lever arm and minimum cosine are optional; the rotation is required even
233 * though a default exists, presumably so the mount is always stated explicitly. */
234 const unsigned required = (1U << key_width) | (1U << key_height) | (1U << key_fx)
235 | (1U << key_fy) | (1U << key_cx) | (1U << key_cy) | (1U << key_k1)
236 | (1U << key_k2) | (1U << key_p1) | (1U << key_p2) | (1U << key_k3)
237 | (1U << key_verified) | (1U << key_rotation);
238 if (!valid || (seen & required) != required || parsed.fx <= 0 || parsed.fy <= 0 ||
239 parsed.minimum_ground_cosine < 0.05 || parsed.minimum_ground_cosine > 1) return false;
240 *geometry = parsed;
241 return true;
242}
243
244/**
245 * @brief Multiply a row-major 3x3 matrix by a 3-vector.
246 * @param matrix Row-major matrix.
247 * @param vector Input vector; must not alias @p result.
248 * @param[out] result matrix * vector.
249 */
250static void rotate_vector(const double matrix[9], const double vector[3], double result[3])
251{
252 for (size_t row = 0; row < 3; ++row) {
253 result[row] = 0;
254 for (size_t column = 0; column < 3; ++column)
255 result[row] += matrix[3 * row + column] * vector[column];
256 }
257}
258
259/**
260 * @brief Project a native subpixel location onto the local ground plane.
261 * @details Steps:
262 * -# Validate every input (finite, in range, proper rotation).
263 * -# Pixel -> distorted normalized coordinates via intrinsics.
264 * -# Invert Brown-Conrady distortion by fixed-point iteration.
265 * -# Build the camera ray (x, y, 1), rotate camera -> body -> NED.
266 * -# Intersect with the plane `agl_m` below the navigation reference, starting
267 * from the lever-arm-offset camera origin.
268 * -# Convert the NED offset to WGS84 latitude/longitude via ECEF.
269 * @return False for invalid inputs, an improper mount rotation, nonconvergent
270 * undistortion, a ray too close to the horizon, or a camera origin at/below
271 * the ground plane.
272 * @note Pixel coordinates are combined with cx/cy as-is, so they must follow the
273 * calibration's convention (OpenCV: integer coordinates at pixel centres).
274 */
275bool lwir_geolocation_project(double pixel_x, double pixel_y,
276 const struct lwir_camera_geometry *camera,
277 const struct lwir_camera_pose *pose,
278 struct lwir_ground_point *point)
279{
280 if (!camera || !pose || !point) return false;
281 const double values[] = {pixel_x, pixel_y, camera->fx, camera->fy, camera->cx, camera->cy,
282 camera->k1, camera->k2, camera->p1, camera->p2, camera->k3, camera->minimum_ground_cosine,
283 pose->latitude_deg, pose->longitude_deg, pose->altitude_ellipsoid_m, pose->agl_m,
284 pose->roll_rad, pose->pitch_rad, pose->yaw_rad};
285 for (size_t index = 0; index < sizeof(values) / sizeof(values[0]); ++index)
286 if (!isfinite(values[index])) return false;
287 if (!camera->image_width || !camera->image_height || camera->image_width > LWIR_MAX_WIDTH ||
288 camera->image_height > LWIR_MAX_HEIGHT || pixel_x < 0 || pixel_y < 0 ||
289 pixel_x >= camera->image_width || pixel_y >= camera->image_height ||
290 camera->fx <= 0 || camera->fy <= 0 || pose->agl_m <= 0 ||
291 fabs(pose->latitude_deg) >= 90 || fabs(pose->longitude_deg) > 180 ||
292 camera->minimum_ground_cosine < 0.05 || camera->minimum_ground_cosine > 1) return false;
293 for (size_t index = 0; index < 3; ++index)
294 if (!isfinite(camera->lever_arm_body_m[index])) return false;
295 for (size_t index = 0; index < 9; ++index)
296 if (!isfinite(camera->camera_to_body[index])) return false;
297 /* A reflected/skewed mount can produce plausible but wrong ground positions. */
298 /* Orthonormality: R * R^T must equal I, checked row against row. */
299 for (size_t row = 0; row < 3; ++row) {
300 for (size_t other = 0; other < 3; ++other) {
301 double product = 0;
302 for (size_t column = 0; column < 3; ++column)
303 product += camera->camera_to_body[3 * row + column] * camera->camera_to_body[3 * other + column];
304 if (fabs(product - (row == other ? 1.0 : 0.0)) > 1e-6) return false;
305 }
306 }
307 const double *mount = camera->camera_to_body;
308 /* Orthonormal matrices have determinant +/-1; -1 is a mirror, not a mount. */
309 const double determinant = mount[0] * (mount[4] * mount[8] - mount[5] * mount[7])
310 - mount[1] * (mount[3] * mount[8] - mount[5] * mount[6])
311 + mount[2] * (mount[3] * mount[7] - mount[4] * mount[6]);
312 if (fabs(determinant - 1) > 1e-6) return false;
313 /* Pinhole inverse: normalized image-plane coordinates still containing lens
314 * distortion, i.e. x_d = (u - cx) / fx, y_d = (v - cy) / fy. */
315 const double distorted_x = (pixel_x - camera->cx) / camera->fx;
316 const double distorted_y = (pixel_y - camera->cy) / camera->fy;
317 double undistorted_x = distorted_x, undistorted_y = distorted_y;
318 /* Bound inverse distortion work; failed convergence must not become a coordinate. */
319 /* Forward model (OpenCV): x_d = x * k_r + t_x, y_d = y * k_r + t_y, with
320 * r^2 = x^2 + y^2, k_r = 1 + k1 r^2 + k2 r^4 + k3 r^6,
321 * t_x = 2 p1 x y + p2 (r^2 + 2 x^2), t_y = p1 (r^2 + 2 y^2) + 2 p2 x y.
322 * It has no closed-form inverse, so iterate x <- (x_d - t_x) / k_r from the
323 * distorted point until the forward residual is below 1e-12 (normalized
324 * units), an iterative scheme similar to cv::undistortPoints. A nonpositive k_r
325 * presumably means the polynomial has folded over, so the ray is rejected. */
326 bool converged = false;
327 for (unsigned iteration = 0; iteration < 50; ++iteration) {
328 const double radius2 = undistorted_x * undistorted_x + undistorted_y * undistorted_y;
329 const double radial = 1 + radius2 * (camera->k1 + radius2 * (camera->k2 + radius2 * camera->k3));
330 if (!isfinite(radial) || radial <= 0) return false;
331 const double tangent_x = 2 * camera->p1 * undistorted_x * undistorted_y +
332 camera->p2 * (radius2 + 2 * undistorted_x * undistorted_x);
333 const double tangent_y = camera->p1 * (radius2 + 2 * undistorted_y * undistorted_y) +
334 2 * camera->p2 * undistorted_x * undistorted_y;
335 if (hypot(undistorted_x * radial + tangent_x - distorted_x,
336 undistorted_y * radial + tangent_y - distorted_y) < 1e-12) {
337 converged = true;
338 break;
339 }
340 undistorted_x = (distorted_x - tangent_x) / radial;
341 undistorted_y = (distorted_y - tangent_y) / radial;
342 }
343 if (!converged) return false;
344 /* Keep distortion in camera coordinates; mount and attitude rotations follow convergence. */
345 /* Body-to-NED direction cosine matrix for aerospace Z-Y-X Euler angles:
346 * R = Rz(yaw) * Ry(pitch) * Rx(roll), i.e. roll applied first in body axes.
347 * Row-major; columns are the body forward/right/down axes expressed in NED. */
348 const double roll_cos = cos(pose->roll_rad), roll_sin = sin(pose->roll_rad);
349 const double pitch_cos = cos(pose->pitch_rad), pitch_sin = sin(pose->pitch_rad);
350 const double yaw_cos = cos(pose->yaw_rad), yaw_sin = sin(pose->yaw_rad);
351 const double body_to_ned[9] = {
352 pitch_cos * yaw_cos, roll_sin * pitch_sin * yaw_cos - roll_cos * yaw_sin, roll_cos * pitch_sin * yaw_cos + roll_sin * yaw_sin,
353 pitch_cos * yaw_sin, roll_sin * pitch_sin * yaw_sin + roll_cos * yaw_cos, roll_cos * pitch_sin * yaw_sin - roll_sin * yaw_cos,
354 -pitch_sin, roll_sin * pitch_cos, roll_cos * pitch_cos};
355 /* Unnormalized ray through the undistorted point at unit depth; only its
356 * direction matters, and the norm is applied later for range and the guard. */
357 const double camera_ray[3] = {undistorted_x, undistorted_y, 1};
358 double body_ray[3], ned_ray[3], ned_origin[3];
359 rotate_vector(camera->camera_to_body, camera_ray, body_ray);
360 rotate_vector(body_to_ned, body_ray, ned_ray);
361 /* Camera origin relative to the navigation reference, in NED. */
362 rotate_vector(body_to_ned, camera->lever_arm_body_m, ned_origin);
363 const double norm = sqrt(ned_ray[NED_NORTH] * ned_ray[NED_NORTH] +
364 ned_ray[NED_EAST] * ned_ray[NED_EAST] +
365 ned_ray[NED_DOWN] * ned_ray[NED_DOWN]);
366 /* Near-horizon intersections amplify small calibration/pose errors without bound. */
367 /* down/norm is the cosine between the ray and straight down. The camera
368 * origin must also be above the plane, else the intersection is behind it. */
369 if (!isfinite(norm) || ned_ray[NED_DOWN] / norm < camera->minimum_ground_cosine ||
370 pose->agl_m <= ned_origin[NED_DOWN]) return false;
371 /* Ray-plane intersection: origin_down + s * ray_down = agl (ground is +agl
372 * down from the reference), so s = (agl - origin_down) / ray_down; ray_down > 0
373 * is guaranteed by the cosine guard. Because the ray is unnormalized, the
374 * metric range is s * |ray|. Flat-ground gotcha: any terrain height difference
375 * dh moves the point by roughly dh * tan(off-nadir angle) horizontally. */
376 const double scale = (pose->agl_m - ned_origin[NED_DOWN]) / ned_ray[NED_DOWN];
378 result.north_m = ned_origin[NED_NORTH] + scale * ned_ray[NED_NORTH];
379 result.east_m = ned_origin[NED_EAST] + scale * ned_ray[NED_EAST];
380 result.slant_range_m = scale * norm;
381 /* Apply the local NED offset in ECEF before recovering geodetic latitude/longitude. */
382 /* Step 1: reference position in ECEF on the WGS84 ellipsoid (a = 6378137 m,
383 * e^2 = 6.694e-3), with N the prime-vertical radius of curvature:
384 * X = (N + h) cos(lat) cos(lon), Y = (N + h) cos(lat) sin(lon),
385 * Z = (N (1 - e^2) + h) sin(lat).
386 * h is the WGS84 ellipsoidal height, exactly what this formula requires.
387 * Step 2: add north * n + east * e + agl * d, where the NED unit vectors are
388 * n = (-sin lat cos lon, -sin lat sin lon, cos lat),
389 * e = (-sin lon, cos lon, 0),
390 * d = (-cos lat cos lon, -cos lat sin lon, -sin lat).
391 * Doing the offset in ECEF avoids a flat-earth metres-per-degree approximation. */
392 const double pi = 3.14159265358979323846;
393 const double radius = 6378137.0;
394 const double eccentricity_squared = 6.6943799901413165e-3;
395 const double latitude = pose->latitude_deg * pi / 180;
396 const double longitude = pose->longitude_deg * pi / 180;
397 const double latitude_sin = sin(latitude), latitude_cos = cos(latitude);
398 const double longitude_sin = sin(longitude), longitude_cos = cos(longitude);
399 const double prime_vertical = radius / sqrt(1 - eccentricity_squared * latitude_sin * latitude_sin);
400 const double earth_x = (prime_vertical + pose->altitude_ellipsoid_m) * latitude_cos * longitude_cos
401 - latitude_sin * longitude_cos * result.north_m - longitude_sin * result.east_m
402 - latitude_cos * longitude_cos * pose->agl_m;
403 const double earth_y = (prime_vertical + pose->altitude_ellipsoid_m) * latitude_cos * longitude_sin
404 - latitude_sin * longitude_sin * result.north_m + longitude_cos * result.east_m
405 - latitude_cos * longitude_sin * pose->agl_m;
406 const double earth_z = (prime_vertical * (1 - eccentricity_squared) + pose->altitude_ellipsoid_m) * latitude_sin
407 + latitude_cos * result.north_m - latitude_sin * pose->agl_m;
408 const double horizontal = hypot(earth_x, earth_y);
409 /* Step 3: ECEF -> geodetic latitude by fixed-point iteration
410 * lat <- atan2(Z + e^2 N(lat) sin(lat), p), p = sqrt(X^2 + Y^2),
411 * seeded with the h = 0 solution. A fixed ten iterations is expected to be
412 * ample for near-surface points (no convergence test); longitude is closed-form. */
413 double target_latitude = atan2(earth_z, horizontal * (1 - eccentricity_squared));
414 for (unsigned iteration = 0; iteration < 10; ++iteration) {
415 const double target_sin = sin(target_latitude);
416 const double target_radius = radius / sqrt(1 - eccentricity_squared * target_sin * target_sin);
417 target_latitude = atan2(earth_z + eccentricity_squared * target_radius * target_sin, horizontal);
418 }
419 result.latitude_deg = target_latitude * 180 / pi;
420 result.longitude_deg = atan2(earth_y, earth_x) * 180 / pi;
421 /* Reported altitude is the assumed plane, not a height recovered from ECEF. */
422 result.altitude_ellipsoid_m = pose->altitude_ellipsoid_m - pose->agl_m;
423 if (!isfinite(result.latitude_deg) || !isfinite(result.longitude_deg) || !isfinite(result.slant_range_m)) return false;
424 *point = result;
425 return true;
426}
427
static double latitude
static double longitude
Native frame arithmetic and camera measurements; no codec or flight dependencies.
#define LWIR_MAX_WIDTH
Largest supported native width in pixels.
Definition lwir_frame.h:47
#define LWIR_MAX_HEIGHT
Largest supported native height in pixels.
Definition lwir_frame.h:49
static bool parse_scalar(const char *text, double *value)
Parse a value that must be exactly one number, optionally followed by a comment.
static bool parse_number(const char **cursor, double *value)
Parse one finite number at a cursor, skipping surrounding blanks.
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.
static void rotate_vector(const double matrix[9], const double vector[3], double result[3])
Multiply a row-major 3x3 matrix by a 3-vector.
static bool parse_unsigned_scalar(const char *text, unsigned *value)
Parse a nonnegative decimal integer that fits in unsigned int.
static bool parse_array(const char *text, double *values, size_t count)
Parse a single-line flow array [a, b, ...] with exactly count numbers.
@ lwir_calibration_max
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.
ned_axis
Axis identities for rays and lever arms after rotation into NED.
@ NED_NORTH
@ NED_EAST
@ NED_DOWN
Optional camera calibration and native pixel-to-ground geometry only.
uint8_t row[LWIR_MAX_WIDTH *3U]
Definition lwir_image.c:63
static size_t count
Definition pose_log.c:79
Projection calibration in native coordinates, never display coordinates.
double k2
Dimensionless radial coefficient multiplying normalized radius to the fourth power.
double minimum_ground_cosine
Minimum normalized downward ray component; rejects unstable horizon intersections.
double k1
Dimensionless radial coefficient multiplying normalized radius squared.
double cx
Principal-point column in native pixel coordinates.
double k3
Dimensionless radial coefficient multiplying normalized radius to the sixth power.
double camera_to_body[9]
Row-major rotation: camera right/down/forward to body forward/right/down.
double fx
Horizontal focal length in native pixels; must be positive.
double p1
First dimensionless tangential-distortion coefficient in OpenCV order.
double cy
Principal-point row in native pixel coordinates.
double p2
Second dimensionless tangential-distortion coefficient in OpenCV order.
bool verified
Operator verification claim; loading coefficients does not establish it.
double fy
Vertical focal length in native pixels; must be positive.
double lever_arm_body_m[3]
Navigation reference to camera origin, in body forward/right/down metres.
Observation pose; geographic angles are degrees, attitude angles radians.
double agl_m
Positive height of the navigation reference above the local ground plane.
double yaw_rad
Body yaw in radians, measured from north toward east.
double longitude_deg
Navigation reference longitude in WGS84 degrees.
double altitude_ellipsoid_m
Navigation reference height above the WGS84 ellipsoid in metres.
double pitch_rad
Body pitch in radians for the body-to-NED attitude rotation.
double roll_rad
Body roll in radians for the body-to-NED attitude rotation.
double latitude_deg
Navigation reference latitude in WGS84 degrees.
WGS84 estimate on a local horizontal plane, not a surveyed accuracy claim.
One timestamped geographic position for a replay annotation.
static struct camera_backend camera
Definition usher.c:521
bool valid
Definition usher.c:537
struct usher_control_result result
Definition usher.c:377