Merge branch 'feature/Lidar' into merge/sdk_2.6.1

This commit is contained in:
ob-yalian
2025-12-08 14:21:32 +08:00
132 changed files with 9441 additions and 7664 deletions
@@ -3,8 +3,8 @@
/**
* @file Context.hpp
* @brief The SDK context class, which serves as the entry point to the underlying SDK. It is used to query device lists, handle device callbacks, and set the
* log level.
* @brief The SDK context class, which serves as the entry point to the underlying SDK. It is used
* to query device lists, handle device callbacks, and set the log level.
*
*/
#pragma once
@@ -25,278 +25,298 @@ class DeviceInfo;
class DeviceList;
class Context {
public:
/**
* @brief Type definition for the device changed callback function.
*
* @param[in] removedList The list of removed devices.
* @param[in] addedList The list of added devices.
*/
typedef std::function<void(std::shared_ptr<DeviceList> removedList, std::shared_ptr<DeviceList> addedList)> DeviceChangedCallback;
public:
/**
* @brief Type definition for the device changed callback function.
*
* @param[in] removedList The list of removed devices.
* @param[in] addedList The list of added devices.
*/
typedef std::function<void(std::shared_ptr<DeviceList> removedList,
std::shared_ptr<DeviceList> addedList)>
DeviceChangedCallback;
/**
* @brief Type definition for the log output callback function.
*
* @param[in] severity The current callback log level.
* @param[in] logMsg The log message.
*/
typedef std::function<void(OBLogSeverity severity, const char *logMsg)> LogCallback;
/**
* @brief Type definition for the log output callback function.
*
* @param[in] severity The current callback log level.
* @param[in] logMsg The log message.
*/
typedef std::function<void(OBLogSeverity severity, const char *logMsg)> LogCallback;
private:
ob_context *impl_ = nullptr;
DeviceChangedCallback deviceChangedCallback_;
// static LogCallback logCallback_;
private:
ob_context *impl_ = nullptr;
DeviceChangedCallback deviceChangedCallback_;
// static LogCallback logCallback_;
public:
/**
* @brief Context constructor.
* @brief The Context class is a management class that describes the runtime of the SDK. It is responsible for applying and releasing resources for the SDK.
* The context has the ability to manage multiple devices, enumerate devices, monitor device callbacks, and enable functions such as multi-device
* synchronization.
*
* @param[in] configPath The path to the configuration file. If the path is empty, the default configuration will be used.
*/
explicit Context(const char *configPath = "") {
ob_error *error = nullptr;
impl_ = ob_create_context_with_config(configPath, &error);
Error::handle(&error);
public:
/**
* @brief Context constructor.
* @brief The Context class is a management class that describes the runtime of the SDK. It is
* responsible for applying and releasing resources for the SDK. The context has the ability to
* manage multiple devices, enumerate devices, monitor device callbacks, and enable functions such
* as multi-device synchronization.
*
* @param[in] configPath The path to the configuration file. If the path is empty, the default
* configuration will be used.
*/
explicit Context(const char *configPath = "") {
ob_error *error = nullptr;
impl_ = ob_create_context_with_config(configPath, &error);
Error::handle(&error);
}
/**
* @brief Context destructor.
*/
~Context() noexcept {
ob_error *error = nullptr;
ob_delete_context(impl_, &error);
Error::handle(&error, false);
}
/**
* @brief Queries the enumerated device list.
*
* @return std::shared_ptr<DeviceList> A pointer to the device list class.
*/
std::shared_ptr<DeviceList> queryDeviceList() const {
ob_error *error = nullptr;
auto list = ob_query_device_list(impl_, &error);
Error::handle(&error);
return std::make_shared<DeviceList>(list);
}
/**
* @brief enable or disable net device enumeration.
* @brief after enable, the net device will be discovered automatically and can be retrieved by
* @ref queryDeviceList. The default state can be set in the configuration file.
*
* @attention Net device enumeration by gvcp protocol, if the device is not in the same subnet as
* the host, it will be discovered but cannot be connected.
*
* @param[in] enable true to enable, false to disable
*/
void enableNetDeviceEnumeration(bool enable) const {
ob_error *error = nullptr;
ob_enable_net_device_enumeration(impl_, enable, &error);
Error::handle(&error);
}
/**
* @brief "Force" a static IP address configuration in a device identified by its MAC Address.
*
* @param[in] macAddress MAC address of the network device.
* You can obtain it from @ref ob_device_info_get_uid, or specify it
* manually in the format xx:xx:xx:xx:xx:xx, where each xx is a two-digit hexadecimal value.
* @param[in] config The new IP configuration.
* @return bool true if the configuration command was processed successfully, false otherwise.
*
* @note This applies to all GigE Vision devices
*/
bool forceIp(const char *macAddress, const OBNetIpConfig &config) {
ob_error *error = nullptr;
auto res = ob_force_ip_config(macAddress, config, &error);
Error::handle(&error);
return res;
}
/**
* @brief Creates a network device with the specified IP address and port.
*
* @param[in] address The IP address, ipv4 only. such as "192.168.1.10"
* @param[in] port The port number, currently only support 8090
* @param[in] accessMode Device access mode. @ref ob_device_access_mode.
* If the device does not support setting the Access Mode, the default
* OB_DEVICE_DEFAULT_ACCESS is used. Applies only on first device creation or after release and
* re-creation; subsequent calls ignore it.
*
* @return std::shared_ptr<Device> The created device object.
*/
std::shared_ptr<Device> createNetDevice(
const char *address, uint16_t port,
OBDeviceAccessMode accessMode = OB_DEVICE_DEFAULT_ACCESS) const {
ob_error *error = nullptr;
auto device = ob_create_net_device_ex(impl_, address, port, accessMode, &error);
Error::handle(&error);
return std::make_shared<Device>(device);
}
/**
* @brief Set the device plug-in callback function.
* @attention This function supports multiple callbacks. Each call to this function adds a new
* callback to an internal list.
*
* @param[in] callback The function triggered when the device is plugged and unplugged.
*/
void setDeviceChangedCallback(DeviceChangedCallback callback) {
deviceChangedCallback_ = callback;
ob_error *error = nullptr;
ob_set_device_changed_callback(impl_, &Context::deviceChangedCallback, this, &error);
Error::handle(&error);
}
/**
* @brief Activates device clock synchronization to synchronize the clock of the host and all
* created devices (if supported).
*
* @param[in] repeatIntervalMsec The interval for auto-repeated synchronization, in milliseconds.
* If the value is 0, synchronization is performed only once.
*/
void enableDeviceClockSync(uint64_t repeatIntervalMsec) const {
ob_error *error = nullptr;
ob_enable_device_clock_sync(impl_, repeatIntervalMsec, &error);
Error::handle(&error);
}
/**
* @brief Frees idle memory from the internal frame memory pool.
* @brief The SDK includes an internal frame memory pool that caches memory allocated for frames
* received from devices.
*/
void freeIdleMemory() const {
ob_error *error = nullptr;
ob_free_idle_memory(impl_, &error);
Error::handle(&error);
}
/**
* @brief For linux, there are two ways to enable the UVC backend: libuvc and v4l2. This function
* is used to set the backend type.
* @brief It is effective when the new device is created.
*
* @attention This interface is only available for Linux.
*
* @param[in] type The backend type to be used.
*/
void setUvcBackendType(OBUvcBackendType type) const {
ob_error *error = nullptr;
ob_set_uvc_backend_type(impl_, type, &error);
Error::handle(&error);
}
/**
* @brief Set the level of the global log, which affects both the log level output to the console,
* output to the file and output the user defined callback.
*
* @param[in] severity The log output level.
*/
static void setLoggerSeverity(OBLogSeverity severity) {
ob_error *error = nullptr;
ob_set_logger_severity(severity, &error);
Error::handle(&error);
}
/**
* @brief Set log output to a file.
*
* @param[in] severity The log level output to the file.
* @param[in] directory The log file output path. If the path is empty, the existing settings will
* continue to be used (if the existing configuration is also empty, the log will not be output to
* the file).
*/
static void setLoggerToFile(OBLogSeverity severity, const char *directory) {
ob_error *error = nullptr;
ob_set_logger_to_file(severity, directory, &error);
Error::handle(&error);
}
/**
* @brief Set the log file name for file output
*
* @param[in] fileName Log file name. Must not be empty.
*
* @note Other settings, such as log level and output directory, remain unchanged.
*/
static void setLoggerFileName(const std::string &fileName) {
ob_error *error = nullptr;
ob_set_logger_file_name(fileName.c_str(), &error);
Error::handle(&error);
}
/**
* @brief Set log output to the console.
*
* @param[in] severity The log level output to the console.
*/
static void setLoggerToConsole(OBLogSeverity severity) {
ob_error *error = nullptr;
ob_set_logger_to_console(severity, &error);
Error::handle(&error);
}
/**
* @brief Set the logger to callback.
*
* @param[in] severity The callback log level.
* @param[in] callback The callback function.
*/
static void setLoggerToCallback(OBLogSeverity severity, LogCallback callback) {
ob_error *error = nullptr;
Context::getLogCallback() = callback;
ob_set_logger_to_callback(severity, &Context::logCallback, &Context::getLogCallback(), &error);
Error::handle(&error);
}
/**
* @brief Logs a message with severity, file, function, and line info.
*
* @param severity Log level, see @ref OBLogSeverity for details
* @param module The module or component the log belongs to
* @param message Message string to log
* @param file Source file name, e.g., __FILE__
* @param func Function name, e.g., __func__
* @param line Line number, e.g., __LINE__
*/
static void logExternalMessage(OBLogSeverity severity, const std::string &module,
const std::string &message, const std::string &file,
const std::string &func, int line) {
ob_error *error = nullptr;
ob_log_external_message(severity, module.c_str(), message.c_str(), file.c_str(), func.c_str(),
line, &error);
Error::handle(&error);
}
/**
* @brief Set the extensions directory
* @brief The extensions directory is used to search for dynamic libraries that provide additional
* functionality to the SDK, such as the Frame filters.
*
* @attention Should be called before creating the context and pipeline, otherwise the default
* extensions directory (./extensions) will be used.
*
* @param[in] directory Path to the extensions directory. If the path is empty, the existing
* settings will continue to be used (if the existing
*/
static void setExtensionsDirectory(const char *directory) {
ob_error *error = nullptr;
ob_set_extensions_directory(directory, &error);
Error::handle(&error);
}
private:
static void deviceChangedCallback(ob_device_list *removedList, ob_device_list *addedList,
void *userData) {
auto ctx = static_cast<Context *>(userData);
if (ctx && ctx->deviceChangedCallback_) {
auto removed = std::make_shared<DeviceList>(removedList);
auto added = std::make_shared<DeviceList>(addedList);
ctx->deviceChangedCallback_(removed, added);
}
}
/**
* @brief Context destructor.
*/
~Context() noexcept {
ob_error *error = nullptr;
ob_delete_context(impl_, &error);
Error::handle(&error, false);
static void logCallback(OBLogSeverity severity, const char *logMsg, void *userData) {
auto cb = static_cast<LogCallback *>(userData);
if (cb) {
(*cb)(severity, logMsg);
}
}
/**
* @brief Queries the enumerated device list.
*
* @return std::shared_ptr<DeviceList> A pointer to the device list class.
*/
std::shared_ptr<DeviceList> queryDeviceList() const {
ob_error *error = nullptr;
auto list = ob_query_device_list(impl_, &error);
Error::handle(&error);
return std::make_shared<DeviceList>(list);
}
/**
* @brief enable or disable net device enumeration.
* @brief after enable, the net device will be discovered automatically and can be retrieved by @ref queryDeviceList. The default state can be set in the
* configuration file.
*
* @attention Net device enumeration by gvcp protocol, if the device is not in the same subnet as the host, it will be discovered but cannot be connected.
*
* @param[in] enable true to enable, false to disable
*/
void enableNetDeviceEnumeration(bool enable) const {
ob_error *error = nullptr;
ob_enable_net_device_enumeration(impl_, enable, &error);
Error::handle(&error);
}
/**
* @brief "Force" a static IP address configuration in a device identified by its MAC Address.
*
* @param[in] macAddress MAC address of the network device.
* You can obtain it from @ref ob_device_info_get_uid, or specify it manually
* in the format xx:xx:xx:xx:xx:xx, where each xx is a two-digit hexadecimal value.
* @param[in] config The new IP configuration.
* @return bool true if the configuration command was processed successfully, false otherwise.
*
* @note This applies to all GigE Vision devices
*/
bool forceIp(const char *macAddress, const OBNetIpConfig &config) {
ob_error *error = nullptr;
auto res = ob_force_ip_config(macAddress, config, &error);
Error::handle(&error);
return res;
}
/**
* @brief Creates a network device with the specified IP address and port.
*
* @param[in] address The IP address, ipv4 only. such as "192.168.1.10"
* @param[in] port The port number, currently only support 8090
* @param[in] accessMode Device access mode. @ref ob_device_access_mode.
* If the device does not support setting the Access Mode, the default OB_DEVICE_DEFAULT_ACCESS is used.
* Applies only on first device creation or after release and re-creation; subsequent calls ignore it.
*
* @return std::shared_ptr<Device> The created device object.
*/
std::shared_ptr<Device> createNetDevice(const char *address, uint16_t port, OBDeviceAccessMode accessMode = OB_DEVICE_DEFAULT_ACCESS) const {
ob_error *error = nullptr;
auto device = ob_create_net_device_ex(impl_, address, port, accessMode, &error);
Error::handle(&error);
return std::make_shared<Device>(device);
}
/**
* @brief Set the device plug-in callback function.
* @attention This function supports multiple callbacks. Each call to this function adds a new callback to an internal list.
*
* @param[in] callback The function triggered when the device is plugged and unplugged.
*/
void setDeviceChangedCallback(DeviceChangedCallback callback) {
deviceChangedCallback_ = callback;
ob_error *error = nullptr;
ob_set_device_changed_callback(impl_, &Context::deviceChangedCallback, this, &error);
Error::handle(&error);
}
/**
* @brief Activates device clock synchronization to synchronize the clock of the host and all created devices (if supported).
*
* @param[in] repeatIntervalMsec The interval for auto-repeated synchronization, in milliseconds. If the value is 0, synchronization is performed only once.
*/
void enableDeviceClockSync(uint64_t repeatIntervalMsec) const {
ob_error *error = nullptr;
ob_enable_device_clock_sync(impl_, repeatIntervalMsec, &error);
Error::handle(&error);
}
/**
* @brief Frees idle memory from the internal frame memory pool.
* @brief The SDK includes an internal frame memory pool that caches memory allocated for frames received from devices.
*/
void freeIdleMemory() const {
ob_error *error = nullptr;
ob_free_idle_memory(impl_, &error);
Error::handle(&error);
}
/**
* @brief For linux, there are two ways to enable the UVC backend: libuvc and v4l2. This function is used to set the backend type.
* @brief It is effective when the new device is created.
*
* @attention This interface is only available for Linux.
*
* @param[in] type The backend type to be used.
*/
void setUvcBackendType(OBUvcBackendType type) const {
ob_error *error = nullptr;
ob_set_uvc_backend_type(impl_, type, &error);
Error::handle(&error);
}
/**
* @brief Set the level of the global log, which affects both the log level output to the console, output to the file and output the user defined
* callback.
*
* @param[in] severity The log output level.
*/
static void setLoggerSeverity(OBLogSeverity severity) {
ob_error *error = nullptr;
ob_set_logger_severity(severity, &error);
Error::handle(&error);
}
/**
* @brief Set log output to a file.
*
* @param[in] severity The log level output to the file.
* @param[in] directory The log file output path. If the path is empty, the existing settings will continue to be used (if the existing configuration is
* also empty, the log will not be output to the file).
*/
static void setLoggerToFile(OBLogSeverity severity, const char *directory) {
ob_error *error = nullptr;
ob_set_logger_to_file(severity, directory, &error);
Error::handle(&error);
}
/**
* @brief Set the log file name for file output
*
* @param[in] fileName Log file name. Must not be empty.
*
* @note Other settings, such as log level and output directory, remain unchanged.
*/
static void setLoggerFileName(const std::string &fileName) {
ob_error *error = nullptr;
ob_set_logger_file_name(fileName.c_str(), &error);
Error::handle(&error);
}
/**
* @brief Set log output to the console.
*
* @param[in] severity The log level output to the console.
*/
static void setLoggerToConsole(OBLogSeverity severity) {
ob_error *error = nullptr;
ob_set_logger_to_console(severity, &error);
Error::handle(&error);
}
/**
* @brief Set the logger to callback.
*
* @param[in] severity The callback log level.
* @param[in] callback The callback function.
*/
static void setLoggerToCallback(OBLogSeverity severity, LogCallback callback) {
ob_error *error = nullptr;
Context::getLogCallback() = callback;
ob_set_logger_to_callback(severity, &Context::logCallback, &Context::getLogCallback(), &error);
Error::handle(&error);
}
/**
* @brief Logs a message with severity, file, function, and line info.
*
* @param severity Log level, see @ref OBLogSeverity for details
* @param module The module or component the log belongs to
* @param message Message string to log
* @param file Source file name, e.g., __FILE__
* @param func Function name, e.g., __func__
* @param line Line number, e.g., __LINE__
*/
static void logExternalMessage(OBLogSeverity severity, const std::string &module, const std::string &message, const std::string &file,
const std::string &func, int line) {
ob_error *error = nullptr;
ob_log_external_message(severity, module.c_str(), message.c_str(), file.c_str(), func.c_str(), line, &error);
Error::handle(&error);
}
/**
* @brief Set the extensions directory
* @brief The extensions directory is used to search for dynamic libraries that provide additional functionality to the SDK, such as the Frame filters.
*
* @attention Should be called before creating the context and pipeline, otherwise the default extensions directory (./extensions) will be used.
*
* @param[in] directory Path to the extensions directory. If the path is empty, the existing settings will continue to be used (if the existing
*/
static void setExtensionsDirectory(const char *directory) {
ob_error *error = nullptr;
ob_set_extensions_directory(directory, &error);
Error::handle(&error);
}
private:
static void deviceChangedCallback(ob_device_list *removedList, ob_device_list *addedList, void *userData) {
auto ctx = static_cast<Context *>(userData);
if(ctx && ctx->deviceChangedCallback_) {
auto removed = std::make_shared<DeviceList>(removedList);
auto added = std::make_shared<DeviceList>(addedList);
ctx->deviceChangedCallback_(removed, added);
}
}
static void logCallback(OBLogSeverity severity, const char *logMsg, void *userData) {
auto cb = static_cast<LogCallback *>(userData);
if(cb) {
(*cb)(severity, logMsg);
}
}
// Lazy initialization of the logcallback_. The purpose is to initialize logcallback_ in .hpp
static LogCallback &getLogCallback() {
static LogCallback logCallback_ = nullptr;
return logCallback_;
}
// Lazy initialization of the logcallback_. The purpose is to initialize logcallback_ in .hpp
static LogCallback &getLogCallback() {
static LogCallback logCallback_ = nullptr;
return logCallback_;
}
// for backward compatibility
#define enableMultiDeviceSync enableDeviceClockSync
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -3,8 +3,8 @@
/**
* @file Pipeline.hpp
* @brief The SDK's advanced API type can quickly implement switching streaming and frame synchronization
* operations.
* @brief The SDK's advanced API type can quickly implement switching streaming and frame
* synchronization operations.
*/
#pragma once
@@ -26,444 +26,477 @@ namespace ob {
* The Config class provides an interface for configuring pipeline parameters.
*/
class Config {
private:
ob_config_t *impl_;
private:
ob_config_t *impl_;
public:
/**
* @brief Construct a new Config object
*/
Config() {
ob_error *error = nullptr;
impl_ = ob_create_config(&error);
Error::handle(&error);
}
public:
/**
* @brief Construct a new Config object
*/
Config() {
ob_error *error = nullptr;
impl_ = ob_create_config(&error);
Error::handle(&error);
}
explicit Config(ob_config_t *impl) : impl_(impl) {}
explicit Config(ob_config_t *impl) : impl_(impl) {}
/**
* @brief Destroy the Config object
*/
~Config() noexcept {
ob_error *error = nullptr;
ob_delete_config(impl_, &error);
Error::handle(&error, false);
}
/**
* @brief Destroy the Config object
*/
~Config() noexcept {
ob_error *error = nullptr;
ob_delete_config(impl_, &error);
Error::handle(&error, false);
}
ob_config_t *getImpl() const {
return impl_;
}
ob_config_t *getImpl() const { return impl_; }
/**
* @brief enable a stream with a specific stream type
*
* @param[in] streamType The stream type to be enabled
*/
void enableStream(OBStreamType streamType) const {
ob_error *error = nullptr;
ob_config_enable_stream(impl_, streamType, &error);
Error::handle(&error);
}
/**
* @brief enable a stream with a specific stream type
*
* @param[in] streamType The stream type to be enabled
*/
void enableStream(OBStreamType streamType) const {
ob_error *error = nullptr;
ob_config_enable_stream(impl_, streamType, &error);
Error::handle(&error);
}
/**
* @brief Enable a stream with a specific sensor type
* @brief Will convert sensor type to stream type automatically.
*
* @param[in] sensorType The sensor type to be enabled
*/
void enableStream(OBSensorType sensorType) const {
auto streamType = ob::TypeHelper::convertSensorTypeToStreamType(sensorType);
enableStream(streamType);
}
/**
* @brief Enable a stream with a specific sensor type
* @brief Will convert sensor type to stream type automatically.
*
* @param[in] sensorType The sensor type to be enabled
*/
void enableStream(OBSensorType sensorType) const {
auto streamType = ob::TypeHelper::convertSensorTypeToStreamType(sensorType);
enableStream(streamType);
}
/**
* @brief Enable a stream to be used in the pipeline
*
* @param[in] streamProfile The stream configuration to be enabled
*/
void enableStream(std::shared_ptr<const StreamProfile> streamProfile) const {
ob_error *error = nullptr;
auto c_stream_profile = streamProfile->getImpl();
ob_config_enable_stream_with_stream_profile(impl_, c_stream_profile, &error);
Error::handle(&error);
}
/**
* @brief Enable a stream to be used in the pipeline
*
* @param[in] streamProfile The stream configuration to be enabled
*/
void enableStream(std::shared_ptr<const StreamProfile> streamProfile) const {
ob_error *error = nullptr;
auto c_stream_profile = streamProfile->getImpl();
ob_config_enable_stream_with_stream_profile(impl_, c_stream_profile, &error);
Error::handle(&error);
}
/**
* @brief Enable a video stream to be used in the pipeline.
*
* This function allows users to enable a video stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default resolution settings.
* Users who wish to set custom resolutions should refer to the product manual, as available resolutions vary by camera model.
*
* @param[in] streamType The video stream type.
* @param[in] width The video stream width (default is OB_WIDTH_ANY, which selects the default resolution).
* @param[in] height The video stream height (default is OB_HEIGHT_ANY, which selects the default resolution).
* @param[in] fps The video stream frame rate (default is OB_FPS_ANY, which selects the default frame rate).
* @param[in] format The video stream format (default is OB_FORMAT_ANY, which selects the default format).
*/
void enableVideoStream(OBStreamType streamType, uint32_t width = OB_WIDTH_ANY, uint32_t height = OB_HEIGHT_ANY, uint32_t fps = OB_FPS_ANY,
OBFormat format = OB_FORMAT_ANY) const {
ob_error *error = nullptr;
ob_config_enable_video_stream(impl_, streamType, width, height, fps, format, &error);
Error::handle(&error);
}
/**
* @brief Enable a video stream to be used in the pipeline.
*
* This function allows users to enable a video stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default resolution settings.
* Users who wish to set custom resolutions should refer to the product manual, as available
* resolutions vary by camera model.
*
* @param[in] streamType The video stream type.
* @param[in] width The video stream width (default is OB_WIDTH_ANY, which selects the default
* resolution).
* @param[in] height The video stream height (default is OB_HEIGHT_ANY, which selects the default
* resolution).
* @param[in] fps The video stream frame rate (default is OB_FPS_ANY, which selects the default
* frame rate).
* @param[in] format The video stream format (default is OB_FORMAT_ANY, which selects the default
* format).
*/
void enableVideoStream(OBStreamType streamType, uint32_t width = OB_WIDTH_ANY,
uint32_t height = OB_HEIGHT_ANY, uint32_t fps = OB_FPS_ANY,
OBFormat format = OB_FORMAT_ANY) const {
ob_error *error = nullptr;
ob_config_enable_video_stream(impl_, streamType, width, height, fps, format, &error);
Error::handle(&error);
}
/**
* @brief Enable a video stream to be used in the pipeline.
* @brief Will convert sensor type to stream type automatically.
*
* @param[in] sensorType The sensor type to be enabled.
* @param[in] width The video stream width (default is OB_WIDTH_ANY, which selects the default resolution).
* @param[in] height The video stream height (default is OB_HEIGHT_ANY, which selects the default resolution).
* @param[in] fps The video stream frame rate (default is OB_FPS_ANY, which selects the default frame rate).
* @param[in] format The video stream format (default is OB_FORMAT_ANY, which selects the default format).
*/
void enableVideoStream(OBSensorType sensorType, uint32_t width = OB_WIDTH_ANY, uint32_t height = OB_HEIGHT_ANY, uint32_t fps = OB_FPS_ANY,
OBFormat format = OB_FORMAT_ANY) const {
auto streamType = ob::TypeHelper::convertSensorTypeToStreamType(sensorType);
enableVideoStream(streamType, width, height, fps, format);
}
/**
* @brief Enable a video stream to be used in the pipeline.
* @brief Will convert sensor type to stream type automatically.
*
* @param[in] sensorType The sensor type to be enabled.
* @param[in] width The video stream width (default is OB_WIDTH_ANY, which selects the default
* resolution).
* @param[in] height The video stream height (default is OB_HEIGHT_ANY, which selects the default
* resolution).
* @param[in] fps The video stream frame rate (default is OB_FPS_ANY, which selects the default
* frame rate).
* @param[in] format The video stream format (default is OB_FORMAT_ANY, which selects the default
* format).
*/
void enableVideoStream(OBSensorType sensorType, uint32_t width = OB_WIDTH_ANY,
uint32_t height = OB_HEIGHT_ANY, uint32_t fps = OB_FPS_ANY,
OBFormat format = OB_FORMAT_ANY) const {
auto streamType = ob::TypeHelper::convertSensorTypeToStreamType(sensorType);
enableVideoStream(streamType, width, height, fps, format);
}
/**
* @brief Enable an accelerometer stream to be used in the pipeline.
*
* This function allows users to enable an accelerometer stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default settings.
* Users who wish to set custom full-scale ranges or sample rates should refer to the product manual, as available settings vary by device model.
*
* @param[in] fullScaleRange The full-scale range of the accelerometer (default is OB_ACCEL_FULL_SCALE_RANGE_ANY, which selects the default range).
* @param[in] sampleRate The sample rate of the accelerometer (default is OB_ACCEL_SAMPLE_RATE_ANY, which selects the default rate).
*/
void enableAccelStream(OBAccelFullScaleRange fullScaleRange = OB_ACCEL_FULL_SCALE_RANGE_ANY,
OBAccelSampleRate sampleRate = OB_ACCEL_SAMPLE_RATE_ANY) const {
ob_error *error = nullptr;
ob_config_enable_accel_stream(impl_, fullScaleRange, sampleRate, &error);
Error::handle(&error);
}
/**
* @brief Enable an accelerometer stream to be used in the pipeline.
*
* This function allows users to enable an accelerometer stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default settings.
* Users who wish to set custom full-scale ranges or sample rates should refer to the product
* manual, as available settings vary by device model.
*
* @param[in] fullScaleRange The full-scale range of the accelerometer (default is
* OB_ACCEL_FULL_SCALE_RANGE_ANY, which selects the default range).
* @param[in] sampleRate The sample rate of the accelerometer (default is
* OB_ACCEL_SAMPLE_RATE_ANY, which selects the default rate).
*/
void enableAccelStream(OBAccelFullScaleRange fullScaleRange = OB_ACCEL_FULL_SCALE_RANGE_ANY,
OBAccelSampleRate sampleRate = OB_ACCEL_SAMPLE_RATE_ANY) const {
ob_error *error = nullptr;
ob_config_enable_accel_stream(impl_, fullScaleRange, sampleRate, &error);
Error::handle(&error);
}
/**
* @brief Enable a gyroscope stream to be used in the pipeline.
*
* This function allows users to enable a gyroscope stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default settings.
* Users who wish to set custom full-scale ranges or sample rates should refer to the product manual, as available settings vary by device model.
*
* @param[in] fullScaleRange The full-scale range of the gyroscope (default is OB_GYRO_FULL_SCALE_RANGE_ANY, which selects the default range).
* @param[in] sampleRate The sample rate of the gyroscope (default is OB_GYRO_SAMPLE_RATE_ANY, which selects the default rate).
*/
void enableGyroStream(OBGyroFullScaleRange fullScaleRange = OB_GYRO_FULL_SCALE_RANGE_ANY, OBGyroSampleRate sampleRate = OB_GYRO_SAMPLE_RATE_ANY) const {
ob_error *error = nullptr;
ob_config_enable_gyro_stream(impl_, fullScaleRange, sampleRate, &error);
Error::handle(&error);
}
/**
* @brief Enable a gyroscope stream to be used in the pipeline.
*
* This function allows users to enable a gyroscope stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default settings.
* Users who wish to set custom full-scale ranges or sample rates should refer to the product
* manual, as available settings vary by device model.
*
* @param[in] fullScaleRange The full-scale range of the gyroscope (default is
* OB_GYRO_FULL_SCALE_RANGE_ANY, which selects the default range).
* @param[in] sampleRate The sample rate of the gyroscope (default is OB_GYRO_SAMPLE_RATE_ANY,
* which selects the default rate).
*/
void enableGyroStream(OBGyroFullScaleRange fullScaleRange = OB_GYRO_FULL_SCALE_RANGE_ANY,
OBGyroSampleRate sampleRate = OB_GYRO_SAMPLE_RATE_ANY) const {
ob_error *error = nullptr;
ob_config_enable_gyro_stream(impl_, fullScaleRange, sampleRate, &error);
Error::handle(&error);
}
/**
* @brief Enable a LiDAR stream to be used in the pipeline.
*
* This function allows users to enable a LiDAR stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default settings.
* Users who wish to set custom full-scale ranges or sample rates should refer to the product manual, as available settings vary by device model.
*
* @param[in] scanRate The scan rate of the LiDAR (default is OB_LIDAR_SCAN_ANY, which selects the default scan rate).
* @param[in] format The stream format (default is OB_FORMAT_ANY, which selects the default format).
*/
void enableLiDARStream(OBLiDARScanRate scanRate = OB_LIDAR_SCAN_ANY, OBFormat format = OB_FORMAT_ANY) const {
ob_error *error = nullptr;
ob_config_enable_lidar_stream(impl_, scanRate, format, &error);
Error::handle(&error);
}
/**
* @brief Enable a LiDAR stream to be used in the pipeline.
*
* This function allows users to enable a LiDAR stream with customizable parameters.
* If no parameters are specified, the stream will be enabled with default settings.
* Users who wish to set custom full-scale ranges or sample rates should refer to the product
* manual, as available settings vary by device model.
*
* @param[in] scanRate The scan rate of the LiDAR (default is OB_LIDAR_SCAN_ANY, which selects the
* default scan rate).
* @param[in] format The stream format (default is OB_FORMAT_ANY, which selects the default
* format).
*/
void enableLiDARStream(OBLiDARScanRate scanRate = OB_LIDAR_SCAN_ANY,
OBFormat format = OB_FORMAT_ANY) const {
ob_error *error = nullptr;
ob_config_enable_lidar_stream(impl_, scanRate, format, &error);
Error::handle(&error);
}
/**
* @deprecated Use enableStream(std::shared_ptr<StreamProfile> streamProfile) instead
* @brief Enable all streams to be used in the pipeline
*/
void enableAllStream() {
ob_error *error = nullptr;
ob_config_enable_all_stream(impl_, &error);
Error::handle(&error);
}
/**
* @deprecated Use enableStream(std::shared_ptr<StreamProfile> streamProfile) instead
* @brief Enable all streams to be used in the pipeline
*/
void enableAllStream() {
ob_error *error = nullptr;
ob_config_enable_all_stream(impl_, &error);
Error::handle(&error);
}
/**
* @brief Disable a stream to be used in the pipeline
*
* @param[in] streamType The stream configuration to be disabled
*/
void disableStream(OBStreamType streamType) const {
ob_error *error = nullptr;
ob_config_disable_stream(impl_, streamType, &error);
Error::handle(&error);
}
/**
* @brief Disable a stream to be used in the pipeline
*
* @param[in] streamType The stream configuration to be disabled
*/
void disableStream(OBStreamType streamType) const {
ob_error *error = nullptr;
ob_config_disable_stream(impl_, streamType, &error);
Error::handle(&error);
}
/**
* @brief Disable a sensor stream to be used in the pipeline.
* @brief Will convert sensor type to stream type automatically.
*
* @param[in] sensorType The sensor configuration to be disabled
*/
void disableStream(OBSensorType sensorType) const {
auto streamType = ob::TypeHelper::convertSensorTypeToStreamType(sensorType);
disableStream(streamType);
}
/**
* @brief Disable a sensor stream to be used in the pipeline.
* @brief Will convert sensor type to stream type automatically.
*
* @param[in] sensorType The sensor configuration to be disabled
*/
void disableStream(OBSensorType sensorType) const {
auto streamType = ob::TypeHelper::convertSensorTypeToStreamType(sensorType);
disableStream(streamType);
}
/**
* @brief Disable all streams to be used in the pipeline
*/
void disableAllStream() const {
ob_error *error = nullptr;
ob_config_disable_all_stream(impl_, &error);
Error::handle(&error);
}
/**
* @brief Disable all streams to be used in the pipeline
*/
void disableAllStream() const {
ob_error *error = nullptr;
ob_config_disable_all_stream(impl_, &error);
Error::handle(&error);
}
/**
* @brief Get the Enabled Stream Profile List
*
* @return std::shared_ptr<StreamProfileList>
*/
std::shared_ptr<StreamProfileList> getEnabledStreamProfileList() const {
ob_error *error = nullptr;
auto list = ob_config_get_enabled_stream_profile_list(impl_, &error);
Error::handle(&error);
return std::make_shared<StreamProfileList>(list);
}
/**
* @brief Get the Enabled Stream Profile List
*
* @return std::shared_ptr<StreamProfileList>
*/
std::shared_ptr<StreamProfileList> getEnabledStreamProfileList() const {
ob_error *error = nullptr;
auto list = ob_config_get_enabled_stream_profile_list(impl_, &error);
Error::handle(&error);
return std::make_shared<StreamProfileList>(list);
}
/**
* @brief Set the alignment mode
*
* @param[in] mode The alignment mode
*/
void setAlignMode(OBAlignMode mode) const {
ob_error *error = nullptr;
ob_config_set_align_mode(impl_, mode, &error);
Error::handle(&error);
}
/**
* @brief Set the alignment mode
*
* @param[in] mode The alignment mode
*/
void setAlignMode(OBAlignMode mode) const {
ob_error *error = nullptr;
ob_config_set_align_mode(impl_, mode, &error);
Error::handle(&error);
}
/**
* @brief Set whether the depth needs to be scaled after setting D2C
*
* @param[in] enable Whether scaling is required
*/
void setDepthScaleRequire(bool enable) const {
ob_error *error = nullptr;
ob_config_set_depth_scale_after_align_require(impl_, enable, &error);
Error::handle(&error);
}
/**
* @brief Set whether the depth needs to be scaled after setting D2C
*
* @param[in] enable Whether scaling is required
*/
void setDepthScaleRequire(bool enable) const {
ob_error *error = nullptr;
ob_config_set_depth_scale_after_align_require(impl_, enable, &error);
Error::handle(&error);
}
/**
* @brief Set the frame aggregation output mode for the pipeline configuration
* @brief The processing strategy when the FrameSet generated by the frame aggregation function does not contain the frames of all opened streams (which
* can be caused by different frame rates of each stream, or by the loss of frames of one stream): drop directly or output to the user.
*
* @param[in] mode The frame aggregation output mode to be set (default mode is @ref OB_FRAME_AGGREGATE_OUTPUT_ANY_SITUATION)
*/
void setFrameAggregateOutputMode(OBFrameAggregateOutputMode mode) const {
ob_error *error = nullptr;
ob_config_set_frame_aggregate_output_mode(impl_, mode, &error);
Error::handle(&error);
}
/**
* @brief Set the frame aggregation output mode for the pipeline configuration
* @brief The processing strategy when the FrameSet generated by the frame aggregation function
* does not contain the frames of all opened streams (which can be caused by different frame rates
* of each stream, or by the loss of frames of one stream): drop directly or output to the user.
*
* @param[in] mode The frame aggregation output mode to be set (default mode is @ref
* OB_FRAME_AGGREGATE_OUTPUT_ANY_SITUATION)
*/
void setFrameAggregateOutputMode(OBFrameAggregateOutputMode mode) const {
ob_error *error = nullptr;
ob_config_set_frame_aggregate_output_mode(impl_, mode, &error);
Error::handle(&error);
}
};
class Pipeline {
public:
/**
* @brief FrameSetCallback is a callback function type for frameset data arrival.
*
* @param[in] frame The returned frameset data
*/
typedef std::function<void(std::shared_ptr<FrameSet> frame)> FrameSetCallback;
public:
/**
* @brief FrameSetCallback is a callback function type for frameset data arrival.
*
* @param[in] frame The returned frameset data
*/
typedef std::function<void(std::shared_ptr<FrameSet> frame)> FrameSetCallback;
private:
ob_pipeline_t *impl_;
FrameSetCallback callback_;
private:
ob_pipeline_t *impl_;
FrameSetCallback callback_;
public:
/**
* @brief Pipeline is a high-level interface for applications, algorithms related RGBD data streams. Pipeline can provide alignment inside and synchronized
* FrameSet. Pipeline() no parameter version, which opens the first device in the list of devices connected to the OS by default. If the application has
* obtained the device through the DeviceList, opening the Pipeline() at this time will throw an exception that the device has been created.
*/
Pipeline() {
ob_error *error = nullptr;
impl_ = ob_create_pipeline(&error);
Error::handle(&error);
public:
/**
* @brief Pipeline is a high-level interface for applications, algorithms related RGBD data
* streams. Pipeline can provide alignment inside and synchronized FrameSet. Pipeline() no
* parameter version, which opens the first device in the list of devices connected to the OS by
* default. If the application has obtained the device through the DeviceList, opening the
* Pipeline() at this time will throw an exception that the device has been created.
*/
Pipeline() {
ob_error *error = nullptr;
impl_ = ob_create_pipeline(&error);
Error::handle(&error);
}
/**
* @brief
* Pipeline(std::shared_ptr< Device > device ) Function for multi-device operations. Multiple
* devices need to be obtained through DeviceList, and the device and pipeline are bound through
* this interface.
*/
explicit Pipeline(std::shared_ptr<Device> device) {
ob_error *error = nullptr;
impl_ = ob_create_pipeline_with_device(device->getImpl(), &error);
Error::handle(&error);
}
/**
* @brief Destroy the pipeline object
*/
~Pipeline() noexcept {
ob_error *error = nullptr;
ob_delete_pipeline(impl_, &error);
Error::handle(&error, false);
}
/**
* @brief Start the pipeline with configuration parameters
*
* @param[in] config The parameter configuration of the pipeline
*/
void start(std::shared_ptr<Config> config = nullptr) const {
ob_error *error = nullptr;
ob_config_t *config_impl = config == nullptr ? nullptr : config->getImpl();
ob_pipeline_start_with_config(impl_, config_impl, &error);
Error::handle(&error);
}
/**
* @brief Start the pipeline and set the frameset data callback
*
* @param[in] config The configuration of the pipeline
* @param[in] callback The callback to be triggered when all frame data in the frameset arrives
*/
void start(std::shared_ptr<Config> config, FrameSetCallback callback) {
callback_ = callback;
ob_error *error = nullptr;
ob_pipeline_start_with_callback(impl_, config ? config->getImpl() : nullptr,
&Pipeline::frameSetCallback, this, &error);
Error::handle(&error);
}
static void frameSetCallback(ob_frame_t *frameSet, void *userData) {
auto pipeline = static_cast<Pipeline *>(userData);
pipeline->callback_(std::make_shared<FrameSet>(frameSet));
}
/**
* @brief Stop the pipeline
*/
void stop() const {
ob_error *error = nullptr;
ob_pipeline_stop(impl_, &error);
Error::handle(&error);
}
/**
* @brief Get the pipeline configuration parameters
* @brief Returns the default configuration if the user has not configured it
*
* @return std::shared_ptr<Config> The configured parameters
*/
std::shared_ptr<Config> getConfig() const {
ob_error *error = nullptr;
auto config = ob_pipeline_get_config(impl_, &error);
Error::handle(&error);
return std::make_shared<Config>(config);
}
/**
* @brief Wait for frameset
*
* @param[in] timeoutMs The waiting timeout in milliseconds
*
* @return std::shared_ptr<FrameSet> The waiting frameset data
*/
std::shared_ptr<FrameSet> waitForFrameset(uint32_t timeoutMs = 1000) const {
ob_error *error = nullptr;
auto frameSet = ob_pipeline_wait_for_frameset(impl_, timeoutMs, &error);
if (frameSet == nullptr) {
return nullptr;
}
Error::handle(&error);
return std::make_shared<FrameSet>(frameSet);
}
/**
* @brief
* Pipeline(std::shared_ptr< Device > device ) Function for multi-device operations. Multiple devices need to be obtained through DeviceList, and the device
* and pipeline are bound through this interface.
*/
explicit Pipeline(std::shared_ptr<Device> device) {
ob_error *error = nullptr;
impl_ = ob_create_pipeline_with_device(device->getImpl(), &error);
Error::handle(&error);
}
/**
* @brief Get the device object
*
* @return std::shared_ptr<Device> The device object
*/
std::shared_ptr<Device> getDevice() const {
ob_error *error = nullptr;
auto device = ob_pipeline_get_device(impl_, &error);
Error::handle(&error);
return std::make_shared<Device>(device);
}
/**
* @brief Destroy the pipeline object
*/
~Pipeline() noexcept {
ob_error *error = nullptr;
ob_delete_pipeline(impl_, &error);
Error::handle(&error, false);
}
/**
* @brief Get the stream profile of the specified sensor
*
* @param[in] sensorType The type of sensor
*
* @return std::shared_ptr<StreamProfileList> The stream profile list
*/
std::shared_ptr<StreamProfileList> getStreamProfileList(OBSensorType sensorType) const {
ob_error *error = nullptr;
auto list = ob_pipeline_get_stream_profile_list(impl_, sensorType, &error);
Error::handle(&error);
return std::make_shared<StreamProfileList>(list);
}
/**
* @brief Start the pipeline with configuration parameters
*
* @param[in] config The parameter configuration of the pipeline
*/
void start(std::shared_ptr<Config> config = nullptr) const {
ob_error *error = nullptr;
ob_config_t *config_impl = config == nullptr ? nullptr : config->getImpl();
ob_pipeline_start_with_config(impl_, config_impl, &error);
Error::handle(&error);
}
/**
* @brief Get the stream profile list of supported depth-to-color alignments
*
* @param[in] colorProfile The color stream profile, which is the target stream profile for the
* depth-to-color alignment.
* @param[in] alignMode The alignment mode.
*
* @attention Currently, only ALIGN_D2C_HW_MODE supported. For other align modes, please using the
* AlignFilter interface.
*
* @return std::shared_ptr<StreamProfileList> The stream profile list of supported depth-to-color
* alignments.
*/
std::shared_ptr<StreamProfileList> getD2CDepthProfileList(
std::shared_ptr<StreamProfile> colorProfile, OBAlignMode alignMode) {
ob_error *error = nullptr;
auto list = ob_get_d2c_depth_profile_list(impl_, colorProfile->getImpl(), alignMode, &error);
Error::handle(&error);
return std::make_shared<StreamProfileList>(list);
}
/**
* @brief Start the pipeline and set the frameset data callback
*
* @param[in] config The configuration of the pipeline
* @param[in] callback The callback to be triggered when all frame data in the frameset arrives
*/
void start(std::shared_ptr<Config> config, FrameSetCallback callback) {
callback_ = callback;
ob_error *error = nullptr;
ob_pipeline_start_with_callback(impl_, config ? config->getImpl() : nullptr, &Pipeline::frameSetCallback, this, &error);
Error::handle(&error);
}
/**
* @brief Turn on frame synchronization
*/
void enableFrameSync() const {
ob_error *error = nullptr;
ob_pipeline_enable_frame_sync(impl_, &error);
Error::handle(&error);
}
static void frameSetCallback(ob_frame_t *frameSet, void *userData) {
auto pipeline = static_cast<Pipeline *>(userData);
pipeline->callback_(std::make_shared<FrameSet>(frameSet));
}
/**
* @brief Turn off frame synchronization
*/
void disableFrameSync() const {
ob_error *error = nullptr;
ob_pipeline_disable_frame_sync(impl_, &error);
Error::handle(&error);
}
/**
* @brief Stop the pipeline
*/
void stop() const {
ob_error *error = nullptr;
ob_pipeline_stop(impl_, &error);
Error::handle(&error);
}
public:
// The following interfaces are deprecated and are retained here for compatibility purposes.
/**
* @brief Get the pipeline configuration parameters
* @brief Returns the default configuration if the user has not configured it
*
* @return std::shared_ptr<Config> The configured parameters
*/
std::shared_ptr<Config> getConfig() const {
ob_error *error = nullptr;
auto config = ob_pipeline_get_config(impl_, &error);
Error::handle(&error);
return std::make_shared<Config>(config);
}
OBCameraParam getCameraParam() {
ob_error *error = nullptr;
OBCameraParam cameraParam = ob_pipeline_get_camera_param(impl_, &error);
Error::handle(&error);
return cameraParam;
}
/**
* @brief Wait for frameset
*
* @param[in] timeoutMs The waiting timeout in milliseconds
*
* @return std::shared_ptr<FrameSet> The waiting frameset data
*/
std::shared_ptr<FrameSet> waitForFrameset(uint32_t timeoutMs = 1000) const {
ob_error *error = nullptr;
auto frameSet = ob_pipeline_wait_for_frameset(impl_, timeoutMs, &error);
if(frameSet == nullptr) {
return nullptr;
}
Error::handle(&error);
return std::make_shared<FrameSet>(frameSet);
}
OBCameraParam getCameraParamWithProfile(uint32_t colorWidth, uint32_t colorHeight,
uint32_t depthWidth, uint32_t depthHeight) {
ob_error *error = nullptr;
OBCameraParam cameraParam = ob_pipeline_get_camera_param_with_profile(
impl_, colorWidth, colorHeight, depthWidth, depthHeight, &error);
Error::handle(&error);
return cameraParam;
}
/**
* @brief Get the device object
*
* @return std::shared_ptr<Device> The device object
*/
std::shared_ptr<Device> getDevice() const {
ob_error *error = nullptr;
auto device = ob_pipeline_get_device(impl_, &error);
Error::handle(&error);
return std::make_shared<Device>(device);
}
OBCalibrationParam getCalibrationParam(std::shared_ptr<Config> config) {
ob_error *error = nullptr;
OBCalibrationParam calibrationParam =
ob_pipeline_get_calibration_param(impl_, config->getImpl(), &error);
Error::handle(&error);
return calibrationParam;
}
/**
* @brief Get the stream profile of the specified sensor
*
* @param[in] sensorType The type of sensor
*
* @return std::shared_ptr<StreamProfileList> The stream profile list
*/
std::shared_ptr<StreamProfileList> getStreamProfileList(OBSensorType sensorType) const {
ob_error *error = nullptr;
auto list = ob_pipeline_get_stream_profile_list(impl_, sensorType, &error);
Error::handle(&error);
return std::make_shared<StreamProfileList>(list);
}
/**
* @brief Get the stream profile list of supported depth-to-color alignments
*
* @param[in] colorProfile The color stream profile, which is the target stream profile for the depth-to-color alignment.
* @param[in] alignMode The alignment mode.
*
* @attention Currently, only ALIGN_D2C_HW_MODE supported. For other align modes, please using the AlignFilter interface.
*
* @return std::shared_ptr<StreamProfileList> The stream profile list of supported depth-to-color alignments.
*/
std::shared_ptr<StreamProfileList> getD2CDepthProfileList(std::shared_ptr<StreamProfile> colorProfile, OBAlignMode alignMode) {
ob_error *error = nullptr;
auto list = ob_get_d2c_depth_profile_list(impl_, colorProfile->getImpl(), alignMode, &error);
Error::handle(&error);
return std::make_shared<StreamProfileList>(list);
}
/**
* @brief Turn on frame synchronization
*/
void enableFrameSync() const {
ob_error *error = nullptr;
ob_pipeline_enable_frame_sync(impl_, &error);
Error::handle(&error);
}
/**
* @brief Turn off frame synchronization
*/
void disableFrameSync() const {
ob_error *error = nullptr;
ob_pipeline_disable_frame_sync(impl_, &error);
Error::handle(&error);
}
public:
// The following interfaces are deprecated and are retained here for compatibility purposes.
OBCameraParam getCameraParam() {
ob_error *error = nullptr;
OBCameraParam cameraParam = ob_pipeline_get_camera_param(impl_, &error);
Error::handle(&error);
return cameraParam;
}
OBCameraParam getCameraParamWithProfile(uint32_t colorWidth, uint32_t colorHeight, uint32_t depthWidth, uint32_t depthHeight) {
ob_error *error = nullptr;
OBCameraParam cameraParam = ob_pipeline_get_camera_param_with_profile(impl_, colorWidth, colorHeight, depthWidth, depthHeight, &error);
Error::handle(&error);
return cameraParam;
}
OBCalibrationParam getCalibrationParam(std::shared_ptr<Config> config) {
ob_error *error = nullptr;
OBCalibrationParam calibrationParam = ob_pipeline_get_calibration_param(impl_, config->getImpl(), &error);
Error::handle(&error);
return calibrationParam;
}
std::shared_ptr<FrameSet> waitForFrames(uint32_t timeoutMs = 1000) const {
return waitForFrameset(timeoutMs);
}
std::shared_ptr<FrameSet> waitForFrames(uint32_t timeoutMs = 1000) const {
return waitForFrameset(timeoutMs);
}
};
} // namespace ob
File diff suppressed because it is too large Load Diff
@@ -18,189 +18,227 @@ namespace ob {
class Device;
class CoordinateTransformHelper {
public:
/**
* @brief Transform a 3d point of a source coordinate system into a 3d point of the target coordinate system.
*
* @param[in] source_point3f Source 3d point value
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point3f Target 3d point value
*
* @return bool Transform result
*/
static bool transformation3dto3d(const OBPoint3f source_point3f, OBExtrinsic extrinsic, OBPoint3f *target_point3f) {
ob_error *error = NULL;
bool result = ob_transformation_3d_to_3d(source_point3f, extrinsic, target_point3f, &error);
Error::handle(&error);
return result;
}
public:
/**
* @brief Transform a 3d point of a source coordinate system into a 3d point of the target
* coordinate system.
*
* @param[in] source_point3f Source 3d point value
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point3f Target 3d point value
*
* @return bool Transform result
*/
static bool transformation3dto3d(const OBPoint3f source_point3f, OBExtrinsic extrinsic,
OBPoint3f *target_point3f) {
ob_error *error = NULL;
bool result = ob_transformation_3d_to_3d(source_point3f, extrinsic, target_point3f, &error);
Error::handle(&error);
return result;
}
/**
* @brief Transform a 2d pixel coordinate with an associated depth value of the source camera into a 3d point of the target coordinate system.
*
* @param[in] source_intrinsic Source intrinsic parameters
* @param[in] source_point2f Source 2d point value
* @param[in] source_depth_pixel_value The depth of sourcePoint2f in millimeters
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point3f Target 3d point value
*
* @return bool Transform result
*/
static bool transformation2dto3d(const OBPoint2f source_point2f, const float source_depth_pixel_value, const OBCameraIntrinsic source_intrinsic,
OBExtrinsic extrinsic, OBPoint3f *target_point3f) {
ob_error *error = NULL;
bool result = ob_transformation_2d_to_3d(source_point2f, source_depth_pixel_value, source_intrinsic, extrinsic, target_point3f, &error);
Error::handle(&error);
return result;
}
/**
* @brief Transform a 2d pixel coordinate with an associated depth value of the source camera into
* a 3d point of the target coordinate system.
*
* @param[in] source_intrinsic Source intrinsic parameters
* @param[in] source_point2f Source 2d point value
* @param[in] source_depth_pixel_value The depth of sourcePoint2f in millimeters
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point3f Target 3d point value
*
* @return bool Transform result
*/
static bool transformation2dto3d(const OBPoint2f source_point2f,
const float source_depth_pixel_value,
const OBCameraIntrinsic source_intrinsic, OBExtrinsic extrinsic,
OBPoint3f *target_point3f) {
ob_error *error = NULL;
bool result = ob_transformation_2d_to_3d(source_point2f, source_depth_pixel_value,
source_intrinsic, extrinsic, target_point3f, &error);
Error::handle(&error);
return result;
}
/**
* @brief Transform a 3d point of a source coordinate system into a 2d pixel coordinate of the target camera.
*
* @param[in] source_point3f Source 3d point value
* @param[in] target_intrinsic Target intrinsic parameters
* @param[in] target_distortion Target distortion parameters
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point2f Target 2d point value
*
* @return bool Transform result
*/
static bool transformation3dto2d(const OBPoint3f source_point3f, const OBCameraIntrinsic target_intrinsic, const OBCameraDistortion target_distortion,
OBExtrinsic extrinsic, OBPoint2f *target_point2f) {
ob_error *error = NULL;
bool result = ob_transformation_3d_to_2d(source_point3f, target_intrinsic, target_distortion, extrinsic, target_point2f, &error);
Error::handle(&error);
return result;
}
/**
* @brief Transform a 3d point of a source coordinate system into a 2d pixel coordinate of the
* target camera.
*
* @param[in] source_point3f Source 3d point value
* @param[in] target_intrinsic Target intrinsic parameters
* @param[in] target_distortion Target distortion parameters
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point2f Target 2d point value
*
* @return bool Transform result
*/
static bool transformation3dto2d(const OBPoint3f source_point3f,
const OBCameraIntrinsic target_intrinsic,
const OBCameraDistortion target_distortion,
OBExtrinsic extrinsic, OBPoint2f *target_point2f) {
ob_error *error = NULL;
bool result = ob_transformation_3d_to_2d(source_point3f, target_intrinsic, target_distortion,
extrinsic, target_point2f, &error);
Error::handle(&error);
return result;
}
/**
* @brief Transform a 2d pixel coordinate with an associated depth value of the source camera into a 2d pixel coordinate of the target camera
*
* @param[in] source_intrinsic Source intrinsic parameters
* @param[in] source_distortion Source distortion parameters
* @param[in] source_point2f Source 2d point value
* @param[in] source_depth_pixel_value The depth of sourcePoint2f in millimeters
* @param[in] target_intrinsic Target intrinsic parameters
* @param[in] target_distortion Target distortion parameters
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point2f Target 2d point value
*
* @return bool Transform result
*/
static bool transformation2dto2d(const OBPoint2f source_point2f, const float source_depth_pixel_value, const OBCameraIntrinsic source_intrinsic,
const OBCameraDistortion source_distortion, const OBCameraIntrinsic target_intrinsic,
const OBCameraDistortion target_distortion, OBExtrinsic extrinsic, OBPoint2f *target_point2f) {
ob_error *error = NULL;
bool result = ob_transformation_2d_to_2d(source_point2f, source_depth_pixel_value, source_intrinsic, source_distortion, target_intrinsic,
target_distortion, extrinsic, target_point2f, &error);
Error::handle(&error);
return result;
}
/**
* @brief Transform a 2d pixel coordinate with an associated depth value of the source camera into
* a 2d pixel coordinate of the target camera
*
* @param[in] source_intrinsic Source intrinsic parameters
* @param[in] source_distortion Source distortion parameters
* @param[in] source_point2f Source 2d point value
* @param[in] source_depth_pixel_value The depth of sourcePoint2f in millimeters
* @param[in] target_intrinsic Target intrinsic parameters
* @param[in] target_distortion Target distortion parameters
* @param[in] extrinsic Transformation matrix from source to target
* @param[out] target_point2f Target 2d point value
*
* @return bool Transform result
*/
static bool transformation2dto2d(const OBPoint2f source_point2f,
const float source_depth_pixel_value,
const OBCameraIntrinsic source_intrinsic,
const OBCameraDistortion source_distortion,
const OBCameraIntrinsic target_intrinsic,
const OBCameraDistortion target_distortion,
OBExtrinsic extrinsic, OBPoint2f *target_point2f) {
ob_error *error = NULL;
bool result = ob_transformation_2d_to_2d(source_point2f, source_depth_pixel_value,
source_intrinsic, source_distortion, target_intrinsic,
target_distortion, extrinsic, target_point2f, &error);
Error::handle(&error);
return result;
}
public:
// The following interfaces are deprecated and are retained here for compatibility purposes.
static bool calibration3dTo3d(const OBCalibrationParam calibrationParam, const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType,
const OBSensorType targetSensorType, OBPoint3f *targetPoint3f) {
ob_error *error = NULL;
bool result = ob_calibration_3d_to_3d(calibrationParam, sourcePoint3f, sourceSensorType, targetSensorType, targetPoint3f, &error);
Error::handle(&error);
return result;
}
public:
// The following interfaces are deprecated and are retained here for compatibility purposes.
static bool calibration3dTo3d(const OBCalibrationParam calibrationParam,
const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType,
const OBSensorType targetSensorType, OBPoint3f *targetPoint3f) {
ob_error *error = NULL;
bool result = ob_calibration_3d_to_3d(calibrationParam, sourcePoint3f, sourceSensorType,
targetSensorType, targetPoint3f, &error);
Error::handle(&error);
return result;
}
static bool calibration2dTo3d(const OBCalibrationParam calibrationParam, const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue,
const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint3f *targetPoint3f) {
ob_error *error = NULL;
bool result =
ob_calibration_2d_to_3d(calibrationParam, sourcePoint2f, sourceDepthPixelValue, sourceSensorType, targetSensorType, targetPoint3f, &error);
Error::handle(&error);
return result;
}
static bool calibration2dTo3d(const OBCalibrationParam calibrationParam,
const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue,
const OBSensorType sourceSensorType,
const OBSensorType targetSensorType, OBPoint3f *targetPoint3f) {
ob_error *error = NULL;
bool result =
ob_calibration_2d_to_3d(calibrationParam, sourcePoint2f, sourceDepthPixelValue,
sourceSensorType, targetSensorType, targetPoint3f, &error);
Error::handle(&error);
return result;
}
static bool calibration3dTo2d(const OBCalibrationParam calibrationParam, const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType,
const OBSensorType targetSensorType, OBPoint2f *targetPoint2f) {
ob_error *error = NULL;
bool result = ob_calibration_3d_to_2d(calibrationParam, sourcePoint3f, sourceSensorType, targetSensorType, targetPoint2f, &error);
Error::handle(&error);
return result;
}
static bool calibration3dTo2d(const OBCalibrationParam calibrationParam,
const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType,
const OBSensorType targetSensorType, OBPoint2f *targetPoint2f) {
ob_error *error = NULL;
bool result = ob_calibration_3d_to_2d(calibrationParam, sourcePoint3f, sourceSensorType,
targetSensorType, targetPoint2f, &error);
Error::handle(&error);
return result;
}
static bool calibration2dTo2d(const OBCalibrationParam calibrationParam, const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue,
const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint2f *targetPoint2f) {
ob_error *error = NULL;
bool result =
ob_calibration_2d_to_2d(calibrationParam, sourcePoint2f, sourceDepthPixelValue, sourceSensorType, targetSensorType, targetPoint2f, &error);
Error::handle(&error);
return result;
}
static bool calibration2dTo2d(const OBCalibrationParam calibrationParam,
const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue,
const OBSensorType sourceSensorType,
const OBSensorType targetSensorType, OBPoint2f *targetPoint2f) {
ob_error *error = NULL;
bool result =
ob_calibration_2d_to_2d(calibrationParam, sourcePoint2f, sourceDepthPixelValue,
sourceSensorType, targetSensorType, targetPoint2f, &error);
Error::handle(&error);
return result;
}
static std::shared_ptr<ob::Frame> transformationDepthFrameToColorCamera(std::shared_ptr<ob::Device> device, std::shared_ptr<ob::Frame> depthFrame,
uint32_t targetColorCameraWidth, uint32_t targetColorCameraHeight) {
ob_error *error = NULL;
static std::shared_ptr<ob::Frame> transformationDepthFrameToColorCamera(
std::shared_ptr<ob::Device> device, std::shared_ptr<ob::Frame> depthFrame,
uint32_t targetColorCameraWidth, uint32_t targetColorCameraHeight) {
ob_error *error = NULL;
// unsafe operation, need to cast const to non-const
auto unConstImpl = const_cast<ob_frame *>(depthFrame->getImpl());
// unsafe operation, need to cast const to non-const
auto unConstImpl = const_cast<ob_frame *>(depthFrame->getImpl());
auto result = transformation_depth_frame_to_color_camera(device->getImpl(), unConstImpl, targetColorCameraWidth, targetColorCameraHeight, &error);
Error::handle(&error);
return std::make_shared<ob::Frame>(result);
}
auto result = transformation_depth_frame_to_color_camera(
device->getImpl(), unConstImpl, targetColorCameraWidth, targetColorCameraHeight, &error);
Error::handle(&error);
return std::make_shared<ob::Frame>(result);
}
static bool transformationInitXYTables(const OBCalibrationParam calibrationParam, const OBSensorType sensorType, float *data, uint32_t *dataSize,
OBXYTables *xyTables) {
ob_error *error = NULL;
bool result = transformation_init_xy_tables(calibrationParam, sensorType, data, dataSize, xyTables, &error);
Error::handle(&error);
return result;
}
static bool transformationInitXYTables(const OBCalibrationParam calibrationParam,
const OBSensorType sensorType, float *data,
uint32_t *dataSize, OBXYTables *xyTables) {
ob_error *error = NULL;
bool result = transformation_init_xy_tables(calibrationParam, sensorType, data, dataSize,
xyTables, &error);
Error::handle(&error);
return result;
}
static void transformationDepthToPointCloud(OBXYTables *xyTables, const void *depthImageData, void *pointCloudData) {
ob_error *error = NULL;
transformation_depth_to_pointcloud(xyTables, depthImageData, pointCloudData, &error);
Error::handle(&error, false);
}
static void transformationDepthToPointCloud(OBXYTables *xyTables, const void *depthImageData,
void *pointCloudData) {
ob_error *error = NULL;
transformation_depth_to_pointcloud(xyTables, depthImageData, pointCloudData, &error);
Error::handle(&error, false);
}
static void transformationDepthToRGBDPointCloud(OBXYTables *xyTables, const void *depthImageData, const void *colorImageData, void *pointCloudData) {
ob_error *error = NULL;
transformation_depth_to_rgbd_pointcloud(xyTables, depthImageData, colorImageData, pointCloudData, &error);
Error::handle(&error, false);
}
static void transformationDepthToRGBDPointCloud(OBXYTables *xyTables, const void *depthImageData,
const void *colorImageData,
void *pointCloudData) {
ob_error *error = NULL;
transformation_depth_to_rgbd_pointcloud(xyTables, depthImageData, colorImageData,
pointCloudData, &error);
Error::handle(&error, false);
}
};
class PointCloudHelper {
public:
/**
* @brief save point cloud to ply file.
*
* @param[in] fileName Point cloud save path
* @param[in] frame Point cloud frame
* @param[in] saveBinary Binary or textual,true: binary, false: textual
* @param[in] useMesh Save mesh or not, true: save as mesh, false: not save as mesh
* @param[in] meshThreshold Distance threshold for creating faces in point cloud,default value :50
*
* @return bool save point cloud result
*/
static bool savePointcloudToPly(const char *fileName, std::shared_ptr<ob::Frame> frame, bool saveBinary, bool useMesh, float meshThreshold) {
ob_error *error = NULL;
auto unConstImpl = const_cast<ob_frame *>(frame->getImpl());
bool result = ob_save_pointcloud_to_ply(fileName, unConstImpl, saveBinary, useMesh, meshThreshold, &error);
Error::handle(&error, false);
return result;
}
public:
/**
* @brief save point cloud to ply file.
*
* @param[in] fileName Point cloud save path
* @param[in] frame Point cloud frame
* @param[in] saveBinary Binary or textual,true: binary, false: textual
* @param[in] useMesh Save mesh or not, true: save as mesh, false: not save as mesh
* @param[in] meshThreshold Distance threshold for creating faces in point cloud,default value :50
*
* @return bool save point cloud result
*/
static bool savePointcloudToPly(const char *fileName, std::shared_ptr<ob::Frame> frame,
bool saveBinary, bool useMesh, float meshThreshold) {
ob_error *error = NULL;
auto unConstImpl = const_cast<ob_frame *>(frame->getImpl());
bool result = ob_save_pointcloud_to_ply(fileName, unConstImpl, saveBinary, useMesh,
meshThreshold, &error);
Error::handle(&error, false);
return result;
}
/**
* @brief Save LiDAR point cloud to PLY file.
*
* @param[in] fileName Point cloud save path
* @param[in] frame LiDAR point cloud frame
* @param[in] saveBinary Binary or textual,true: binary, false: textual
* @return bool save LiDAR point cloud result
*/
static bool saveLiDARPointcloudToPly(const char *fileName, std::shared_ptr<ob::LiDARPointsFrame> frame, bool saveBinary) {
ob_error *error = NULL;
auto unConstImpl = const_cast<ob_frame *>(frame->getImpl());
bool result = ob_save_lidar_pointcloud_to_ply(fileName, unConstImpl, saveBinary, &error);
Error::handle(&error, false);
return result;
}
/**
* @brief Save LiDAR point cloud to PLY file.
*
* @param[in] fileName Point cloud save path
* @param[in] frame LiDAR point cloud frame
* @param[in] saveBinary Binary or textual,true: binary, false: textual
* @return bool save LiDAR point cloud result
*/
static bool saveLiDARPointcloudToPly(const char *fileName,
std::shared_ptr<ob::LiDARPointsFrame> frame,
bool saveBinary) {
ob_error *error = NULL;
auto unConstImpl = const_cast<ob_frame *>(frame->getImpl());
bool result = ob_save_lidar_pointcloud_to_ply(fileName, unConstImpl, saveBinary, &error);
Error::handle(&error, false);
return result;
}
};
} // namespace ob