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_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..b738194 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). 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. + * 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..c28ccf9 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,28 @@ 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); + // 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); + proc.apply(mesu); + } { /* @@ -156,6 +176,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 +228,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 new file mode 100644 index 0000000..af8922b --- /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.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 new file mode 100644 index 0000000..9c9c140 --- /dev/null +++ b/Example_6_Reference_Spectra_cpp/main.cpp @@ -0,0 +1,164 @@ +#include "cuvis.hpp" + +#include +#include +#include +#include +#include +#include +#include + +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, 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. + * + * 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.1 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. + * 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); + 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); + }; + + // 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 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)); + + /* + * Target Spectrum + * - Values are fractions (1.0 = 100%), wavelengths in nm. + * - The spectrum must cover the cube's entire wavelength range, otherwise processing fails. + * - 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 + cuvis::target_spectrum_t target; + 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"); + + proc.clear_reference(cuvis::reference_type_t::Reference_TargetSpectrum); + + /* + * White Spectrum + * - 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]: 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, + * 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 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); + 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; + 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 = + 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..4f23c3e --- /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 ../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" \ + "../SDK_Training_Example_Data/WinterUlm_X20P.cu3s" \ + "reference_spectra" \ + +else + ##########WINDOWS########## + ./Example_6_Reference_Spectra_cpp.exe \ + "../settings" \ + "../SDK_Training_Example_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_7_Change_Distance_cpp/run_Example_7_Change_Distance_cpp.sh b/Example_7_Change_Distance_cpp/run_Example_7_Change_Distance_cpp.sh deleted file mode 100644 index bde262b..0000000 --- a/Example_7_Change_Distance_cpp/run_Example_7_Change_Distance_cpp.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/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 -# new distance [int ] distance reference in mm -# name of export directory [string] The name of your output folder realtive 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" \ - 1000 \ - "export" \ - -else - ##########WINDOWS########## - ./04_changeDistance_cpp.exe \ - "../../../sample_data/set_examples/settings" \ - "../../../sample_data/set_examples/set0_single/single.cu3s" \ - 1000 \ - "export" \ - -fi - \ 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 98% rename from Example_6_Record_Video_From_SessionFile_cpp/main.cpp rename to Example_7_Record_Video_From_SessionFile_cpp/main.cpp index a012301..cd3b903 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; @@ -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_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 50% 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 index 053109d..8093c49 100644 --- 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 @@ -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/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 80% rename from Example_7_Change_Distance_cpp/main.cpp rename to Example_8_Change_Distance_cpp/main.cpp index a0f33aa..008329a 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; @@ -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 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. + * 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 new file mode 100644 index 0000000..19d7fc9 --- /dev/null +++ b/Example_8_Change_Distance_cpp/run_Example_8_Change_Distance_cpp.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Usage: +# 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 relative to the example app path + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + ##########LINUX########## + ./Example_8_Change_Distance_cpp \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + 1000 \ + "export" \ + +else + ##########WINDOWS########## + ./Example_8_Change_Distance_cpp.exe \ + "../settings" \ + "../SDK_Training_Example_Data/single_raw.cu3s" \ + 1000 \ + "export" \ + +fi + \ No newline at end of file diff --git a/README.md b/README.md index 944b852..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 @@ -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. + +### 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/SDK_Training_Example_Data/.gitkeep b/SDK_Training_Example_Data/.gitkeep new file mode 100644 index 0000000..e69de29 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