19#include <opencv2/opencv.hpp>
20#include <unordered_map>
28#define PROGRAM_NAME "loading-images-opencv-demo"
37 spdlog::level::level_enum
logLevel{spdlog::level::info};
60 args::HelpFlag help(parser,
"help",
"Display this help menu", {
'h',
"help"});
62 args::MapFlag<std::string, spdlog::level::level_enum> logLevelArg(
65 args::ValueFlag<uint64_t> numFramesArg(
66 parser,
"#frames",
"Number of frames to iterate over", {
'n',
"frames-count"});
68 args::ValueFlag<double> fpsArg(parser,
"fps",
"Desired FPS for capturing image", {
'f',
"fps"});
71 parser.ParseCLI(argc, argv);
73 std::cerr << parser.Help() << std::endl;
75 }
catch(args::ParseError e) {
76 std::cerr <<
"Error parsing command-line arguments:\n" << e.what() <<
"\n\n" << parser.Help();
82 params.
logLevel = args::get(logLevelArg);
85 params.numFrames = args::get(numFramesArg);
88 params.fps = args::get(fpsArg);
102 if(image.IsEmpty()) {
108 IRSOL_LOG_INFO(
"{}x{}, {} bytes", image.GetHeight(), image.GetWidth(), image.GetSize());
151 auto lastTick = irsol::types::clock_t::now();
152 const auto desiredDt =
153 params.fps > 0.0 ? std::chrono::microseconds(
static_cast<uint64_t
>(1000000.0 / params.fps))
154 : std::chrono::microseconds(0);
155 for(
size_t i = 0; i < params.numFrames; ++i) {
156 const auto t0 = irsol::types::clock_t::now();
158 const auto nextTick = lastTick + desiredDt;
160 std::this_thread::sleep_until(nextTick);
161 const auto loopDuration = irsol::types::clock_t::now() - t0;
162 const auto measuredFps =
163 1000000.0 / std::chrono::duration_cast<std::chrono::microseconds>(loopDuration).count();
164 IRSOL_LOG_INFO(
"Desired FPS: {:.4f}, measured FPS: {:.4f}", params.fps, measuredFps);
High-level wrapper around the NeoAPI camera for synchronized access.
image_t captureImage(std::optional< irsol::types::duration_t > timeout=std::nullopt)
Capture a single image from the camera.
static Interface HalfResolution()
Factory method to create a camera interface using half sensor resolution.
static Interface FullResolution()
Factory method to create a camera interface using full sensor resolution.
Class that offers an easy way to run a background monitorin thread that periodically inspects and rep...
void start()
Starts the monitoring thread. If the monitor is already running, this call has no effect.
void initAssertHandler()
Initializes the assertion handler system.
#define IRSOL_ASSERT_FATAL
Fatal-level assertion macro.
#define IRSOL_LOG_INFO(...)
Logs an info-level message using the default logger.
#define IRSOL_LOG_WARN(...)
Logs a warning-level message using the default logger.
void initLogging(const char *fileSinkFilename="logs/irsol.log", std::optional< spdlog::level::level_enum > minLogLevel=std::nullopt)
Initializes the irsol logging system.
const std::unordered_map< std::string, spdlog::level::level_enum > levelNameToLevelMap
Runtime map from string names to spdlog log levels.
cv::Mat convertNeoImageToCvMat(const NeoAPI::Image &image)
Converts a NeoAPI::Image (Mono12, non-packed) into an OpenCV cv::Mat.
const std::string getProgramName()
Returns the program name, typically used for logging. If PROGRAM_NAME is not defined at compile time,...
Params getParams(int argc, char **argv)
Parses command-line arguments using args library.
void runCapture(irsol::camera::Interface &cam)
Captures a single image using the provided camera interface, logs metadata and performance stats.
Command-line parameters for the program.
double fps
FPS at which to capture frames from the camera (negative means as fast as you can)
uint64_t numFrames
Number of frames to capture from the camera (default: 10)
spdlog::level::level_enum logLevel
Logging verbosity level (default: info)