19#define _POSIX_C_SOURCE 200809L
54#include <opencv2/calib3d.hpp>
55#include <opencv2/core.hpp>
56#include <opencv2/core/persistence.hpp>
57#include <opencv2/imgproc.hpp>
82namespace fs = std::filesystem;
85constexpr size_t maximum_jpeg_bytes = 128U * 1024U * 1024U;
87constexpr uint64_t maximum_image_pixels = 32U * 1024U * 1024U;
89constexpr unsigned maximum_image_dimension = 8192U;
91constexpr size_t maximum_directory_images = 10000U;
93constexpr size_t minimum_fit_views = 15U;
95constexpr size_t minimum_check_views = 5U;
97constexpr double metres_per_millimetre = 0.001;
99constexpr double preferred_preview_scale = 3.0;
101constexpr int preview_jpeg_quality = 95;
103constexpr const char* profile_verified_key =
"verified";
106struct UsageError : std::runtime_error {
107 using std::runtime_error::runtime_error;
116 void operator()(FILE* file)
const noexcept
118 if (file !=
nullptr) {
125using File = std::unique_ptr<FILE, FileCloser>;
133 jpeg_error_mgr manager{};
135 void (*emit)(j_common_ptr, int) =
nullptr;
147 auto*
error =
reinterpret_cast<JpegError*
>(state->err);
148 longjmp(
error->recovery, 1);
154 reinterpret_cast<JpegError*
>(state->err)->emit(state, level);
159 jpeg_decompress_struct state{};
161 bool created =
false;
168 jpeg_destroy_decompress(&state);
175 jpeg_compress_struct state{};
177 bool created =
false;
183 jpeg_destroy_compress(&state);
194 enum class Mode { lens, mount };
195 Mode mode = Mode::lens;
198 double square_mm = 0.0;
204 bool reverse_corners =
false;
217 cv::Mat camera_matrix;
222using Report = std::vector<std::string>;
229void require(
bool condition,
const std::string& message)
232 throw std::runtime_error(message);
244double parse_double(
const std::string& text,
const std::string& option)
247 const double value = std::stod(text, &consumed);
248 if (consumed != text.size() || !std::isfinite(value)) {
249 throw UsageError(option +
" requires one finite number");
262int parse_integer(
const std::string& text,
const std::string& option)
265 const long value = std::stol(text, &consumed, 10);
266 if (consumed != text.size() || value < 0 || value > 1000000) {
267 throw UsageError(option +
" requires a nonnegative integer");
269 return static_cast<int>(value);
279 <<
" " << program <<
" lens --images DIR [--check DIR] --columns N --rows N\n"
280 <<
" --square-mm MM --output PROFILE.yml\n"
281 <<
" " << program <<
" mount --image PHOTO.jpg --lens PROFILE.yml\n"
282 <<
" --columns N --rows N --square-mm MM --output PROFILE.yml\n"
283 <<
" [--reverse-corners]\n"
284 <<
"Only original JPG/JPEG calibration photographs are accepted.\n";
299 throw UsageError(
"select lens or mount mode");
302 const std::string mode(argv[1]);
303 if (mode ==
"lens") {
304 options.mode = Options::Mode::lens;
305 }
else if (mode ==
"mount") {
306 options.mode = Options::Mode::mount;
308 throw UsageError(
"mode must be lens or mount");
311 std::set<std::string> seen;
312 for (
int index = 2; index < argc; ++index) {
313 const std::string key(argv[index]);
314 if (!seen.insert(key).second) {
315 throw UsageError(
"option repeated: " + key);
317 if (key ==
"--reverse-corners") {
318 options.reverse_corners =
true;
321 if (index + 1 >= argc) {
322 throw UsageError(
"missing value for " + key);
324 const std::string value(argv[++index]);
325 if (key ==
"--columns") {
326 options.columns = parse_integer(value, key);
327 }
else if (key ==
"--rows") {
328 options.rows = parse_integer(value, key);
329 }
else if (key ==
"--square-mm") {
331 }
else if (key ==
"--output") {
333 }
else if (key ==
"--images") {
335 }
else if (key ==
"--check") {
337 }
else if (key ==
"--image") {
339 }
else if (key ==
"--lens") {
342 throw UsageError(
"unknown option: " + key);
348 throw UsageError(
"use 3..64 inner corners per dimension, a positive square pitch, and --output");
352 throw UsageError(
"lens mode requires --images and does not accept mount-only options");
356 throw UsageError(
"mount mode requires --image and --lens, not --images or --check");
368File open_regular_jpeg(
const fs::path& path)
370 const std::string native_path = path.string();
371 File input(std::fopen(native_path.c_str(),
"rb"));
372 require(input !=
nullptr,
"cannot open JPEG: " + native_path);
373 struct stat status {};
374 require(::fstat(::fileno(input.get()), &status) == 0 && S_ISREG(status.st_mode)
375 && status.st_size > 0 &&
static_cast<uint64_t
>(status.st_size) <= maximum_jpeg_bytes,
376 "JPEG must be a non-empty regular file below 128 MiB: " + native_path);
388cv::Mat read_jpeg_gray(
const fs::path& path)
390 File input = open_regular_jpeg(path);
391 auto decoder = std::make_unique<Decoder>();
396 if (setjmp(
decoder->error.recovery)) {
397 throw std::runtime_error(
"invalid or damaged JPEG: " + path.string());
400 jpeg_create_decompress(&
decoder->state);
401 jpeg_stdio_src(&
decoder->state, input.get());
402 require(jpeg_read_header(&
decoder->state, TRUE) == JPEG_HEADER_OK,
403 "invalid JPEG header: " + path.string());
404 const uint64_t width =
decoder->state.image_width;
405 const uint64_t height =
decoder->state.image_height;
406 require(width >= 2 && height >= 2 && width <= maximum_image_dimension
407 && height <= maximum_image_dimension && width * height <= maximum_image_pixels,
408 "unsupported JPEG dimensions: " + path.string());
409 decoder->state.out_color_space = JCS_GRAYSCALE;
410 jpeg_start_decompress(&
decoder->state);
411 decoder->gray.create(
static_cast<int>(height),
static_cast<int>(width), CV_8UC1);
412 while (
decoder->state.output_scanline <
decoder->state.output_height) {
414 require(jpeg_read_scanlines(&
decoder->state, &
row, 1) == 1,
415 "incomplete JPEG scanline: " + path.string());
417 jpeg_finish_decompress(&
decoder->state);
418 require(
decoder->error.manager.num_warnings == 0,
"damaged JPEG: " + path.string());
431void write_jpeg_bgr(
const fs::path& path,
const cv::Mat& bgr)
433 require(!bgr.empty() && bgr.type() == CV_8UC3
434 && bgr.cols <=
static_cast<int>(maximum_image_dimension)
435 && bgr.rows <=
static_cast<int>(maximum_image_dimension)
436 &&
static_cast<uint64_t
>(bgr.cols) *
static_cast<uint64_t
>(bgr.rows) <= maximum_image_pixels,
437 "preview must be an 8-bit BGR image within the configured dimension limit");
438 const std::string native_path = path.string();
439 File
output(std::fopen(native_path.c_str(),
"wb"));
440 require(
output !=
nullptr,
"cannot create JPEG preview: " + native_path);
441 auto encoder = std::make_unique<Encoder>();
444 std::array<JSAMPLE, maximum_image_dimension * 3U> rgb_row{};
445 if (setjmp(
encoder->error.recovery)) {
446 ::unlink(native_path.c_str());
447 throw std::runtime_error(
"JPEG preview encoding failed: " + native_path);
450 jpeg_create_compress(&
encoder->state);
452 encoder->state.image_width =
static_cast<JDIMENSION
>(bgr.cols);
453 encoder->state.image_height =
static_cast<JDIMENSION
>(bgr.rows);
454 encoder->state.input_components = 3;
455 encoder->state.in_color_space = JCS_RGB;
456 jpeg_set_defaults(&
encoder->state);
457 jpeg_set_quality(&
encoder->state, preview_jpeg_quality, TRUE);
458 jpeg_start_compress(&
encoder->state, TRUE);
459 while (
encoder->state.next_scanline <
encoder->state.image_height) {
460 const unsigned int y =
encoder->state.next_scanline;
461 const cv::Vec3b* source = bgr.ptr<cv::Vec3b>(
static_cast<int>(y));
462 for (
int x = 0; x < bgr.cols; ++x) {
463 rgb_row[
static_cast<size_t>(x) * 3U] = source[x][2];
464 rgb_row[
static_cast<size_t>(x) * 3U + 1U] = source[x][1];
465 rgb_row[
static_cast<size_t>(x) * 3U + 2U] = source[x][0];
467 JSAMPROW
row = rgb_row.data();
468 require(jpeg_write_scanlines(&
encoder->state, &
row, 1) == 1,
469 "cannot write JPEG preview scanline");
471 jpeg_finish_compress(&
encoder->state);
472 require(std::fflush(
output.get()) == 0,
"cannot flush JPEG preview: " + native_path);
483std::vector<fs::path> jpg_paths(
const fs::path& directory)
485 std::error_code
error;
486 require(fs::is_directory(directory,
error) && !
error,
487 "not an image directory: " + directory.string());
488 std::vector<fs::path> paths;
489 for (fs::directory_iterator it(directory,
error), end; !
error && it != end; it.increment(
error)) {
490 if (paths.size() >= maximum_directory_images) {
491 throw std::runtime_error(
"image directory exceeds the 10000-file limit: " + directory.string());
497 std::string extension = it->path().extension().string();
498 std::transform(extension.begin(), extension.end(), extension.begin(),
499 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
500 if (extension ==
".jpg" || extension ==
".jpeg") {
501 paths.push_back(it->path());
504 require(!
error,
"cannot enumerate image directory: " + directory.string());
505 std::sort(paths.begin(), paths.end());
506 require(!paths.empty(),
"no JPG/JPEG images in " + directory.string());
518std::vector<cv::Point3f> board_points(
int columns,
int rows,
double square_mm)
520 const float pitch_m =
static_cast<float>(square_mm * metres_per_millimetre);
521 std::vector<cv::Point3f> points;
522 points.reserve(
static_cast<size_t>(columns) *
static_cast<size_t>(rows));
524 for (
int column = 0; column < columns; ++column) {
525 points.emplace_back(column * pitch_m,
row * pitch_m, 0.0F);
539bool detect_board(
const cv::Mat& gray,
const Options&
options, std::vector<cv::Point2f>& corners)
542 return cv::findChessboardCornersSB(gray, pattern, corners,
543 cv::CALIB_CB_NORMALIZE_IMAGE | cv::CALIB_CB_EXHAUSTIVE);
558double reprojection_rms(
const std::vector<cv::Point3f>& object_points,
559 const std::vector<cv::Point2f>& image_points,
560 const cv::Mat& rotation,
const cv::Mat& translation,
561 const cv::Mat& camera_matrix,
const cv::Mat& distortion)
563 std::vector<cv::Point2f> projected;
564 cv::projectPoints(object_points, rotation, translation, camera_matrix, distortion, projected);
565 double squared_error = 0.0;
566 for (
size_t index = 0; index < projected.size(); ++index) {
567 const cv::Point2f delta = projected[index] - image_points[index];
568 squared_error += delta.dot(delta);
570 return std::sqrt(squared_error /
static_cast<double>(projected.size()));
584void write_preview(
const cv::Mat& gray,
const std::vector<cv::Point2f>& corners,
585 const Options&
options,
const fs::path& path,
bool numbered)
588 cv::cvtColor(gray, canvas, cv::COLOR_GRAY2BGR);
589 cv::drawChessboardCorners(canvas, cv::Size(
options.columns,
options.rows), corners,
true);
590 const double dimension_scale = std::min(
591 static_cast<double>(maximum_image_dimension) / canvas.cols,
592 static_cast<double>(maximum_image_dimension) / canvas.rows);
593 const double pixel_scale = std::sqrt(
static_cast<double>(maximum_image_pixels) / canvas.total());
594 const double scale = std::min(preferred_preview_scale, std::min(dimension_scale, pixel_scale));
595 const cv::Size preview_size(std::max(1, cvRound(canvas.cols * scale)),
596 std::max(1, cvRound(canvas.rows * scale)));
597 cv::resize(canvas, canvas, preview_size, 0.0, 0.0, cv::INTER_NEAREST);
599 for (
const int index : {0, 1,
options.columns}) {
600 require(
static_cast<size_t>(index) < corners.size(),
"internal corner index outside detected pattern");
601 const cv::Point
point(cvRound(corners[index].x * preview_size.width / gray.cols),
602 cvRound(corners[index].y * preview_size.height / gray.rows));
603 const std::string label = std::to_string(index);
604 cv::putText(canvas, label,
point, cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(0, 0, 0), 4, cv::LINE_AA);
605 cv::putText(canvas, label,
point, cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(255, 255, 255), 1, cv::LINE_AA);
608 write_jpeg_bgr(path, canvas);
615void report_line(Report&
report,
const std::string& line)
618 std::cout << line <<
'\n';
627void write_report(
const fs::path& path,
const Report&
report)
629 std::ofstream
output(path, std::ios::binary | std::ios::trunc);
630 require(
output.good(),
"cannot write calibration report: " + path.string());
631 for (
const std::string& line :
report) {
634 require(
output.good(),
"incomplete calibration report: " + path.string());
646OutputPaths prepare_outputs(
const Options&
options)
650 paths.report.replace_extension(
".report.txt");
651 std::error_code
error;
652 require(!fs::exists(paths.profile,
error) && !
error && !fs::exists(paths.previews,
error)
654 "output, report or preview path already exists; choose a new output name");
655 fs::path parent = paths.profile.parent_path();
656 if (parent.empty()) {
659 fs::create_directories(parent);
660 fs::create_directory(paths.previews);
668void append_report_header(
const Options&
options, Report&
report)
670 std::ostringstream
header;
671 header <<
"LWIR workshop calibration; OpenCV " << CV_VERSION;
673 std::ostringstream pattern;
675 <<
" inner corners, pitch " <<
options.square_mm <<
" mm";
676 report.push_back(pattern.str());
677 report.emplace_back(
"verified=0; inspect previews and perform independent physical checks.");
687void validate_outputs(
const cv::Mat& camera_matrix,
const cv::Mat& distortion,
688 const std::array<double, 9>& mounting)
690 require(cv::checkRange(camera_matrix) && cv::checkRange(distortion),
691 "fit produced non-finite camera coefficients");
692 require(std::all_of(mounting.begin(), mounting.end(),
693 [](
double value) { return std::isfinite(value); }),
694 "fit produced non-finite mounting coefficients");
710void write_profile(
const fs::path& path, cv::Size
size,
const cv::Mat& matrix,
711 const cv::Mat& distortion,
const std::array<double, 9>& mounting)
713 validate_outputs(matrix, distortion, mounting);
714 std::ofstream
output(path, std::ios::out | std::ios::trunc);
715 require(
output.is_open(),
"cannot write calibration profile: " + path.string());
716 output <<
"%YAML:1.0\n---\n" << std::setprecision(17);
717 output <<
"image_width: " <<
size.width <<
'\n';
718 output <<
"image_height: " <<
size.height <<
'\n';
719 output <<
"fx: " << matrix.at<
double>(0, 0) <<
'\n';
720 output <<
"fy: " << matrix.at<
double>(1, 1) <<
'\n';
721 output <<
"cx: " << matrix.at<
double>(0, 2) <<
'\n';
722 output <<
"cy: " << matrix.at<
double>(1, 2) <<
'\n';
723 const cv::Mat flat_distortion = distortion.reshape(1, 1);
724 static const std::array<const char*, 5> keys{{
"k1",
"k2",
"p1",
"p2",
"k3"}};
725 for (
int index = 0; index < 5; ++index) {
727 << flat_distortion.at<
double>(0, index) <<
'\n';
729 output << profile_verified_key <<
": 0\ncamera_to_body: [";
730 for (
size_t index = 0; index < mounting.size(); ++index) {
731 output << (index == 0 ?
" " :
", ") << mounting[index];
735 require(
output.good(),
"cannot finish calibration profile: " + path.string());
736 require(fs::file_size(path) > 0,
"calibration profile is empty: " + path.string());
749LensProfile read_lens_profile(
const fs::path& path)
751 cv::FileStorage input(path.string(), cv::FileStorage::READ);
752 require(input.isOpened(),
"cannot open lens profile: " + path.string());
753 const auto read_number = [&input, &path](
const char* key) {
754 const cv::FileNode node = input[key];
755 require(!node.empty() && (node.isInt() || node.isReal()),
756 std::string(
"missing or nonnumeric lens key: ") + key +
" in " + path.string());
759 require(std::isfinite(value), std::string(
"non-finite lens key: ") + key);
762 const double width_value = read_number(
"image_width");
763 const double height_value = read_number(
"image_height");
764 require(width_value >= 1 && width_value <= maximum_image_dimension
765 && height_value >= 1 && height_value <= maximum_image_dimension
766 && std::floor(width_value) == width_value && std::floor(height_value) == height_value,
767 "invalid lens-profile dimensions");
769 profile.image_size = cv::Size(
static_cast<int>(width_value),
static_cast<int>(height_value));
770 profile.camera_matrix = cv::Mat::eye(3, 3, CV_64F);
771 profile.camera_matrix.at<
double>(0, 0) = read_number(
"fx");
772 profile.camera_matrix.at<
double>(1, 1) = read_number(
"fy");
773 profile.camera_matrix.at<
double>(0, 2) = read_number(
"cx");
774 profile.camera_matrix.at<
double>(1, 2) = read_number(
"cy");
775 require(
profile.camera_matrix.at<
double>(0, 0) > 0 &&
profile.camera_matrix.at<
double>(1, 1) > 0,
776 "lens focal lengths must be positive");
777 profile.distortion = cv::Mat(1, 5, CV_64F);
778 static const std::array<const char*, 5> keys{{
"k1",
"k2",
"p1",
"p2",
"k3"}};
779 for (
int index = 0; index < 5; ++index) {
780 profile.distortion.at<
double>(0, index) = read_number(keys[
static_cast<size_t>(index)]);
799void fit_lens(
const Options&
options,
const OutputPaths& outputs, Report&
report)
801 const std::vector<cv::Point3f> board = board_points(
options.columns,
options.rows,
options.square_mm);
802 const std::vector<fs::path> paths = jpg_paths(
options.images);
803 std::vector<std::vector<cv::Point3f>> object_views;
804 std::vector<std::vector<cv::Point2f>> image_views;
805 std::vector<fs::path> accepted_paths;
807 for (
size_t index = 0; index < paths.size(); ++index) {
808 const cv::Mat gray = read_jpeg_gray(paths[index]);
809 const cv::Size current_size(gray.cols, gray.rows);
810 if (image_size.empty()) {
811 image_size = current_size;
813 require(image_size == current_size,
814 "mixed image dimensions at " + paths[index].
string() +
"; do not resize to force a match");
816 std::vector<cv::Point2f> corners;
817 if (!detect_board(gray,
options, corners)) {
818 report_line(
report,
"SKIPPED no complete pattern: " + paths[index].
string());
821 object_views.push_back(board);
822 image_views.push_back(corners);
823 accepted_paths.push_back(paths[index]);
824 std::ostringstream preview_name;
825 preview_name <<
"fit-" << std::setw(3) << std::setfill(
'0') << index <<
".jpg";
826 write_preview(gray, corners,
options, outputs.previews / preview_name.str(),
false);
828 require(object_views.size() >= minimum_fit_views,
829 "only " + std::to_string(object_views.size()) +
" complete patterns; need at least 15 varied views");
831 cv::Mat camera_matrix;
833 std::vector<cv::Mat> rotations;
834 std::vector<cv::Mat> translations;
835 const double rms = cv::calibrateCamera(object_views, image_views, image_size,
836 camera_matrix, distortion, rotations, translations);
837 require(std::isfinite(rms),
"lens fit produced non-finite RMS");
839 std::ostringstream line;
840 line << std::fixed << std::setprecision(6) <<
"Fitting RMS: " << rms
841 <<
" pixels; retained views: " << accepted_paths.size();
842 report_line(
report, line.str());
844 for (
size_t index = 0; index < accepted_paths.size(); ++index) {
845 std::ostringstream line;
846 line << std::fixed << std::setprecision(6) <<
"FIT "
847 << reprojection_rms(board, image_views[index], rotations[index], translations[index],
848 camera_matrix, distortion)
849 <<
" px: " << accepted_paths[index].string();
850 report_line(
report, line.str());
856 std::set<fs::path> fit_files;
857 for (
const fs::path& path : paths) {
858 fit_files.insert(fs::weakly_canonical(path));
860 size_t check_count = 0;
861 const std::vector<fs::path> check_paths = jpg_paths(
options.check);
862 for (
size_t index = 0; index < check_paths.size(); ++index) {
863 require(fit_files.count(fs::weakly_canonical(check_paths[index])) == 0,
864 "check images must be separate from fitting images: " + check_paths[index].string());
865 const cv::Mat gray = read_jpeg_gray(check_paths[index]);
866 require(cv::Size(gray.cols, gray.rows) == image_size,
867 "check-image dimensions differ: " + check_paths[index].string());
868 std::vector<cv::Point2f> corners;
869 if (!detect_board(gray,
options, corners)) {
870 report_line(
report,
"SKIPPED check pattern: " + check_paths[index].
string());
875 require(cv::solvePnP(board, corners, camera_matrix, distortion, rotation, translation),
876 "cannot estimate check-board pose: " + check_paths[index].
string());
877 std::ostringstream line;
878 line << std::fixed << std::setprecision(6) <<
"CHECK "
879 << reprojection_rms(board, corners, rotation, translation, camera_matrix, distortion)
880 <<
" px: " << check_paths[index].string();
881 report_line(
report, line.str());
883 std::ostringstream preview_name;
884 preview_name <<
"check-" << std::setw(3) << std::setfill(
'0') << index <<
".jpg";
885 write_preview(gray, corners,
options, outputs.previews / preview_name.str(),
false);
887 require(check_count >= minimum_check_views,
888 "only " + std::to_string(check_count) +
" complete check patterns; supply at least 5");
890 report_line(
report,
"WARNING: no independent check set supplied");
892 report_line(
report,
"Mounting is NOMINAL ONLY; physical axis measurement is still required.");
893 const std::array<double, 9> nominal_mounting{{0, -1, 0, 1, 0, 0, 0, 0, 1}};
894 write_profile(outputs.profile, image_size, camera_matrix, distortion, nominal_mounting);
913void fit_mount(
const Options&
options,
const OutputPaths& outputs, Report&
report)
915 const LensProfile lens = read_lens_profile(
options.lens);
916 const cv::Mat gray = read_jpeg_gray(
options.image);
917 require(cv::Size(gray.cols, gray.rows) == lens.image_size,
918 "mount image does not match lens-profile dimensions");
919 std::vector<cv::Point2f> corners;
920 require(detect_board(gray,
options, corners),
921 "no complete checker pattern; improve contrast, focus or framing");
924 std::reverse(corners.begin(), corners.end());
926 write_preview(gray, corners,
options, outputs.previews /
"mount-order.jpg",
true);
928 const std::vector<cv::Point3f> board = board_points(
options.columns,
options.rows,
options.square_mm);
929 std::vector<cv::Point3f> body_points;
930 body_points.reserve(board.size());
933 for (
const cv::Point3f&
point : board) {
938 require(cv::solvePnP(body_points, corners, lens.camera_matrix, lens.distortion, rotation, translation),
939 "mounting pose did not converge");
940 cv::Mat body_to_camera_mat;
941 cv::Rodrigues(rotation, body_to_camera_mat);
942 cv::Matx33d body_to_camera;
944 for (
int column = 0; column < 3; ++column) {
945 body_to_camera(
row, column) = body_to_camera_mat.at<
double>(
row, column);
949 for (
const cv::Point3f&
point : body_points) {
950 const cv::Vec3d camera_point = body_to_camera * cv::Vec3d(
point.x,
point.y,
point.z)
951 + cv::Vec3d(translation.at<
double>(0), translation.at<
double>(1),
952 translation.at<
double>(2));
953 require(camera_point[2] > 0.0,
"board pose lies behind the camera; check corner order");
957 const cv::Matx33d camera_to_body = body_to_camera.t();
958 std::array<double, 9> mounting{};
960 for (
int column = 0; column < 3; ++column) {
961 mounting[
static_cast<size_t>(3 *
row + column)] = camera_to_body(
row, column);
965 std::ostringstream line;
966 line << std::fixed << std::setprecision(6) <<
"Mount reprojection RMS: "
967 << reprojection_rms(body_points, corners, rotation, translation,
968 lens.camera_matrix, lens.distortion) <<
" pixels";
969 report_line(
report, line.str());
971 report_line(
report,
"ASSUMPTION: board columns point body-right; rows point toward tail; board is level with body datum.");
972 report_line(
report,
"CONFIRM preview labels 0, 1 and " + std::to_string(
options.columns)
973 +
" against the physical board; no automatic verification.");
975 const cv::Vec3d optical_axis(camera_to_body(0, 2), camera_to_body(1, 2), camera_to_body(2, 2));
976 std::ostringstream line;
977 line <<
"Optical axis in body forward/right/down: [" << optical_axis[0] <<
", "
978 << optical_axis[1] <<
", " << optical_axis[2] <<
"]";
979 report_line(
report, line.str());
981 write_profile(outputs.profile, lens.image_size, lens.camera_matrix, lens.distortion, mounting);
998 if (argc == 2 && (std::string(argv[1]) ==
"--version" || std::string(argv[1]) ==
"-V")) {
1002 if (argc == 2 && (std::string(argv[1]) ==
"--help" || std::string(argv[1]) ==
"-h")) {
1010 }
catch (
const UsageError&
error) {
1011 std::cerr <<
error.what() <<
'\n';
1014 }
catch (
const std::exception&
error) {
1015 std::cerr <<
error.what() <<
'\n';
1019 OutputPaths outputs;
1023 outputs = prepare_outputs(
options);
1025 if (
options.mode == Options::Mode::lens) {
1030 report_line(
report,
"Not automatically verified. Inspect evidence before using coordinates.");
1031 write_report(outputs.report,
report);
1032 std::cout <<
"Profile: " << outputs.profile <<
"\nReport: " << outputs.report
1033 <<
"\nPreviews: " << outputs.previews <<
'\n';
1035 }
catch (
const cv::Exception&
error) {
1036 report.push_back(std::string(
"STOP: ") +
error.what());
1037 }
catch (
const std::exception&
error) {
1038 report.push_back(std::string(
"STOP: ") +
error.what());
1041 std::error_code remove_error;
1044 if (!outputs.profile.empty()) {
1045 fs::remove(outputs.profile, remove_error);
1047 if (!outputs.report.empty()) {
1049 write_report(outputs.report,
report);
1054 std::cerr <<
report.back() <<
'\n';
1056 if (!outputs.report.empty()) {
1057 std::cerr <<
"Details: " << outputs.report <<
"\nChoose a new output filename on retry.\n";
static void report(const struct capture_intent *intent, unsigned camera_id, uint32_t outcome)
Record a terminal outcome without allowing telemetry backlog to block camera release.
RAII guard installing the backend at startup and joining workers before main() exits.
static bool parse_double(const char *text, double *value)
Parse a finite floating-point token in full.
static int parse_options(int argc, char **argv, struct options *options)
Parse and cross-validate EARcam command-line configuration.
static void print_usage(FILE *stream, const char *program)
Print command-line help or version-led usage text.
static void jpeg_message(j_common_ptr codec, int level)
Check JPEG marker bounds ahead of normal codec diagnostics.
Reject invalid Huffman selectors before the bundled codec indexes its tables.
static void usher_jpeg_validate_marker(j_common_ptr state)
Validate marker parameters from an error manager's emit_message callback.
int main(int argc, char **argv)
Run one workshop stage with distinct invocation and fitting failures.
struct jpeg_compress_struct encoder
uint8_t row[LWIR_MAX_WIDTH *3U]
static void jpeg_failure(j_common_ptr encoder)
libjpeg error_exit replacement: abandon the photo instead of exiting.
struct jpeg_error_mgr error
struct jpeg_decompress_struct decoder
static struct usher_camera_profile profile
Header-only C++17 cv::parallel::ParallelForAPI backend for Sensoraia.
static const char header[]
Compile-time build identity strings for USHER executables.
#define LWIR_CALIBRATE_BUILD_VERSION
Validated capture and reporting policy, fixed before the sample loop.
One timestamped geographic position for a replay annotation.
struct captured_image image