From bd45f4896375cc295c19d8e4f9b1ab5280152867 Mon Sep 17 00:00:00 2001 From: Philip Manke Date: Mon, 28 Sep 2026 16:59:38 +0200 Subject: [PATCH 1/5] Add reference spectra example; Bump cuvis.cpp submodule to v3.6.0 --- CMakeLists.txt | 5 +- .../CMakeLists.txt | 7 + Example_6_Reference_Spectra_cpp/main.cpp | 194 ++++++++++++++++++ .../run_Example_6_Reference_Spectra_cpp.sh | 23 +++ Example_7_Change_Distance_cpp/CMakeLists.txt | 7 - .../CMakeLists.txt | 8 +- .../main.cpp | 2 +- ...ple_7_Record_Video_From_SessionFile_cpp.sh | 0 Example_8_Change_Distance_cpp/CMakeLists.txt | 7 + .../main.cpp | 2 +- .../run_Example_8_Change_Distance_cpp.sh | 0 README.md | 7 +- cuvis.cpp | 2 +- 13 files changed, 246 insertions(+), 18 deletions(-) create mode 100644 Example_6_Reference_Spectra_cpp/CMakeLists.txt create mode 100644 Example_6_Reference_Spectra_cpp/main.cpp create mode 100644 Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh delete mode 100644 Example_7_Change_Distance_cpp/CMakeLists.txt rename {Example_6_Record_Video_From_SessionFile_cpp => Example_7_Record_Video_From_SessionFile_cpp}/CMakeLists.txt (55%) rename {Example_6_Record_Video_From_SessionFile_cpp => Example_7_Record_Video_From_SessionFile_cpp}/main.cpp (99%) rename Example_6_Record_Video_From_SessionFile_cpp/run_Example_6_Record_Video_From_SessionFile_cpp.sh => Example_7_Record_Video_From_SessionFile_cpp/run_Example_7_Record_Video_From_SessionFile_cpp.sh (100%) create mode 100644 Example_8_Change_Distance_cpp/CMakeLists.txt rename {Example_7_Change_Distance_cpp => Example_8_Change_Distance_cpp}/main.cpp (98%) rename Example_7_Change_Distance_cpp/run_Example_7_Change_Distance_cpp.sh => Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d8e41b..1f5dfea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,5 +5,6 @@ add_subdirectory(Example_2_Load_Measurement_cpp) add_subdirectory(Example_3_Reprocess_cpp) add_subdirectory(Example_4_Exporters_cpp) add_subdirectory(Example_5_Record_Video_cpp) -add_subdirectory(Example_6_Record_Video_From_SessionFile_cpp) -add_subdirectory(Example_7_Change_Distance_cpp) \ No newline at end of file +add_subdirectory(Example_6_Reference_Spectra_cpp) +add_subdirectory(Example_7_Record_Video_From_SessionFile_cpp) +add_subdirectory(Example_8_Change_Distance_cpp) \ No newline at end of file diff --git a/Example_6_Reference_Spectra_cpp/CMakeLists.txt b/Example_6_Reference_Spectra_cpp/CMakeLists.txt new file mode 100644 index 0000000..5e2e14c --- /dev/null +++ b/Example_6_Reference_Spectra_cpp/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.16.0) +project(Example_6_Reference_Spectra_cpp) +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_CURRENT_LIST_DIR}/../cuvis.cpp/") +find_package(CuvisCpp 3.6 REQUIRED) +add_executable(Example_6_Reference_Spectra_cpp main.cpp) +target_link_libraries(Example_6_Reference_Spectra_cpp PRIVATE cuvis::cpp) \ No newline at end of file diff --git a/Example_6_Reference_Spectra_cpp/main.cpp b/Example_6_Reference_Spectra_cpp/main.cpp new file mode 100644 index 0000000..2bdbbc4 --- /dev/null +++ b/Example_6_Reference_Spectra_cpp/main.cpp @@ -0,0 +1,194 @@ +#include "cuvis.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +/* +* Linearly interpolate a spectrum onto the cube's wavelengths, +* plus one 10nm step at both ends as a margin, so the spectrum safely covers the cube's full range +*/ +static void resample_to_cube(std::vector const& cubeWavelengths, std::vector const& srcWavelengths, + std::vector const& srcValues, std::vector& outWavelengths, std::vector& outValues) +{ + outWavelengths.assign(1, static_cast(cubeWavelengths.front()) - 10.0f); + for (std::uint32_t const wl : cubeWavelengths) + outWavelengths.push_back(static_cast(wl)); + outWavelengths.push_back(static_cast(cubeWavelengths.back()) + 10.0f); + + outValues.clear(); + for (float const wl : outWavelengths) + { + auto const upper = std::upper_bound(srcWavelengths.begin(), srcWavelengths.end(), wl); + if (upper == srcWavelengths.begin()) + outValues.push_back(srcValues.front()); + else if (upper == srcWavelengths.end()) + outValues.push_back(srcValues.back()); + else + { + auto const j = static_cast(upper - srcWavelengths.begin()) - 1; + double const t = (wl - srcWavelengths[j]) / (srcWavelengths[j + 1] - srcWavelengths[j]); + outValues.push_back(srcValues[j] + t * (srcValues[j + 1] - srcValues[j])); + } + } +} + +int main(int argc, char* argv[]) +{ + { + /* + * Reprocess a measurement with reference spectra + * + * Cuvis 3.6 adds two spectrum reference types to the *ProcessingContext*: + * - *TargetSpectrum*: Reflectance of the white target (fractions, 1.0 = 100%). Default without it: 100% at every wavelength. + * - *WhiteSpectrum*: Averaged white spectrum in raw sensor counts. Replaces the White reference measurement. + * + * The measurement is processed to reflectance with a target spectrum, then with a white spectrum. + * Each result is exported as a SessionFile including the cube. + * + * Used principles: + * - *SessionFile* to load a recorded measurement and its references + * - *ProcessingContext* with `set_reference_target_spectrum` and `set_reference_white_spectrum` + * - *CubeExporter* to save the results + * + * Prerequisites to running this example: + * - Have a recorded measurement in *SessionFile* format (.cu3s) that contains Dark and White references *or* downloaded the provided [demo data](https://cloud.cubert-gmbh.de/s/SDKSampleData) + * - Have the Cuvis SDK 3.6 or newer installed + * + * Run properties + * - "path/to/settings" "path/to/measurement/single.cu3s" "OutputFolderName" + */ + if (argc != 4) + { + std::cout << std::endl << "Too few Arguments! Please provide:" << std::endl; + std::cout << "user settings directory" << std::endl; + std::cout << "measurement file with Dark and White references (.cu3s)" << std::endl; + std::cout << "Name of output directory" << std::endl; + + return -1; + } + + char* const userSettingsDir = argv[1]; + char* const measurementLoc = argv[2]; + char* const outDir = argv[3]; + + std::cout << "Example 06 reference spectra cpp " << std::endl; + std::cout << "User Settings Dir: " << userSettingsDir << std::endl; + std::cout << "measurement file (.cu3s): " << measurementLoc << std::endl; + std::cout << "output Dir: " << outDir << std::endl; + + std::cout << "loading settings... " << std::endl; + cuvis::General::init(userSettingsDir); + cuvis::General::set_log_level(loglevel_info); + + // The ProcessingContext loads the Dark and White references stored in the SessionFile + std::cout << "Loading processing context" << std::endl; + cuvis::SessionFile sess(measurementLoc); + cuvis::ProcessingContext proc(sess); + cuvis::ProcessingArgs procArgs; + procArgs.processing_mode = cuvis::processing_mode_t::Cube_Reflectance; + proc.set_processingArgs(procArgs); + + cuvis::SaveArgs saveArgs; + saveArgs.allow_overwrite = true; + saveArgs.allow_info_file = false; + saveArgs.full_export = true; // include the reflectance cube in the export + + /* + * Process a fresh Measurement from the SessionFile with the current references and export it. + * Use a fresh Measurement for every reference configuration: processing with a reference spectrum stores it in the Measurement, + * and in Cuvis 3.6.0 a Measurement processed again after the spectrum was removed from the ProcessingContext keeps using it. + */ + auto process_and_export = [&](std::string const& name) { + auto optMesu = sess.get_mesu(0); + assert(optMesu.has_value()); + cuvis::Measurement mesu = optMesu.value(); + std::cout << "processing to reflectance with " << name << std::endl; + proc.apply(mesu); + saveArgs.export_dir = std::filesystem::path(outDir) / name; + cuvis::CubeExporter exporter(saveArgs); + exporter.apply(mesu); + }; + + // Raw cube of the White reference measurement: source of the white spectrum below and of the cube's wavelengths + auto optWhite = proc.get_reference(cuvis::reference_type_t::Reference_White); + assert(optWhite.has_value()); + cuvis::Measurement white = optWhite.value(); + + cuvis::ProcessingContext rawProc(sess); + cuvis::ProcessingArgs rawArgs; + rawArgs.processing_mode = cuvis::processing_mode_t::Cube_Raw; + rawProc.set_processingArgs(rawArgs); + rawProc.apply(white); + auto const& whiteCube = std::get>(white.get_imdata()->at(CUVIS_MESU_CUBE_KEY)); + std::vector const wavelengths(whiteCube._wavelength, whiteCube._wavelength + whiteCube._channels); + + /* + * Target Spectrum + * - Values are fractions (1.0 = 100%), wavelengths in nm. + * - The spectrum must cover the cube's entire wavelength range, otherwise processing fails. + * - Resample it onto the cube's wavelengths, so the SDK uses exactly the values you expect at every channel. + * - For a constant reflectivity, e.g. 95% (the constant reflectivity option of the Cuvis UI applications), + * set two points spanning the cube's range: wavelengths {first - 10, last + 10}, values {0.95, 0.95}. + */ + // Example certificate of a white target (illustrative values): wavelength [nm] and reflectance as fraction + std::vector const certificateWavelengths = {300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1100}; + std::vector const certificateReflectance = {0.80, 0.86, 0.91, 0.94, 0.95, 0.96, 0.96, 0.96, 0.95, 0.94, 0.93}; + + cuvis::target_spectrum_t target; + std::vector targetValues; + resample_to_cube(wavelengths, certificateWavelengths, certificateReflectance, target.wavelengths, targetValues); + for (double const value : targetValues) + target.values.push_back(static_cast(value)); + proc.set_reference_target_spectrum(target); + + process_and_export("TargetSpectrum"); + + proc.clear_reference(cuvis::reference_type_t::Reference_TargetSpectrum); + + /* + * White Spectrum + * - Raw sensor counts (uint16), wavelengths in nm, covering the cube's entire wavelength range. + * - `effective_bit_depth` (1 to 16) is required: the bit depth of the sensor's pixel format, e.g. 12 for Mono12Packed. + * - `integration_time` [ms]: record the white spectrum with the same integration time as the measurements. + * - White spectrum and White reference measurement are mutually exclusive: setting one clears the other. + * + * Limitation: A white spectrum is applied to the whole image equally and does not correct spatial effects, + * like lens vignetting or uneven illumination, as a White reference measurement does. + * This is an intended limitation of the current implementation, the first iteration of this feature: + * some cameras allow exchanging the objective, which makes a fixed, calibrated spatial correction invalid in some cases. + * For spatially accurate reflectance across the whole image, use a White reference measurement. + */ + // Average the raw counts over a 40 x 40 pixel region in the image center + std::size_t const cx = whiteCube._width / 2; + std::size_t const cy = whiteCube._height / 2; + std::vector whiteCounts(whiteCube._channels, 0.0); + for (std::size_t y = cy - 20; y < cy + 20; y++) + for (std::size_t x = cx - 20; x < cx + 20; x++) + for (std::size_t chn = 0; chn < whiteCube._channels; chn++) + whiteCounts[chn] += whiteCube.get(x, y, chn) / 1600.0; + + cuvis::sensor_spectrum_t whiteSpectrum; + std::vector whiteValues; + resample_to_cube(wavelengths, std::vector(wavelengths.begin(), wavelengths.end()), whiteCounts, + whiteSpectrum.wavelengths, whiteValues); + for (double const value : whiteValues) + whiteSpectrum.values.push_back(static_cast(std::nearbyint(value))); + + std::string const pixelFormat = white.get_sensor_info()->at("IMAGE_info").pixel_format; + whiteSpectrum.effective_bit_depth = + static_cast(std::stoi(pixelFormat.substr(pixelFormat.find_first_of("0123456789")))); + whiteSpectrum.integration_time = white.get_meta()->integration_time; + proc.set_reference_white_spectrum(whiteSpectrum); + + process_and_export("WhiteSpectrum"); + } + cuvis::General::shutdown(); + std::cout << "finished." << std::endl; + return 0; +} diff --git a/Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh b/Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh new file mode 100644 index 0000000..7d04709 --- /dev/null +++ b/Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Usage: +# example app path [string] E.g. ./Example_6_Reference_Spectra_cpp.exe for windows or ./Example_6_Reference_Spectra_cpp for linux +# user settings directory [string] Default is ../settings +# sessionfile (.cu3s) [string] Default is ../sample_data/WinterUlm_X20P.cu3s (demo data, must contain Dark and White references) +# name of output directory [string] The name of your output folder relative to the example app path + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + ##########LINUX########## + ./Example_6_Reference_Spectra_cpp \ + "../settings" \ + "../sample_data/WinterUlm_X20P.cu3s" \ + "reference_spectra" \ + +else + ##########WINDOWS########## + ./Example_6_Reference_Spectra_cpp.exe \ + "../settings" \ + "../sample_data/WinterUlm_X20P.cu3s" \ + "reference_spectra" \ + +fi diff --git a/Example_7_Change_Distance_cpp/CMakeLists.txt b/Example_7_Change_Distance_cpp/CMakeLists.txt deleted file mode 100644 index 2736124..0000000 --- a/Example_7_Change_Distance_cpp/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.16.0) -project(Example_7_Change_Distance_cpp) -list(APPEND CMAKE_MODULE_PATH - "${CMAKE_CURRENT_LIST_DIR}/../cuvis.cpp/") -find_package(CuvisCpp 3.5 REQUIRED) -add_executable(Example_7_Change_Distance_cpp main.cpp) -target_link_libraries(Example_7_Change_Distance_cpp PRIVATE cuvis::cpp) \ No newline at end of file diff --git a/Example_6_Record_Video_From_SessionFile_cpp/CMakeLists.txt b/Example_7_Record_Video_From_SessionFile_cpp/CMakeLists.txt similarity index 55% rename from Example_6_Record_Video_From_SessionFile_cpp/CMakeLists.txt rename to Example_7_Record_Video_From_SessionFile_cpp/CMakeLists.txt index 1d790a1..2e1c5f1 100644 --- a/Example_6_Record_Video_From_SessionFile_cpp/CMakeLists.txt +++ b/Example_7_Record_Video_From_SessionFile_cpp/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16.0) -project(Example_6_Record_Video_From_SessionFile_cpp) +project(Example_7_Record_Video_From_SessionFile_cpp) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cuvis.cpp/") find_package(CuvisCpp 3.5 REQUIRED) @@ -7,9 +7,9 @@ if (UNIX) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) endif() -add_executable(Example_6_Record_Video_From_SessionFile_cpp main.cpp) -target_link_libraries(Example_6_Record_Video_From_SessionFile_cpp PRIVATE cuvis::cpp) +add_executable(Example_7_Record_Video_From_SessionFile_cpp main.cpp) +target_link_libraries(Example_7_Record_Video_From_SessionFile_cpp PRIVATE cuvis::cpp) if (UNIX) - target_link_libraries(Example_6_Record_Video_From_SessionFile_cpp PRIVATE Threads::Threads) + target_link_libraries(Example_7_Record_Video_From_SessionFile_cpp PRIVATE Threads::Threads) endif() \ No newline at end of file diff --git a/Example_6_Record_Video_From_SessionFile_cpp/main.cpp b/Example_7_Record_Video_From_SessionFile_cpp/main.cpp similarity index 99% rename from Example_6_Record_Video_From_SessionFile_cpp/main.cpp rename to Example_7_Record_Video_From_SessionFile_cpp/main.cpp index a012301..127e4bf 100644 --- a/Example_6_Record_Video_From_SessionFile_cpp/main.cpp +++ b/Example_7_Record_Video_From_SessionFile_cpp/main.cpp @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) bool autoExp = std::stoi(autoExpString); double fps = std::stod(fpsString); - std::cout << "Example 06 video from SessionFile cpp " << std::endl; + std::cout << "Example 07 video from SessionFile cpp " << std::endl; std::cout << "User Settings Dir: " << userSettingsDir << std::endl; std::cout << "Sessionfile: " << sessionfile << std::endl; std::cout << "Recording Dir: " << recDir << std::endl; diff --git a/Example_6_Record_Video_From_SessionFile_cpp/run_Example_6_Record_Video_From_SessionFile_cpp.sh b/Example_7_Record_Video_From_SessionFile_cpp/run_Example_7_Record_Video_From_SessionFile_cpp.sh similarity index 100% rename from Example_6_Record_Video_From_SessionFile_cpp/run_Example_6_Record_Video_From_SessionFile_cpp.sh rename to Example_7_Record_Video_From_SessionFile_cpp/run_Example_7_Record_Video_From_SessionFile_cpp.sh diff --git a/Example_8_Change_Distance_cpp/CMakeLists.txt b/Example_8_Change_Distance_cpp/CMakeLists.txt new file mode 100644 index 0000000..62362a8 --- /dev/null +++ b/Example_8_Change_Distance_cpp/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.16.0) +project(Example_8_Change_Distance_cpp) +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_CURRENT_LIST_DIR}/../cuvis.cpp/") +find_package(CuvisCpp 3.5 REQUIRED) +add_executable(Example_8_Change_Distance_cpp main.cpp) +target_link_libraries(Example_8_Change_Distance_cpp PRIVATE cuvis::cpp) \ No newline at end of file diff --git a/Example_7_Change_Distance_cpp/main.cpp b/Example_8_Change_Distance_cpp/main.cpp similarity index 98% rename from Example_7_Change_Distance_cpp/main.cpp rename to Example_8_Change_Distance_cpp/main.cpp index a0f33aa..83abef8 100644 --- a/Example_7_Change_Distance_cpp/main.cpp +++ b/Example_8_Change_Distance_cpp/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char* argv[]) int distance = std::stoi(distanceString); - std::cout << "Example 07 change distance cpp " << std::endl; + std::cout << "Example 08 change distance cpp " << std::endl; std::cout << "User Settings Dir: " << userSettingsDir << std::endl; std::cout << "sessionfile (.cu3s): " << sessionLoc << std::endl; std::cout << "New Distance in mm: " << distance << std::endl; diff --git a/Example_7_Change_Distance_cpp/run_Example_7_Change_Distance_cpp.sh b/Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh similarity index 100% rename from Example_7_Change_Distance_cpp/run_Example_7_Change_Distance_cpp.sh rename to Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh diff --git a/README.md b/README.md index 944b852..1256be7 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,11 @@ Load measurement from disk and save to different file formats. ### Example_5_Record_Video Setup camera and record measurements via internal clock triggering, aka "video mode". In this example the `cuvis.Worker` is used to make use of multithreading (`cuvis_worker_create`). -### Example_6_Record_Video_From_SessionFile +### Example_6_Reference_Spectra +Load measurement from disk and reprocess to reflectance with a target spectrum and with a white spectrum (reference spectra, requires Cuvis 3.6). + +### Example_7_Record_Video_From_SessionFile Set up a virtual camera based on a pre-recorded session file to simulate actual camera behaviour. -### Example_7_Change_Distance +### Example_8_Change_Distance Load measurement from disk and reprocess to a new given distance. diff --git a/cuvis.cpp b/cuvis.cpp index ecc9bab..1f86a7c 160000 --- a/cuvis.cpp +++ b/cuvis.cpp @@ -1 +1 @@ -Subproject commit ecc9babdbb5ec81f457431348acc2769df494182 +Subproject commit 1f86a7cde96bf57b20d4526a247fc8d7a0bed730 From 1d70193c8ce9e31764933be8b4c7ca1cfa09d30d Mon Sep 17 00:00:00 2001 From: Philip Manke Date: Tue, 13 Oct 2026 17:36:06 +0200 Subject: [PATCH 2/5] Update for 3.6.1 --- Example_6_Reference_Spectra_cpp/main.cpp | 86 ++++++++---------------- 1 file changed, 27 insertions(+), 59 deletions(-) diff --git a/Example_6_Reference_Spectra_cpp/main.cpp b/Example_6_Reference_Spectra_cpp/main.cpp index 2bdbbc4..1ae421d 100644 --- a/Example_6_Reference_Spectra_cpp/main.cpp +++ b/Example_6_Reference_Spectra_cpp/main.cpp @@ -1,6 +1,5 @@ #include "cuvis.hpp" -#include #include #include #include @@ -9,35 +8,6 @@ #include #include -/* -* Linearly interpolate a spectrum onto the cube's wavelengths, -* plus one 10nm step at both ends as a margin, so the spectrum safely covers the cube's full range -*/ -static void resample_to_cube(std::vector const& cubeWavelengths, std::vector const& srcWavelengths, - std::vector const& srcValues, std::vector& outWavelengths, std::vector& outValues) -{ - outWavelengths.assign(1, static_cast(cubeWavelengths.front()) - 10.0f); - for (std::uint32_t const wl : cubeWavelengths) - outWavelengths.push_back(static_cast(wl)); - outWavelengths.push_back(static_cast(cubeWavelengths.back()) + 10.0f); - - outValues.clear(); - for (float const wl : outWavelengths) - { - auto const upper = std::upper_bound(srcWavelengths.begin(), srcWavelengths.end(), wl); - if (upper == srcWavelengths.begin()) - outValues.push_back(srcValues.front()); - else if (upper == srcWavelengths.end()) - outValues.push_back(srcValues.back()); - else - { - auto const j = static_cast(upper - srcWavelengths.begin()) - 1; - double const t = (wl - srcWavelengths[j]) / (srcWavelengths[j + 1] - srcWavelengths[j]); - outValues.push_back(srcValues[j] + t * (srcValues[j + 1] - srcValues[j])); - } - } -} - int main(int argc, char* argv[]) { { @@ -45,8 +15,8 @@ int main(int argc, char* argv[]) * Reprocess a measurement with reference spectra * * Cuvis 3.6 adds two spectrum reference types to the *ProcessingContext*: - * - *TargetSpectrum*: Reflectance of the white target (fractions, 1.0 = 100%). Default without it: 100% at every wavelength. - * - *WhiteSpectrum*: Averaged white spectrum in raw sensor counts. Replaces the White reference measurement. + * - *TargetSpectrum*: Reflectance of the white target (fractions, 1.0 = 100%). Default without it: 100% at every wavelength, or the white_target_reflectivity_percentage setting. + * - *WhiteSpectrum*: Averaged white spectrum in dark-corrected sensor counts. Replaces the White reference measurement. * * The measurement is processed to reflectance with a target spectrum, then with a white spectrum. * Each result is exported as a SessionFile including the cube. @@ -101,8 +71,6 @@ int main(int argc, char* argv[]) /* * Process a fresh Measurement from the SessionFile with the current references and export it. - * Use a fresh Measurement for every reference configuration: processing with a reference spectrum stores it in the Measurement, - * and in Cuvis 3.6.0 a Measurement processed again after the spectrum was removed from the ProcessingContext keeps using it. */ auto process_and_export = [&](std::string const& name) { auto optMesu = sess.get_mesu(0); @@ -115,36 +83,32 @@ int main(int argc, char* argv[]) exporter.apply(mesu); }; - // Raw cube of the White reference measurement: source of the white spectrum below and of the cube's wavelengths + // Dark Subtract cube of the White reference measurement: source of the white spectrum below auto optWhite = proc.get_reference(cuvis::reference_type_t::Reference_White); assert(optWhite.has_value()); cuvis::Measurement white = optWhite.value(); - cuvis::ProcessingContext rawProc(sess); - cuvis::ProcessingArgs rawArgs; - rawArgs.processing_mode = cuvis::processing_mode_t::Cube_Raw; - rawProc.set_processingArgs(rawArgs); - rawProc.apply(white); + cuvis::ProcessingContext darkSubProc(sess); + cuvis::ProcessingArgs darkSubArgs; + darkSubArgs.processing_mode = cuvis::processing_mode_t::Cube_DarkSubtract; + darkSubProc.set_processingArgs(darkSubArgs); + darkSubProc.apply(white); auto const& whiteCube = std::get>(white.get_imdata()->at(CUVIS_MESU_CUBE_KEY)); - std::vector const wavelengths(whiteCube._wavelength, whiteCube._wavelength + whiteCube._channels); /* * Target Spectrum * - Values are fractions (1.0 = 100%), wavelengths in nm. * - The spectrum must cover the cube's entire wavelength range, otherwise processing fails. - * - Resample it onto the cube's wavelengths, so the SDK uses exactly the values you expect at every channel. - * - For a constant reflectivity, e.g. 95% (the constant reflectivity option of the Cuvis UI applications), - * set two points spanning the cube's range: wavelengths {first - 10, last + 10}, values {0.95, 0.95}. + * - The SDK interpolates linearly between the points; they do not need to match the cube's wavelengths. + * - For a constant reflectivity, e.g. 95% (the constant reflectivity option of CuvisNEXT), + * set two points spanning the cube's range: the cube's first and last wavelength, values {0.95, 0.95}. + * Alternatively, `white_target_reflectivity_percentage` in cuvis.settings sets it for all processing (default 100); + * an explicitly set target spectrum overrides it. */ // Example certificate of a white target (illustrative values): wavelength [nm] and reflectance as fraction - std::vector const certificateWavelengths = {300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1100}; - std::vector const certificateReflectance = {0.80, 0.86, 0.91, 0.94, 0.95, 0.96, 0.96, 0.96, 0.95, 0.94, 0.93}; - cuvis::target_spectrum_t target; - std::vector targetValues; - resample_to_cube(wavelengths, certificateWavelengths, certificateReflectance, target.wavelengths, targetValues); - for (double const value : targetValues) - target.values.push_back(static_cast(value)); + target.wavelengths = {300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1100}; + target.values = {0.80f, 0.86f, 0.91f, 0.94f, 0.95f, 0.96f, 0.96f, 0.96f, 0.95f, 0.94f, 0.93f}; proc.set_reference_target_spectrum(target); process_and_export("TargetSpectrum"); @@ -153,9 +117,13 @@ int main(int argc, char* argv[]) /* * White Spectrum - * - Raw sensor counts (uint16), wavelengths in nm, covering the cube's entire wavelength range. + * - Dark-corrected sensor counts (uint16), wavelengths in nm, covering the cube's entire wavelength range. * - `effective_bit_depth` (1 to 16) is required: the bit depth of the sensor's pixel format, e.g. 12 for Mono12Packed. - * - `integration_time` [ms]: record the white spectrum with the same integration time as the measurements. + * - `integration_time` [ms]: not used by default (`correct_ref_integration_time="false"` in cuvis.settings), + * so record the white spectrum with the same integration time as the measurements. + * With "true", the reflectance is scaled by white spectrum integration time / measurement integration time. + * - Channels with 0 counts (demo data: 350-358 nm) give no meaningful reflectance: + * setting such a spectrum logs a warning, and processing flags the cube as white-dark underflow. * - White spectrum and White reference measurement are mutually exclusive: setting one clears the other. * * Limitation: A white spectrum is applied to the whole image equally and does not correct spatial effects, @@ -164,7 +132,7 @@ int main(int argc, char* argv[]) * some cameras allow exchanging the objective, which makes a fixed, calibrated spatial correction invalid in some cases. * For spatially accurate reflectance across the whole image, use a White reference measurement. */ - // Average the raw counts over a 40 x 40 pixel region in the image center + // Average the dark-corrected counts over a 40 x 40 pixel region in the image center std::size_t const cx = whiteCube._width / 2; std::size_t const cy = whiteCube._height / 2; std::vector whiteCounts(whiteCube._channels, 0.0); @@ -174,11 +142,11 @@ int main(int argc, char* argv[]) whiteCounts[chn] += whiteCube.get(x, y, chn) / 1600.0; cuvis::sensor_spectrum_t whiteSpectrum; - std::vector whiteValues; - resample_to_cube(wavelengths, std::vector(wavelengths.begin(), wavelengths.end()), whiteCounts, - whiteSpectrum.wavelengths, whiteValues); - for (double const value : whiteValues) - whiteSpectrum.values.push_back(static_cast(std::nearbyint(value))); + for (std::size_t chn = 0; chn < whiteCube._channels; chn++) + { + whiteSpectrum.wavelengths.push_back(static_cast(whiteCube._wavelength[chn])); + whiteSpectrum.values.push_back(static_cast(std::nearbyint(whiteCounts[chn]))); + } std::string const pixelFormat = white.get_sensor_info()->at("IMAGE_info").pixel_format; whiteSpectrum.effective_bit_depth = From 7c0b2608a4c81612cd21e681b6bfa5f7befd181a Mon Sep 17 00:00:00 2001 From: Philip Manke Date: Tue, 13 Oct 2026 17:40:26 +0200 Subject: [PATCH 3/5] Update readme wording --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1256be7..9d71762 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Load measurement from disk and save to different file formats. Setup camera and record measurements via internal clock triggering, aka "video mode". In this example the `cuvis.Worker` is used to make use of multithreading (`cuvis_worker_create`). ### Example_6_Reference_Spectra -Load measurement from disk and reprocess to reflectance with a target spectrum and with a white spectrum (reference spectra, requires Cuvis 3.6). +Load measurement from disk and reprocess to reflectance with a target spectrum and with a white spectrum. ### Example_7_Record_Video_From_SessionFile Set up a virtual camera based on a pre-recorded session file to simulate actual camera behaviour. From 4d328f20b1d0482a562bf0678d0f59bd5a82286a Mon Sep 17 00:00:00 2001 From: Philip Manke Date: Fri, 6 Nov 2026 16:44:46 +0100 Subject: [PATCH 4/5] Update examples, example data used and run scripts --- Example_1_Take_Snapshot_cpp/main.cpp | 1 + .../run_Example_1_Take_Snapshot_cpp.sh | 8 +-- Example_2_Load_Measurement_cpp/main.cpp | 10 ++++ .../run_Example_2_Load_Measurement_cpp.sh | 18 +++---- Example_3_Reprocess_cpp/main.cpp | 28 ++++++++--- .../run_Example_3_Reprocess_cpp.sh | 38 +++++++------- Example_4_Exporters_cpp/main.cpp | 49 ++++++++++++++++--- .../run_Example_4_Exporters_cpp.sh | 29 ++++++----- Example_5_Record_Video_cpp/main.cpp | 1 + .../run_Example_5_Record_Video_cpp.sh | 8 +-- .../CMakeLists.txt | 2 +- Example_6_Reference_Spectra_cpp/main.cpp | 4 +- .../run_Example_6_Reference_Spectra_cpp.sh | 6 +-- .../main.cpp | 1 + ...ple_7_Record_Video_From_SessionFile_cpp.sh | 20 ++++---- Example_8_Change_Distance_cpp/main.cpp | 18 +++++-- .../run_Example_8_Change_Distance_cpp.sh | 20 ++++---- README.md | 2 +- SDK_Training_Example_Data/.gitkeep | 0 19 files changed, 170 insertions(+), 93 deletions(-) create mode 100644 SDK_Training_Example_Data/.gitkeep diff --git a/Example_1_Take_Snapshot_cpp/main.cpp b/Example_1_Take_Snapshot_cpp/main.cpp index 70ddc6f..99968e5 100644 --- a/Example_1_Take_Snapshot_cpp/main.cpp +++ b/Example_1_Take_Snapshot_cpp/main.cpp @@ -107,6 +107,7 @@ int main(int argc, char* argv[]) saveArgs.allow_overwrite = true; saveArgs.export_dir = recDir; saveArgs.allow_session_file = true; + saveArgs.full_export = false; // do not include the cube in the export // Setup the Cube Exporter for saving the measurements to disk in the SessionFile format(.cu3s) cuvis::CubeExporter exporter(saveArgs); diff --git a/Example_1_Take_Snapshot_cpp/run_Example_1_Take_Snapshot_cpp.sh b/Example_1_Take_Snapshot_cpp/run_Example_1_Take_Snapshot_cpp.sh index 4243e96..35ebe48 100644 --- a/Example_1_Take_Snapshot_cpp/run_Example_1_Take_Snapshot_cpp.sh +++ b/Example_1_Take_Snapshot_cpp/run_Example_1_Take_Snapshot_cpp.sh @@ -1,16 +1,16 @@ #!/bin/bash # Usage: -# example app path [string] E.g. ./05_recordSingleImages_cpp.exe for windows or ./05_recordSingleImages_cpp for linux +# example app path [string] E.g. ./Example_1_Take_Snapshot_cpp.exe for windows or ./Example_1_Take_Snapshot_cpp for linux # user settings directory [string] Default is C:/Program Files/cuvis/user/settings for windows or /etc/cuvis/user/settings for linux # factory directory [string] Default is C:/Program Files/cuvis/factory for windows or /etc/cuvis/factory for linux -# name of recording directory [string] The name of your recording folder realtive to the example app path +# name of recording directory [string] The name of your recording folder relative to the example app path # exposure time [int ] exposure (integration) time in ms # number of images to record [int ] the number of images you want to record if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## - ./05_recordSingleImages_cpp \ + ./Example_1_Take_Snapshot_cpp \ "/etc/cuvis/user/settings" \ "/etc/cuvis/factory" \ "images" \ @@ -19,7 +19,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then else ##########WINDOWS########## - ./05_recordSingleImages_cpp.exe \ + ./Example_1_Take_Snapshot_cpp.exe \ "C:/Program Files/cuvis/user/settings" \ "C:/Program Files/cuvis/factory" \ "images" \ diff --git a/Example_2_Load_Measurement_cpp/main.cpp b/Example_2_Load_Measurement_cpp/main.cpp index 7ea2c80..9583d51 100644 --- a/Example_2_Load_Measurement_cpp/main.cpp +++ b/Example_2_Load_Measurement_cpp/main.cpp @@ -101,6 +101,16 @@ int main(int argc, char* argv[]) } } + // SessionFiles are saved without the cube by default (Preview mode): compute it now (ProcessingContext, see Example 3) + if (mesu.get_meta()->processing_mode == cuvis::processing_mode_t::Preview) + { + cuvis::ProcessingContext proc(sess); + cuvis::ProcessingArgs procArgs; + procArgs.processing_mode = cuvis::processing_mode_t::Cube_Raw; + proc.set_processingArgs(procArgs); + proc.apply(mesu); + } + assert( mesu.get_meta()->processing_mode == Cube_Raw && "This example requires raw mode"); diff --git a/Example_2_Load_Measurement_cpp/run_Example_2_Load_Measurement_cpp.sh b/Example_2_Load_Measurement_cpp/run_Example_2_Load_Measurement_cpp.sh index 8c47167..c75b26f 100644 --- a/Example_2_Load_Measurement_cpp/run_Example_2_Load_Measurement_cpp.sh +++ b/Example_2_Load_Measurement_cpp/run_Example_2_Load_Measurement_cpp.sh @@ -1,20 +1,20 @@ #!/bin/bash # Usage: -# example app path [string] E.g. ./01_loadMeasurement_cpp.exe for windows or ./01_loadMeasurement_cpp for linux -# user settings directory [string] Default is ../../../sample_data/set_examples/settings -# sessionfile (.cu3s) [string] Default is ../../../sample_data/set_examples/set0_single/single.cu3s +# example app path [string] E.g. ./Example_2_Load_Measurement_cpp.exe for windows or ./Example_2_Load_Measurement_cpp for linux +# user settings directory [string] Default is ../settings +# sessionfile (.cu3s) [string] Default is ../SDK_Training_Example_Data/single_raw.cu3s (demo data, Ultris X20) if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## - ./01_loadMeasurement_cpp \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single.cu3s" \ + ./Example_2_Load_Measurement_cpp \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ else ##########WINDOWS########## - ./01_loadMeasurement_cpp.exe \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single.cu3s" \ + ./Example_2_Load_Measurement_cpp.exe \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ fi diff --git a/Example_3_Reprocess_cpp/main.cpp b/Example_3_Reprocess_cpp/main.cpp index f3bf626..423a46d 100644 --- a/Example_3_Reprocess_cpp/main.cpp +++ b/Example_3_Reprocess_cpp/main.cpp @@ -91,30 +91,43 @@ int main(int argc, char* argv[]) std::cout << "loading dark... " << std::endl; cuvis::SessionFile sessDark(darkLoc); - auto optDark = sessDark.get_mesu(0); + // use the reference stored in the file (e.g. the demo data), otherwise its first measurement + auto optDark = sessDark.get_ref(0, cuvis::reference_type_t::Reference_Dark); + if (!optDark.has_value()) + { + optDark = sessDark.get_mesu(0); + } assert(optDark.has_value()); cuvis::Measurement dark = optDark.value(); std::cout << "loading white... " << std::endl; cuvis::SessionFile sessWhite(whiteLoc); - auto optWhite = sessWhite.get_mesu(0); + auto optWhite = sessWhite.get_ref(0, cuvis::reference_type_t::Reference_White); + if (!optWhite.has_value()) + { + optWhite = sessWhite.get_mesu(0); + } assert(optWhite.has_value()); cuvis::Measurement white = optWhite.value(); /* * Distance Calibration - * Most Ultris cameras(except for Relay - variants) require distance calibration to achieve optimal results. + * Most Ultris cameras (except for relay variants) require distance calibration to achieve optimal results. * - * ** Please note : **The provided default demo dataset was recorded with a relay - equipped camera(Ultris XM with relay optics).Thus this step is not applicable to this dataset. + * Please note: Distance calibration is not supported for R models (relay optics, e.g. Ultris XMR) and P models (pan sensor, e.g. Ultris X20P). * * Distance calibration is an operation that can be done with already recorded data and requires a distance reference measurement. - * The reference should contain high - contrast data over the relevant spectral channels at the desired distance that data should be calibrated to. + * The reference should contain high-contrast data over the relevant spectral channels at the desired distance that data should be calibrated to. * - * In this example, the measurement itself will be used as the distance reference.If the target object is suitable(high contrast, non - repeating patterns), this can suffice for good results. + * In this example, the distance reference stored in the distance file is used, otherwise its first measurement. If the target object is suitable (high contrast, non-repeating patterns), the measurement itself can suffice for good results. */ std::cout << "loading distance... " << std::endl; cuvis::SessionFile sessDistance(distanceLoc); - auto optDistance = sessDistance.get_mesu(0); + auto optDistance = sessDistance.get_ref(0, cuvis::reference_type_t::Reference_Distance); + if (!optDistance.has_value()) + { + optDistance = sessDistance.get_mesu(0); + } assert(optDistance.has_value()); cuvis::Measurement distance = optDistance.value(); @@ -149,6 +162,7 @@ int main(int argc, char* argv[]) saveArgs.allow_overwrite = true; saveArgs.allow_session_file = true; saveArgs.allow_info_file = false; + saveArgs.full_export = false; // do not include the cube in the export std::map target_modes = { {"Raw", cuvis::processing_mode_t::Cube_Raw}, diff --git a/Example_3_Reprocess_cpp/run_Example_3_Reprocess_cpp.sh b/Example_3_Reprocess_cpp/run_Example_3_Reprocess_cpp.sh index f100527..3a5f89a 100644 --- a/Example_3_Reprocess_cpp/run_Example_3_Reprocess_cpp.sh +++ b/Example_3_Reprocess_cpp/run_Example_3_Reprocess_cpp.sh @@ -1,32 +1,32 @@ #!/bin/bash # Usage: -# example app path [string] E.g. .02_reprocessMeasurement.exe for windows or ./02_reprocessMeasurement_cpp for linux -# user settings directory [string] Default is ../../../sample_data/set_examples/settings -# measurement file (.cu3s) [string] Default is ../../../sample_data/set0_single/single_raw.cu3s -# dark file (.cu3s) [string] Default is ../../../sample_data/set0_single/single_dark.cu3s -# white file (.cu3s) [string] Default is ../../../sample_data/set0_single/single_white.cu3s -# distance file (.cu3s) [string] Default is ../../../sample_data/set0_single/single_distance.cu3s -# name of output directory [string] The name of your output folder realtive to the example app path +# example app path [string] E.g. ./Example_3_Reprocess_cpp.exe for windows or ./Example_3_Reprocess_cpp for linux +# user settings directory [string] Default is ../settings +# measurement file (.cu3s) [string] Default is ../SDK_Training_Example_Data/single_raw.cu3s (demo data, Ultris X20) +# dark file (.cu3s) [string] Default is ../SDK_Training_Example_Data/single_raw.cu3s +# white file (.cu3s) [string] Default is ../SDK_Training_Example_Data/single_raw.cu3s +# distance file (.cu3s) [string] Default is ../SDK_Training_Example_Data/single_raw.cu3s +# name of output directory [string] The name of your output folder relative to the example app path if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## - ./02_reprocessMeasurement_cpp \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single_raw.cu3s" \ - "../../../sample_data/set_examples/set0_single/single_dark.cu3s" \ - "../../../sample_data/set_examples/set0_single/single_white.cu3s" \ - "../../../sample_data/set_examples/set0_single/single_distance.cu3s" \ + ./Example_3_Reprocess_cpp \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ "reprocessed" \ else ##########WINDOWS########## - ./02_reprocessMeasurement_cpp.exe \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single_raw.cu3s" \ - "../../../sample_data/set_examples/set0_single/single_dark.cu3s" \ - "../../../sample_data/set_examples/set0_single/single_white.cu3s" \ - "../../../sample_data/set_examples/set0_single/single_distance.cu3s" \ + ./Example_3_Reprocess_cpp.exe \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ "reprocessed" \ fi diff --git a/Example_4_Exporters_cpp/main.cpp b/Example_4_Exporters_cpp/main.cpp index f2961a9..184eabc 100644 --- a/Example_4_Exporters_cpp/main.cpp +++ b/Example_4_Exporters_cpp/main.cpp @@ -25,13 +25,14 @@ int main(int argc, char* argv[]) * - Have the Cuvis SDK installed * * Run properties - * - "path/to/settings" path/to/measurement/single.cu3s" "path/to/user/plugin/file.xml" "OutputFolderName" + * - "path/to/settings" "path/to/measurement/file.cu3s" measurementIndex "path/to/user/plugin/file.xml" "OutputFolderName" */ - if (argc != 5) + if (argc != 6) { std::cout << std::endl << "Too few Arguments! Please provide:" << std::endl; std::cout << "user settings directory" << std::endl; std::cout << "sessionfile (.cu3s)" << std::endl; + std::cout << "measurement index" << std::endl; std::cout << "user plugin file (.xml)" << std::endl; std::cout << "Name of export directory" << std::endl; @@ -39,12 +40,14 @@ int main(int argc, char* argv[]) } char* const userSettingsDir = argv[1]; char* const sessionLoc = argv[2]; - char* const pluginLoc = argv[3]; - char* const exportDir = argv[4]; + int const mesuIndex = std::stoi(argv[3]); + char* const pluginLoc = argv[4]; + char* const exportDir = argv[5]; std::cout << "Example 04 export measurement" << std::endl; std::cout << "User Settings Dir: " << userSettingsDir << std::endl; std::cout << "sessionfile (.cu3s): " << sessionLoc << std::endl; + std::cout << "measurement index: " << mesuIndex << std::endl; std::cout << "user plugin file (.xml): " << pluginLoc << std::endl; std::cout << "Export Dir: " << exportDir << std::endl; @@ -56,11 +59,19 @@ int main(int argc, char* argv[]) cuvis::SessionFile sess(sessionLoc); std::cout << "loading measurement... " << std::endl; - auto optmesu = sess.get_mesu(0); + auto optmesu = sess.get_mesu(mesuIndex); assert(optmesu.has_value()); cuvis::Measurement mesu = optmesu.value(); - assert(mesu.get_meta()->processing_mode != cuvis::processing_mode_t::Preview); + // the exporters need a cube: SessionFiles are saved without it by default (Preview mode), so compute it now + if (mesu.get_meta()->processing_mode == cuvis::processing_mode_t::Preview) + { + cuvis::ProcessingContext proc(sess); + cuvis::ProcessingArgs procArgs; + procArgs.processing_mode = cuvis::processing_mode_t::Cube_Raw; + proc.set_processingArgs(procArgs); + proc.apply(mesu); + } { /* @@ -156,6 +167,31 @@ int main(int argc, char* argv[]) cuvis::ViewExporter exporter(args); exporter.apply(mesu); + + /* + * View Exporter - Pansharpening + * Only for cameras with a panchromatic sensor (P models, e.g. Ultris X20P). + * Pansharpening fuses the cube (high spectral resolution) with the pan image (high spatial resolution). + * It is set in the pansharpening settings of any exporter. With the *ViewExporter* it is applied after rendering the view, which is fast. + * - `pan_scale`: 0.0 = off, 1.0 = resolution of the pan image + * - `pan_algorithm`: `CubertMacroPixel` works in all processing modes, `CubertPanRatio` needs Reflectance mode, `Noop` only upscales + * - `pre_pan_sharpen_cube`: sharpen the whole cube before rendering (more accurate, much slower) + */ + if (mesu.get_imdata()->count(CUVIS_MESU_PAN_KEY) > 0) // only with a pan image + { + std::cout << "Export pansharpened view to file" << std::endl; + char exportDirPansharpen[CUVIS_MAXBUF]; + strcpy(exportDirPansharpen, exportDir); + strcat(exportDirPansharpen, "/pansharpened"); + args.export_dir = exportDirPansharpen; + args.pansharpening_settings.pan_scale = 1.0; + args.pansharpening_settings.pan_interpolation_type = pan_sharpening_interpolation_type_Linear; + args.pansharpening_settings.pan_algorithm = pan_sharpening_algorithm_CubertMacroPixel; + args.pansharpening_settings.pre_pan_sharpen_cube = false; + + cuvis::ViewExporter pansharpenExporter(args); + pansharpenExporter.apply(mesu); + } } { /* @@ -183,6 +219,7 @@ int main(int argc, char* argv[]) saveArgs.export_dir = exportDirView; saveArgs.allow_overwrite = true; saveArgs.allow_session_file = true; + saveArgs.full_export = false; // do not include the cube in the export cuvis::CubeExporter exporter(saveArgs); exporter.apply(mesu); diff --git a/Example_4_Exporters_cpp/run_Example_4_Exporters_cpp.sh b/Example_4_Exporters_cpp/run_Example_4_Exporters_cpp.sh index 7ef7d19..e5d335d 100644 --- a/Example_4_Exporters_cpp/run_Example_4_Exporters_cpp.sh +++ b/Example_4_Exporters_cpp/run_Example_4_Exporters_cpp.sh @@ -1,26 +1,29 @@ #!/bin/bash # Usage: -# example app path [string] E.g. ./03_exportMeasurement_cpp.exe for windows or ./03_exportMeasurement_cpp for linux -# user settings directory [string] Default is ../../../sample_data/set_examples/settings -# sessionfile (.cu3s) [string] Default is ../../../sample_data/set_examples/set0_single/single.cu3s -# user plugin file (.xml) [string] Default is ../../../sample_data/set_examples/plugin/ref/cai.xml -# name of export directory [string] The name of your output folder realtive to the example app path +# example app path [string] E.g. ./Example_4_Exporters_cpp.exe for windows or ./Example_4_Exporters_cpp for linux +# user settings directory [string] Default is ../settings +# sessionfile (.cu3s) [string] Default is ../SDK_Training_Example_Data/Drone.cu3s (demo data, Ultris X20P with pan sensor) +# measurement index [int ] Default is 2 (in Drone.cu3s, 0 and 1 are copies of the Dark and White references) +# user plugin file (.xml) [string] Default is ../plugins/00_RGB.xml +# name of export directory [string] The name of your output folder relative to the example app path if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## - ./03_exportMeasurement_cpp \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single.cu3s" \ - "../../../sample_data/set_examples/plugin/ref/cai.xml" \ + ./Example_4_Exporters_cpp \ + "../settings" \ + "../SDK_Training_Example_Data/Drone.cu3s" \ + 2 \ + "../plugins/00_RGB.xml" \ "export" \ else ##########WINDOWS########## - ./03_exportMeasurement_cpp.exe \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single.cu3s" \ - "../../../sample_data/set_examples/plugin/ref/cai.xml" \ + ./Example_4_Exporters_cpp.exe \ + "../settings" \ + "../SDK_Training_Example_Data/Drone.cu3s" \ + 2 \ + "../plugins/00_RGB.xml" \ "export" \ fi diff --git a/Example_5_Record_Video_cpp/main.cpp b/Example_5_Record_Video_cpp/main.cpp index c179564..17eaa2f 100644 --- a/Example_5_Record_Video_cpp/main.cpp +++ b/Example_5_Record_Video_cpp/main.cpp @@ -140,6 +140,7 @@ int main(int argc, char* argv[]) sargs.operation_mode = OperationMode_Internal; sargs.allow_overwrite = true; sargs.allow_session_file = true; + sargs.full_export = false; // do not include the cube in the export sargs.export_dir = std::filesystem::path(recDir); std::cout << "Writing Files to: " << sargs.export_dir << std::endl; diff --git a/Example_5_Record_Video_cpp/run_Example_5_Record_Video_cpp.sh b/Example_5_Record_Video_cpp/run_Example_5_Record_Video_cpp.sh index 4c33d18..c3106f6 100644 --- a/Example_5_Record_Video_cpp/run_Example_5_Record_Video_cpp.sh +++ b/Example_5_Record_Video_cpp/run_Example_5_Record_Video_cpp.sh @@ -1,17 +1,17 @@ #!/bin/bash # Usage: -# example app path [string] E.g. ./06_recordVideo_cpp.exe for windows or ./06_recordVideo_cpp for linux +# example app path [string] E.g. ./Example_5_Record_Video_cpp.exe for windows or ./Example_5_Record_Video_cpp for linux # user settings directory [string] Default is C:/Program Files/cuvis/user/settings for windows or /etc/cuvis/user/settings for linux # factory directory [string] Default is C:/Program Files/cuvis/factory for windows or /etc/cuvis/factory for linux -# name of recording directory [string] The name of your output folder realtive to the example app path +# name of recording directory [string] The name of your output folder relative to the example app path # exposure time [int ] exposure (integration) time in ms # auto exposure [bool ] 1 is "on", 0 is "off"; if "on" the aquisition will start with the given exposure time and then adjust on the fly # target fps [double] Frames Per Second that shall be recorded. if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## - ./06_recordVideo_cpp \ + ./Example_5_Record_Video_cpp \ "/etc/cuvis/user/settings" \ "/etc/cuvis/factory" \ "video01" \ @@ -21,7 +21,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then else ##########WINDOWS########## - ./06_recordVideo_cpp.exe \ + ./Example_5_Record_Video_cpp.exe \ "C:/Program Files/cuvis/user/settings" \ "C:/Program Files/cuvis/factory" \ "video01" \ diff --git a/Example_6_Reference_Spectra_cpp/CMakeLists.txt b/Example_6_Reference_Spectra_cpp/CMakeLists.txt index 5e2e14c..af8922b 100644 --- a/Example_6_Reference_Spectra_cpp/CMakeLists.txt +++ b/Example_6_Reference_Spectra_cpp/CMakeLists.txt @@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.16.0) project(Example_6_Reference_Spectra_cpp) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cuvis.cpp/") -find_package(CuvisCpp 3.6 REQUIRED) +find_package(CuvisCpp 3.6.1 REQUIRED) add_executable(Example_6_Reference_Spectra_cpp main.cpp) target_link_libraries(Example_6_Reference_Spectra_cpp PRIVATE cuvis::cpp) \ No newline at end of file diff --git a/Example_6_Reference_Spectra_cpp/main.cpp b/Example_6_Reference_Spectra_cpp/main.cpp index 1ae421d..9c9c140 100644 --- a/Example_6_Reference_Spectra_cpp/main.cpp +++ b/Example_6_Reference_Spectra_cpp/main.cpp @@ -28,7 +28,7 @@ int main(int argc, char* argv[]) * * Prerequisites to running this example: * - Have a recorded measurement in *SessionFile* format (.cu3s) that contains Dark and White references *or* downloaded the provided [demo data](https://cloud.cubert-gmbh.de/s/SDKSampleData) - * - Have the Cuvis SDK 3.6 or newer installed + * - Have the Cuvis SDK 3.6.1 or newer installed * * Run properties * - "path/to/settings" "path/to/measurement/single.cu3s" "OutputFolderName" @@ -71,6 +71,8 @@ int main(int argc, char* argv[]) /* * Process a fresh Measurement from the SessionFile with the current references and export it. + * The exported SessionFile contains the spectrum: a ProcessingContext created from it (with load_references, the default) has it as explicit reference, + * and the Measurement as implicit reference. To process it without the spectrum, call both `ProcessingContext::clear_reference` and `Measurement::clear_implicit_reference`. */ auto process_and_export = [&](std::string const& name) { auto optMesu = sess.get_mesu(0); diff --git a/Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh b/Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh index 7d04709..4f23c3e 100644 --- a/Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh +++ b/Example_6_Reference_Spectra_cpp/run_Example_6_Reference_Spectra_cpp.sh @@ -3,21 +3,21 @@ # Usage: # example app path [string] E.g. ./Example_6_Reference_Spectra_cpp.exe for windows or ./Example_6_Reference_Spectra_cpp for linux # user settings directory [string] Default is ../settings -# sessionfile (.cu3s) [string] Default is ../sample_data/WinterUlm_X20P.cu3s (demo data, must contain Dark and White references) +# sessionfile (.cu3s) [string] Default is ../SDK_Training_Example_Data/WinterUlm_X20P.cu3s (demo data, must contain Dark and White references) # name of output directory [string] The name of your output folder relative to the example app path if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## ./Example_6_Reference_Spectra_cpp \ "../settings" \ - "../sample_data/WinterUlm_X20P.cu3s" \ + "../SDK_Training_Example_Data/WinterUlm_X20P.cu3s" \ "reference_spectra" \ else ##########WINDOWS########## ./Example_6_Reference_Spectra_cpp.exe \ "../settings" \ - "../sample_data/WinterUlm_X20P.cu3s" \ + "../SDK_Training_Example_Data/WinterUlm_X20P.cu3s" \ "reference_spectra" \ fi diff --git a/Example_7_Record_Video_From_SessionFile_cpp/main.cpp b/Example_7_Record_Video_From_SessionFile_cpp/main.cpp index 127e4bf..cd3b903 100644 --- a/Example_7_Record_Video_From_SessionFile_cpp/main.cpp +++ b/Example_7_Record_Video_From_SessionFile_cpp/main.cpp @@ -108,6 +108,7 @@ int main(int argc, char* argv[]) sargs.operation_mode = OperationMode_Internal; sargs.allow_overwrite = true; sargs.allow_session_file = true; + sargs.full_export = false; // do not include the cube in the export sargs.export_dir = std::filesystem::path(recDir); std::cout << "Writing Files to: " << sargs.export_dir << std::endl; diff --git a/Example_7_Record_Video_From_SessionFile_cpp/run_Example_7_Record_Video_From_SessionFile_cpp.sh b/Example_7_Record_Video_From_SessionFile_cpp/run_Example_7_Record_Video_From_SessionFile_cpp.sh index 053109d..8093c49 100644 --- a/Example_7_Record_Video_From_SessionFile_cpp/run_Example_7_Record_Video_From_SessionFile_cpp.sh +++ b/Example_7_Record_Video_From_SessionFile_cpp/run_Example_7_Record_Video_From_SessionFile_cpp.sh @@ -1,19 +1,19 @@ #!/bin/bash # Usage: -# example app path [string] E.g. ./07_recordVideo_cpp.exe for windows or ./07_recordVideo_cpp for linux -# user settings directory [string] Default is ../../../sample_data/set_examples/settings -# sessionfile [string] Default is ../../../sample_data/set_examples/set1_video/video.cu3s -# name of recording directory [string] The name of your output folder realtive to the example app path +# example app path [string] E.g. ./Example_7_Record_Video_From_SessionFile_cpp.exe for windows or ./Example_7_Record_Video_From_SessionFile_cpp for linux +# user settings directory [string] Default is ../settings +# sessionfile [string] Default is ../SDK_Training_Example_Data/WinterUlm_X20P.cu3s +# name of recording directory [string] The name of your output folder relative to the example app path # exposure time [int ] exposure (integration) time in ms # auto exposure [bool ] 1 is "on", 0 is "off"; if "on" the aquisition will start with the given exposure time and then adjust on the fly # target fps [double] Frames Per Second that shall be recorded. if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## - ./07_recordVideoFromSessionfile_cpp \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set1_video/video.cu3s" \ + ./Example_7_Record_Video_From_SessionFile_cpp \ + "../settings" \ + "../SDK_Training_Example_Data/WinterUlm_X20P.cu3s" \ "video01" \ 100 \ 0 \ @@ -21,9 +21,9 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then else ##########WINDOWS########## - ./07_recordVideoFromSessionfile_cpp.exe \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set1_video/video.cu3s" \ + ./Example_7_Record_Video_From_SessionFile_cpp.exe \ + "../settings" \ + "../SDK_Training_Example_Data/WinterUlm_X20P.cu3s" \ "video01" \ 100 \ 0 \ diff --git a/Example_8_Change_Distance_cpp/main.cpp b/Example_8_Change_Distance_cpp/main.cpp index 83abef8..609a18f 100644 --- a/Example_8_Change_Distance_cpp/main.cpp +++ b/Example_8_Change_Distance_cpp/main.cpp @@ -84,22 +84,30 @@ int main(int argc, char* argv[]) saveArgs.allow_overwrite = true; saveArgs.export_dir = exportDir; saveArgs.allow_session_file = true; + saveArgs.full_export = false; // do not include the cube in the export cuvis::CubeExporter exporter(saveArgs); /* * Distance Calibration - * Most Ultris cameras(except for Relay - variants) require distance calibration to achieve optimal results. + * Most Ultris cameras (except for relay variants) require distance calibration to achieve optimal results. * - * ** Please note : **The provided default demo dataset was recorded with a relay - equipped camera(Ultris XM with relay optics).Thus this step is not applicable to this dataset. + * Please note: Setting the distance is not supported for R models (relay optics, e.g. Ultris XMR) and P models (pan sensor, e.g. Ultris X20P). * * Distance calibration is an operation that can be done with already recorded data and requires a distance reference measurement. - * The reference should contain high - contrast data over the relevant spectral channels at the desired distance that data should be calibrated to. + * The reference should contain high-contrast data over the relevant spectral channels at the desired distance that data should be calibrated to. * - * In this example, the measurement itself will be used as the distance reference.If the target object is suitable(high contrast, non - repeating patterns), this can suffice for good results. + * If the distance to the object is known, it can also be set directly in mm, without a distance reference measurement. This example does that. */ std::cout << "setting distance..." << std::endl; - proc.calc_distance(distance); + try + { + proc.calc_distance(distance); + } + catch (cuvis::cuvis_sdk_exception const& e) // fails on R and P models, the example continues without it + { + std::cout << "distance not set: " << e.what() << std::endl; + } cuvis::ProcessingArgs procArgs = proc.get_processingArgs(); procArgs.processing_mode = cuvis::processing_mode_t::Cube_Raw; diff --git a/Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh b/Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh index bde262b..19d7fc9 100644 --- a/Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh +++ b/Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh @@ -1,25 +1,25 @@ #!/bin/bash # Usage: -# example app path [string] E.g. ./04_changeDistance_cpp.exe for windows or ./04_changeDistance_cpp for linux -# user settings directory [string] Default is ../../../sample_data/set_examples/settings -# sessionfile (.cu3s) [string] Default is ../../../sample_data/set_examples/set0_single/single.cu3s +# example app path [string] E.g. ./Example_8_Change_Distance_cpp.exe for windows or ./Example_8_Change_Distance_cpp for linux +# user settings directory [string] Default is ../settings +# sessionfile (.cu3s) [string] Default is ../SDK_Training_Example_Data/single_raw.cu3s (demo data, Ultris X20) # new distance [int ] distance reference in mm -# name of export directory [string] The name of your output folder realtive to the example app path +# name of export directory [string] The name of your output folder relative to the example app path if [[ "$OSTYPE" == "linux-gnu"* ]]; then ##########LINUX########## - ./04_changeDistance_cpp \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single.cu3s" \ + ./Example_8_Change_Distance_cpp \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ 1000 \ "export" \ else ##########WINDOWS########## - ./04_changeDistance_cpp.exe \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single.cu3s" \ + ./Example_8_Change_Distance_cpp.exe \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ 1000 \ "export" \ diff --git a/README.md b/README.md index 9d71762..ffcaa29 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Then, you need to install the Cuvis C SDK (see [here](https://cloud.cubert-gmbh. Then use CMake (see https://cmake.org/download/) to configure and generate the Visual Studio project. You can configure either base directory (including all directoreis) or a single example using its respective directory. CMake will require you to locate the Cuvis C SDK (this should be found automatically, if the Cuvis C SDK is properly installed). -For running some of the examples, you have to use sample data (provided [here](https://cloud.cubert-gmbh.de/s/SDKSampleData)). +For running some of the examples, you have to use sample data (provided [here](https://cloud.cubert-gmbh.de/s/SDKSampleData)). Place the sample data in the `SDK_Training_Example_Data/` directory at the root of this repository. ## Inventory diff --git a/SDK_Training_Example_Data/.gitkeep b/SDK_Training_Example_Data/.gitkeep new file mode 100644 index 0000000..e69de29 From 316d698005a360317fb2534c1eb9055cb2a9733c Mon Sep 17 00:00:00 2001 From: Philip Manke Date: Fri, 6 Nov 2026 17:02:54 +0100 Subject: [PATCH 5/5] Clarify distance reference use. Distance calib before pansharpening. --- Example_3_Reprocess_cpp/main.cpp | 2 +- Example_4_Exporters_cpp/main.cpp | 9 +++++++++ Example_8_Change_Distance_cpp/main.cpp | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Example_3_Reprocess_cpp/main.cpp b/Example_3_Reprocess_cpp/main.cpp index 423a46d..b738194 100644 --- a/Example_3_Reprocess_cpp/main.cpp +++ b/Example_3_Reprocess_cpp/main.cpp @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) * Distance Calibration * Most Ultris cameras (except for relay variants) require distance calibration to achieve optimal results. * - * Please note: Distance calibration is not supported for R models (relay optics, e.g. Ultris XMR) and P models (pan sensor, e.g. Ultris X20P). + * Please note: Distance calibration is not supported for R models (relay optics, e.g. Ultris XMR). P models (pan sensor, e.g. Ultris X20P) only support it with a distance reference measurement, not with a distance in mm. * * Distance calibration is an operation that can be done with already recorded data and requires a distance reference measurement. * The reference should contain high-contrast data over the relevant spectral channels at the desired distance that data should be calibrated to. diff --git a/Example_4_Exporters_cpp/main.cpp b/Example_4_Exporters_cpp/main.cpp index 184eabc..c28ccf9 100644 --- a/Example_4_Exporters_cpp/main.cpp +++ b/Example_4_Exporters_cpp/main.cpp @@ -67,6 +67,15 @@ int main(int argc, char* argv[]) if (mesu.get_meta()->processing_mode == cuvis::processing_mode_t::Preview) { cuvis::ProcessingContext proc(sess); + // distance calibration (see Example 3) with the measurement itself, as the demo file has no distance reference + try + { + proc.set_reference(mesu, cuvis::reference_type_t::Reference_Distance); + } + catch (cuvis::cuvis_sdk_exception const& e) // R models (relay optics) do not support distance calibration + { + std::cout << "distance not set: " << e.what() << std::endl; + } cuvis::ProcessingArgs procArgs; procArgs.processing_mode = cuvis::processing_mode_t::Cube_Raw; proc.set_processingArgs(procArgs); diff --git a/Example_8_Change_Distance_cpp/main.cpp b/Example_8_Change_Distance_cpp/main.cpp index 609a18f..008329a 100644 --- a/Example_8_Change_Distance_cpp/main.cpp +++ b/Example_8_Change_Distance_cpp/main.cpp @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) * Distance Calibration * Most Ultris cameras (except for relay variants) require distance calibration to achieve optimal results. * - * Please note: Setting the distance is not supported for R models (relay optics, e.g. Ultris XMR) and P models (pan sensor, e.g. Ultris X20P). + * Please note: Setting the distance in mm is not supported for R models (relay optics, e.g. Ultris XMR) and P models (pan sensor, e.g. Ultris X20P). P models support distance calibration with a distance reference measurement instead (see Example 3). * * Distance calibration is an operation that can be done with already recorded data and requires a distance reference measurement. * The reference should contain high-contrast data over the relevant spectral channels at the desired distance that data should be calibrated to.