Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions 05_recordSingleImages_cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

#include <cassert>
#include <iostream>
#include <filesystem>

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;
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -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;
Expand All @@ -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();

Expand All @@ -81,21 +104,21 @@ 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)";
acq.capture_queue();
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;
}
Expand Down
28 changes: 23 additions & 5 deletions 06_recordVideo_cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include <csignal>
#include <ctime>
#include <iostream>
#include <filesystem>

using namespace std::literals::chrono_literals;
namespace fs = std::filesystem;

int keepRunning = 1;

Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down