diff --git a/05_recordSingleImages_cpp/main.cpp b/05_recordSingleImages_cpp/main.cpp index a4df854..aa8e883 100644 --- a/05_recordSingleImages_cpp/main.cpp +++ b/05_recordSingleImages_cpp/main.cpp @@ -2,13 +2,16 @@ #include #include +#include + +namespace fs = std::filesystem; int main(int argc, char* argv[]) { if (argc != 6) { std::cout << std::endl << "Too few Arguments! Please provide:" << std::endl; - std::cout << "user settings directory" << std::endl; + std::cout << "user settings directory or .cu3c file" << std::endl; std::cout << "factory directory" << std::endl; std::cout << "name of recording directory" << std::endl; std::cout << "exposure time in ms" << std::endl; @@ -18,7 +21,7 @@ int main(int argc, char* argv[]) } char* const userSettingsDir = argv[1]; - char* const factoryDir = argv[2]; + fs::path factoryDir(argv[2]); char* const recDir = argv[3]; char* const exposureString = argv[4]; char* const nrImagesString = argv[5]; @@ -28,7 +31,7 @@ int main(int argc, char* argv[]) std::cout << "Example 05 record single image " << std::endl; std::cout << "User Settings Dir: " << userSettingsDir << std::endl; - std::cout << "Factory Dir: " << factoryDir << std::endl; + std::cout << "Factory Dir or .cu3c file: " << factoryDir.string() << std::endl; std::cout << "Recording Dir: " << recDir << std::endl; std::cout << "Exposure in ms: " << exposure_ms << std::endl; std::cout << "Number of Images: " << nrImages << std::endl; @@ -38,7 +41,26 @@ int main(int argc, char* argv[]) cuvis::General::set_log_level(loglevel_info); std::cout << "Loading Calibration and processing context..." << std::endl; - cuvis::Calibration calib(factoryDir); + + const auto get_calib = [factoryDir]() + { + if (fs::is_directory(factoryDir)) + { + return cuvis::Calibration(factoryDir); + } + else if (fs::is_regular_file(factoryDir) && factoryDir.extension() == ".cu3c") { + std::cout << " using .cu3c file as calibration instead of factory dir..." << std::endl; + cuvis::SessionFile calibFile(factoryDir); + return cuvis::Calibration(calibFile); + } + else { + throw std::exception("Unrecognized file format."); + } + }; + + cuvis::Calibration calib = get_calib(); + + cuvis::ProcessingContext proc(calib); cuvis::AcquisitionContext acq(calib); @@ -52,6 +74,7 @@ int main(int argc, char* argv[]) while (cuvis::hardware_state_t::hardware_state_offline == acq.get_state()) { std::this_thread::sleep_for(std::chrono::seconds(1)); + std::cout << "Waiting for camera to come online ..." << std::endl; } std::cout << "Camera is online" << std::endl; @@ -65,7 +88,7 @@ int main(int argc, char* argv[]) auto async_mesu = acq.capture(); auto mesu_res = async_mesu.get(std::chrono::milliseconds(500)); if (mesu_res.first == cuvis::async_result_t::done && - mesu_res.second.has_value()) + mesu_res.second.has_value()) { auto& mesu = mesu_res.second.value(); @@ -81,7 +104,7 @@ int main(int argc, char* argv[]) } //uncomment for recording in queue mode - /* + /* for (int k = 0; k < nrImages; k++) { std::cout << "Record image #" << k << "... (queue)"; @@ -89,13 +112,13 @@ int main(int argc, char* argv[]) auto mesu = acq.get_next_measurement(std::chrono::milliseconds(500)); if (mesu) { - proc.apply(mesu.value()); - exporter.apply(mesu.value()); - std::cout << "done" << std::endl; + proc.apply(mesu.value()); + exporter.apply(mesu.value()); + std::cout << "done" << std::endl; } else { - std::cout << "failed" << std::endl; + std::cout << "failed" << std::endl; } std::cout << "done" << std::endl; } diff --git a/06_recordVideo_cpp/main.cpp b/06_recordVideo_cpp/main.cpp index 3fc3c64..f352942 100644 --- a/06_recordVideo_cpp/main.cpp +++ b/06_recordVideo_cpp/main.cpp @@ -6,8 +6,10 @@ #include #include #include +#include using namespace std::literals::chrono_literals; +namespace fs = std::filesystem; int keepRunning = 1; @@ -25,7 +27,7 @@ int main(int argc, char* argv[]) if (argc != 7) { std::cout << std::endl << "Too few Arguments! Please provide:" << std::endl; - std::cout << "user settings directory" << std::endl; + std::cout << "user settings directory or .cu3c file" << std::endl; std::cout << "factory directory" << std::endl; std::cout << "name of recording directory" << std::endl; std::cout << "exposure time in ms" << std::endl; @@ -36,7 +38,7 @@ int main(int argc, char* argv[]) } char* userSettingsDir = argv[1]; - char* factoryDir = argv[2]; + fs::path factoryDir(argv[2]); char* recDir = argv[3]; char* exposureString = argv[4]; char* autoExpString = argv[5]; @@ -48,7 +50,7 @@ int main(int argc, char* argv[]) std::cout << "Example 06 video cpp " << std::endl; std::cout << "User Settings Dir: " << userSettingsDir << std::endl; - std::cout << "Factory Dir: " << factoryDir << std::endl; + std::cout << "Factory Dir or .cu3c file: " << factoryDir.string() << std::endl; std::cout << "Recording Dir: " << recDir << std::endl; std::cout << "Exposure in ms: " << exposure_ms << std::endl; std::cout << "Auto Exposure: " << autoExp << std::endl; @@ -72,7 +74,23 @@ int main(int argc, char* argv[]) loglevel_info); std::cout << "loading calibration..." << std::endl; - cuvis::Calibration calib(factoryDir); + const auto get_calib = [factoryDir]() + { + if (fs::is_directory(factoryDir)) + { + return cuvis::Calibration(factoryDir); + } + else if (fs::is_regular_file(factoryDir) && factoryDir.extension() == ".cu3c") { + std::cout << " using .cu3c file as calibration instead of factory dir..." << std::endl; + cuvis::SessionFile calibFile(factoryDir); + return cuvis::Calibration(calibFile); + } + else { + throw std::exception("Unrecognized file format."); + } + }; + + cuvis::Calibration calib = get_calib(); std::cout << "loading acquisition context..." << std::endl; cuvis::AcquisitionContext acq(calib); @@ -129,7 +147,7 @@ int main(int argc, char* argv[]) while (acq.get_state() == hardware_state_offline) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - std::cout << "."; + std::cout << "Waiting for camera to come online ..." << std::endl; } std::cout << std::endl;