init
This commit is contained in:
@@ -0,0 +1,269 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "libobsensor/h/Context.h"
|
||||
#include "Types.hpp"
|
||||
#include "Error.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace ob {
|
||||
|
||||
// forward declarations
|
||||
class Device;
|
||||
class DeviceInfo;
|
||||
class DeviceList;
|
||||
|
||||
class Context {
|
||||
public:
|
||||
/**
|
||||
* @brief Type definition for the device changed callback function.
|
||||
*
|
||||
* @param removedList The list of removed devices.
|
||||
* @param 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 severity The current callback log level.
|
||||
* @param logMsg The log message.
|
||||
*/
|
||||
typedef std::function<void(OBLogSeverity severity, const char *logMsg)> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 DeviceList::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 Orbbec 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
|
||||
* @return std::shared_ptr<Device> The created device object.
|
||||
*/
|
||||
std::shared_ptr<Device> createNetDevice(const char *address, uint16_t port) const {
|
||||
ob_error *error = nullptr;
|
||||
auto device = ob_create_net_device(impl_, address, port, &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 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 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 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 severity The log level output to the file.
|
||||
* @param 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 log output to the console.
|
||||
*
|
||||
* @param 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 severity The callback log level.
|
||||
* @param 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 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 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_;
|
||||
}
|
||||
|
||||
// for backward compatibility
|
||||
#define enableMultiDeviceSync enableDeviceClockSync
|
||||
};
|
||||
} // namespace ob
|
||||
1655
VideoProsessing/OrbbecSDK_v2.5.5/include/libobsensor/hpp/Device.hpp
Normal file
1655
VideoProsessing/OrbbecSDK_v2.5.5/include/libobsensor/hpp/Device.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file Error.hpp
|
||||
* @brief This file defines the Error class, which describes abnormal errors within the SDK.
|
||||
* Detailed information about the exception can be obtained through this class.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "libobsensor/h/Error.h"
|
||||
#include <memory>
|
||||
|
||||
namespace ob {
|
||||
class Error : public std::exception {
|
||||
private:
|
||||
ob_error *impl_;
|
||||
|
||||
/**
|
||||
* @brief Construct a new Error object
|
||||
*
|
||||
* @attention This constructor should not be called directly, use the handle() function instead.
|
||||
*
|
||||
* @param error The ob_error object
|
||||
*/
|
||||
explicit Error(ob_error *error) : impl_(error) {};
|
||||
|
||||
Error& operator=(const Error&) = default;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief A static function to handle the ob_error and throw an exception if needed.
|
||||
*
|
||||
* @param error The ob_error pointer to be handled.
|
||||
* @param throw_exception A boolean value to indicate whether to throw an exception or not, the default value is true.
|
||||
*/
|
||||
static void handle(ob_error **error, bool throw_exception = true) {
|
||||
if(!error || !*error) { // no error
|
||||
return;
|
||||
}
|
||||
|
||||
if(throw_exception) {
|
||||
throw Error(*error);
|
||||
}
|
||||
else {
|
||||
ob_delete_error(*error);
|
||||
*error = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy the Error object
|
||||
*/
|
||||
~Error() override {
|
||||
if(impl_) {
|
||||
ob_delete_error(impl_);
|
||||
impl_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the error message of the exception.
|
||||
*
|
||||
* @return const char* The error message.
|
||||
*/
|
||||
const char *what() const noexcept override {
|
||||
return impl_->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the exception type of the exception.
|
||||
* @brief Read the comments of the OBExceptionType enum in the libobsensor/h/ObTypes.h file for more information.
|
||||
*
|
||||
* @return OBExceptionType The exception type.
|
||||
*/
|
||||
OBExceptionType getExceptionType() const noexcept {
|
||||
return impl_->exception_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the name of the function where the exception occurred.
|
||||
*
|
||||
* @return const char* The function name.
|
||||
*/
|
||||
const char *getFunction() const noexcept {
|
||||
return impl_->function;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the arguments of the function where the exception occurred.
|
||||
*
|
||||
* @return const char* The arguments.
|
||||
*/
|
||||
const char *getArgs() const noexcept {
|
||||
return impl_->args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the error message of the exception.
|
||||
* @brief It is recommended to use the what() function instead.
|
||||
*
|
||||
* @return const char* The error message.
|
||||
*/
|
||||
const char *getMessage() const noexcept {
|
||||
return impl_->message;
|
||||
}
|
||||
|
||||
public:
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
const char *getName() const noexcept {
|
||||
return impl_->function;
|
||||
}
|
||||
};
|
||||
} // namespace ob
|
||||
|
||||
1190
VideoProsessing/OrbbecSDK_v2.5.5/include/libobsensor/hpp/Filter.hpp
Normal file
1190
VideoProsessing/OrbbecSDK_v2.5.5/include/libobsensor/hpp/Filter.hpp
Normal file
File diff suppressed because it is too large
Load Diff
1094
VideoProsessing/OrbbecSDK_v2.5.5/include/libobsensor/hpp/Frame.hpp
Normal file
1094
VideoProsessing/OrbbecSDK_v2.5.5/include/libobsensor/hpp/Frame.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,451 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file Pipeline.hpp
|
||||
* @brief The SDK's advanced API type can quickly implement switching streaming and frame synchronization
|
||||
* operations.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Frame.hpp"
|
||||
#include "Device.hpp"
|
||||
#include "StreamProfile.hpp"
|
||||
|
||||
#include "libobsensor/h/Pipeline.h"
|
||||
#include "libobsensor/hpp/Types.hpp"
|
||||
#include "libobsensor/hpp/TypeHelper.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
namespace ob {
|
||||
|
||||
/**
|
||||
* @brief Config class for configuring pipeline parameters
|
||||
*
|
||||
* The Config class provides an interface for configuring pipeline parameters.
|
||||
*/
|
||||
class Config {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ob_config_t *getImpl() const {
|
||||
return impl_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief enable a stream with a specific stream type
|
||||
*
|
||||
* @param 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 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 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 streamType The video stream type.
|
||||
* @param width The video stream width (default is OB_WIDTH_ANY, which selects the default resolution).
|
||||
* @param height The video stream height (default is OB_HEIGHT_ANY, which selects the default resolution).
|
||||
* @param fps The video stream frame rate (default is OB_FPS_ANY, which selects the default frame rate).
|
||||
* @param 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 sensorType The sensor type to be enabled.
|
||||
* @param width The video stream width (default is OB_WIDTH_ANY, which selects the default resolution).
|
||||
* @param height The video stream height (default is OB_HEIGHT_ANY, which selects the default resolution).
|
||||
* @param fps The video stream frame rate (default is OB_FPS_ANY, which selects the default frame rate).
|
||||
* @param 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 fullScaleRange The full-scale range of the accelerometer (default is OB_ACCEL_FULL_SCALE_RANGE_ANY, which selects the default range).
|
||||
* @param 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 fullScaleRange The full-scale range of the gyroscope (default is OB_GYRO_FULL_SCALE_RANGE_ANY, which selects the default range).
|
||||
* @param 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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 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 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 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 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 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 frame The returned frameset data
|
||||
*/
|
||||
typedef std::function<void(std::shared_ptr<FrameSet> frame)> FrameSetCallback;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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 config The configuration of the pipeline
|
||||
* @param 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 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 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 Get the stream profile of the specified sensor
|
||||
*
|
||||
* @param 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 colorProfile The color stream profile, which is the target stream profile for the depth-to-color alignment.
|
||||
* @param 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);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ob
|
||||
@@ -0,0 +1,188 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file RecordPlayback.hpp
|
||||
* @brief Record and playback device-related types, including interfaces to create recording and playback devices,
|
||||
record and playback streaming data, etc.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "Error.hpp"
|
||||
#include "libobsensor/h/RecordPlayback.h"
|
||||
#include "libobsensor/hpp/Device.hpp"
|
||||
|
||||
namespace ob {
|
||||
|
||||
typedef std::function<void(OBPlaybackStatus status)> PlaybackStatusChangeCallback;
|
||||
|
||||
class RecordDevice {
|
||||
private:
|
||||
ob_record_device_t *impl_ = nullptr;
|
||||
|
||||
public:
|
||||
explicit RecordDevice(std::shared_ptr<Device> device, const std::string &file, bool compressionEnabled = true) {
|
||||
ob_error *error = nullptr;
|
||||
impl_ = ob_create_record_device(device->getImpl(), file.c_str(), compressionEnabled, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
virtual ~RecordDevice() noexcept {
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_record_device(impl_, &error);
|
||||
Error::handle(&error, false);
|
||||
}
|
||||
|
||||
RecordDevice(RecordDevice &&other) noexcept {
|
||||
if(this != &other) {
|
||||
impl_ = other.impl_;
|
||||
other.impl_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RecordDevice &operator=(RecordDevice &&other) noexcept {
|
||||
if(this != &other) {
|
||||
impl_ = other.impl_;
|
||||
other.impl_ = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
RecordDevice(const RecordDevice &) = delete;
|
||||
RecordDevice &operator=(const RecordDevice &) = delete;
|
||||
|
||||
public:
|
||||
void pause() {
|
||||
ob_error *error = nullptr;
|
||||
ob_record_device_pause(impl_, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
void resume() {
|
||||
ob_error *error = nullptr;
|
||||
ob_record_device_resume(impl_, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
};
|
||||
|
||||
class PlaybackDevice : public Device {
|
||||
public:
|
||||
explicit PlaybackDevice(const std::string &file) : Device(nullptr) {
|
||||
ob_error *error = nullptr;
|
||||
impl_ = ob_create_playback_device(file.c_str(), &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
virtual ~PlaybackDevice() noexcept override = default;
|
||||
|
||||
PlaybackDevice(PlaybackDevice &&other) noexcept : Device(std::move(other)) {}
|
||||
|
||||
PlaybackDevice &operator=(PlaybackDevice &&other) noexcept {
|
||||
Device::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
PlaybackDevice(const PlaybackDevice &) = delete;
|
||||
PlaybackDevice &operator=(const PlaybackDevice &) = delete;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Pause the streaming data from the playback device.
|
||||
*/
|
||||
void pause() {
|
||||
ob_error *error = nullptr;
|
||||
ob_playback_device_pause(impl_, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume the streaming data from the playback device.
|
||||
*/
|
||||
void resume() {
|
||||
ob_error *error = nullptr;
|
||||
ob_playback_device_resume(impl_, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Seek to a specific timestamp when playing back a recording.
|
||||
* @param[in] timestamp The timestamp to seek to, in milliseconds.
|
||||
*/
|
||||
void seek(const int64_t timestamp) {
|
||||
ob_error *error = nullptr;
|
||||
ob_playback_device_seek(impl_, timestamp, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the playback rate of the playback device.
|
||||
* @param[in] rate The playback rate to set.
|
||||
*/
|
||||
void setPlaybackRate(const float rate) {
|
||||
ob_error *error = nullptr;
|
||||
ob_playback_device_set_playback_rate(impl_, rate, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a callback function to be called when the playback status changes.
|
||||
* @param[in] callback The callback function to set.
|
||||
*/
|
||||
void setPlaybackStatusChangeCallback(PlaybackStatusChangeCallback callback) {
|
||||
callback_ = callback;
|
||||
ob_error *error = nullptr;
|
||||
ob_playback_device_set_playback_status_changed_callback(impl_, &PlaybackDevice::playbackStatusCallback, this, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current playback status of the playback device.
|
||||
* @return The current playback status.
|
||||
*/
|
||||
OBPlaybackStatus getPlaybackStatus() const {
|
||||
ob_error *error = nullptr;
|
||||
OBPlaybackStatus status = ob_playback_device_get_current_playback_status(impl_, &error);
|
||||
Error::handle(&error);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current position of the playback device.
|
||||
* @return The current position of the playback device, in milliseconds.
|
||||
*/
|
||||
uint64_t getPosition() const {
|
||||
ob_error *error = nullptr;
|
||||
uint64_t position = ob_playback_device_get_position(impl_, &error);
|
||||
Error::handle(&error);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the duration of the playback device.
|
||||
* @return The duration of the playback device, in milliseconds.
|
||||
*/
|
||||
uint64_t getDuration() const {
|
||||
ob_error *error = nullptr;
|
||||
uint64_t duration = ob_playback_device_get_duration(impl_, &error);
|
||||
Error::handle(&error);
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
private:
|
||||
static void playbackStatusCallback(OBPlaybackStatus status, void *userData) {
|
||||
auto *playbackDevice = static_cast<PlaybackDevice *>(userData);
|
||||
if(playbackDevice && playbackDevice->callback_) {
|
||||
playbackDevice->callback_(status);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
PlaybackStatusChangeCallback callback_;
|
||||
};
|
||||
} // namespace ob
|
||||
@@ -0,0 +1,236 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file Sensor.hpp
|
||||
* @brief Defines types related to sensors, which are used to obtain stream configurations, open and close streams, and set and get sensor properties.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "libobsensor/hpp/Filter.hpp"
|
||||
#include "libobsensor/h/Sensor.h"
|
||||
#include "libobsensor/h/Filter.h"
|
||||
#include "Error.hpp"
|
||||
#include "StreamProfile.hpp"
|
||||
#include "Device.hpp"
|
||||
#include "Frame.hpp"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace ob {
|
||||
|
||||
class Sensor {
|
||||
public:
|
||||
/**
|
||||
* @brief Callback function for frame data.
|
||||
*
|
||||
* @param frame The frame data.
|
||||
*/
|
||||
typedef std::function<void(std::shared_ptr<Frame> frame)> FrameCallback;
|
||||
|
||||
protected:
|
||||
ob_sensor_t *impl_;
|
||||
FrameCallback callback_;
|
||||
|
||||
public:
|
||||
explicit Sensor(ob_sensor_t *impl) : impl_(impl) {}
|
||||
|
||||
Sensor(Sensor &&sensor) noexcept : impl_(sensor.impl_) {
|
||||
sensor.impl_ = nullptr;
|
||||
}
|
||||
|
||||
Sensor &operator=(Sensor &&sensor) noexcept {
|
||||
if(this != &sensor) {
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_sensor(impl_, &error);
|
||||
Error::handle(&error);
|
||||
impl_ = sensor.impl_;
|
||||
sensor.impl_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Sensor(const Sensor &sensor) = delete;
|
||||
Sensor &operator=(const Sensor &sensor) = delete;
|
||||
|
||||
virtual ~Sensor() noexcept {
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_sensor(impl_, &error);
|
||||
Error::handle(&error, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the sensor type.
|
||||
*
|
||||
* @return OBSensorType The sensor type.
|
||||
*/
|
||||
OBSensorType getType() const {
|
||||
ob_error *error = nullptr;
|
||||
auto type = ob_sensor_get_type(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the list of stream profiles.
|
||||
*
|
||||
* @return std::shared_ptr<StreamProfileList> The stream profile list.
|
||||
*/
|
||||
std::shared_ptr<StreamProfileList> getStreamProfileList() const {
|
||||
ob_error *error = nullptr;
|
||||
auto list = ob_sensor_get_stream_profile_list(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return std::make_shared<StreamProfileList>(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a list of recommended filters for the sensor.
|
||||
*
|
||||
* @return OBFilterList list of frame processing block
|
||||
*/
|
||||
std::vector<std::shared_ptr<Filter>> createRecommendedFilters() const {
|
||||
ob_error *error = nullptr;
|
||||
auto list = ob_sensor_create_recommended_filter_list(impl_, &error);
|
||||
Error::handle(&error);
|
||||
auto filter_count = ob_filter_list_get_count(list, &error);
|
||||
|
||||
std::vector<std::shared_ptr<Filter>> filters;
|
||||
for(uint32_t i = 0; i < filter_count; i++) {
|
||||
auto filterImpl = ob_filter_list_get_filter(list, i, &error);
|
||||
Error::handle(&error);
|
||||
filters.push_back(std::make_shared<Filter>(filterImpl));
|
||||
}
|
||||
ob_delete_filter_list(list, &error);
|
||||
Error::handle(&error, false);
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Open a frame data stream and set up a callback.
|
||||
*
|
||||
* @param streamProfile The stream configuration.
|
||||
* @param callback The callback to set when frame data arrives.
|
||||
*/
|
||||
void start(std::shared_ptr<StreamProfile> streamProfile, FrameCallback callback) {
|
||||
ob_error *error = nullptr;
|
||||
callback_ = std::move(callback);
|
||||
ob_sensor_start(impl_, const_cast<ob_stream_profile_t *>(streamProfile->getImpl()), &Sensor::frameCallback, this, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the stream.
|
||||
*/
|
||||
void stop() const {
|
||||
ob_error *error = nullptr;
|
||||
ob_sensor_stop(impl_, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dynamically switch resolutions.
|
||||
*
|
||||
* @param streamProfile The resolution to switch to.
|
||||
*/
|
||||
void switchProfile(std::shared_ptr<StreamProfile> streamProfile) {
|
||||
ob_error *error = nullptr;
|
||||
ob_sensor_switch_profile(impl_, const_cast<ob_stream_profile_t *>(streamProfile->getImpl()), &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
private:
|
||||
static void frameCallback(ob_frame *frame, void *userData) {
|
||||
auto sensor = static_cast<Sensor *>(userData);
|
||||
sensor->callback_(std::make_shared<Frame>(frame));
|
||||
}
|
||||
|
||||
public:
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
OBSensorType type() const {
|
||||
return getType();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Filter>> getRecommendedFilters() const {
|
||||
return createRecommendedFilters();
|
||||
}
|
||||
};
|
||||
|
||||
class SensorList {
|
||||
private:
|
||||
ob_sensor_list_t *impl_ = nullptr;
|
||||
|
||||
public:
|
||||
explicit SensorList(ob_sensor_list_t *impl) : impl_(impl) {}
|
||||
|
||||
~SensorList() noexcept {
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_sensor_list(impl_, &error);
|
||||
Error::handle(&error, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the number of sensors.
|
||||
*
|
||||
* @return uint32_t The number of sensors.
|
||||
*/
|
||||
uint32_t getCount() const {
|
||||
ob_error *error = nullptr;
|
||||
auto count = ob_sensor_list_get_count(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the type of the specified sensor.
|
||||
*
|
||||
* @param index The sensor index.
|
||||
* @return OBSensorType The sensor type.
|
||||
*/
|
||||
OBSensorType getSensorType(uint32_t index) const {
|
||||
ob_error *error = nullptr;
|
||||
auto type = ob_sensor_list_get_sensor_type(impl_, index, &error);
|
||||
Error::handle(&error);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a sensor by index number.
|
||||
*
|
||||
* @param index The sensor index. The range is [0, count-1]. If the index exceeds the range, an exception will be thrown.
|
||||
* @return std::shared_ptr<Sensor> The sensor object.
|
||||
*/
|
||||
std::shared_ptr<Sensor> getSensor(uint32_t index) const {
|
||||
ob_error *error = nullptr;
|
||||
auto sensor = ob_sensor_list_get_sensor(impl_, index, &error);
|
||||
Error::handle(&error);
|
||||
return std::make_shared<Sensor>(sensor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a sensor by sensor type.
|
||||
*
|
||||
* @param sensorType The sensor type to obtain.
|
||||
* @return std::shared_ptr<Sensor> A sensor object. If the specified sensor type does not exist, it will return empty.
|
||||
*/
|
||||
std::shared_ptr<Sensor> getSensor(OBSensorType sensorType) const {
|
||||
ob_error *error = nullptr;
|
||||
auto sensor = ob_sensor_list_get_sensor_by_type(impl_, sensorType, &error);
|
||||
Error::handle(&error);
|
||||
return std::make_shared<Sensor>(sensor);
|
||||
}
|
||||
|
||||
public:
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
uint32_t count() const {
|
||||
return getCount();
|
||||
}
|
||||
|
||||
OBSensorType type(uint32_t index) const {
|
||||
return getSensorType(index);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ob
|
||||
|
||||
@@ -0,0 +1,523 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file StreamProfile.hpp
|
||||
* @brief The stream profile related type is used to get information such as the width, height, frame rate, and format of the stream.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "libobsensor/h/StreamProfile.h"
|
||||
#include "libobsensor/h/Error.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
namespace ob {
|
||||
|
||||
class StreamProfile : public std::enable_shared_from_this<StreamProfile> {
|
||||
protected:
|
||||
const ob_stream_profile_t *impl_ = nullptr;
|
||||
|
||||
public:
|
||||
StreamProfile(StreamProfile &streamProfile) = delete;
|
||||
StreamProfile &operator=(StreamProfile &streamProfile) = delete;
|
||||
|
||||
StreamProfile(StreamProfile &&streamProfile) noexcept : impl_(streamProfile.impl_) {
|
||||
streamProfile.impl_ = nullptr;
|
||||
}
|
||||
|
||||
StreamProfile &operator=(StreamProfile &&streamProfile) noexcept {
|
||||
if(this != &streamProfile) {
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_stream_profile(impl_, &error);
|
||||
Error::handle(&error);
|
||||
impl_ = streamProfile.impl_;
|
||||
streamProfile.impl_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~StreamProfile() noexcept {
|
||||
if(impl_) {
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_stream_profile(impl_, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
}
|
||||
|
||||
const ob_stream_profile *getImpl() const {
|
||||
return impl_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the format of the stream.
|
||||
*
|
||||
* @return OBFormat return the format of the stream.
|
||||
*/
|
||||
OBFormat getFormat() const {
|
||||
ob_error *error = nullptr;
|
||||
auto format = ob_stream_profile_get_format(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the type of stream.
|
||||
*
|
||||
* @return OBStreamType return the type of the stream.
|
||||
*/
|
||||
OBStreamType getType() const {
|
||||
ob_error *error = nullptr;
|
||||
auto type = ob_stream_profile_get_type(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the extrinsic parameters from current stream profile to the given target stream profile.
|
||||
*
|
||||
* @return OBExtrinsic Return the extrinsic parameters.
|
||||
*/
|
||||
OBExtrinsic getExtrinsicTo(std::shared_ptr<StreamProfile> target) const {
|
||||
ob_error *error = nullptr;
|
||||
auto extrinsic = ob_stream_profile_get_extrinsic_to(impl_, const_cast<ob_stream_profile_t *>(target->getImpl()), &error);
|
||||
Error::handle(&error);
|
||||
return extrinsic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the extrinsic parameters from current stream profile to the given target stream profile.
|
||||
*
|
||||
* @tparam target Target stream profile.
|
||||
* @tparam extrinsic The extrinsic.
|
||||
*/
|
||||
void bindExtrinsicTo(std::shared_ptr<StreamProfile> target, const OBExtrinsic &extrinsic) {
|
||||
ob_error *error = nullptr;
|
||||
ob_stream_profile_set_extrinsic_to(const_cast<ob_stream_profile_t *>(impl_), const_cast<const ob_stream_profile_t *>(target->getImpl()), extrinsic, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the extrinsic parameters from current stream profile to the given target stream type.
|
||||
*
|
||||
* @tparam targetStreamType Target stream type.
|
||||
* @tparam extrinsic The extrinsic.
|
||||
*/
|
||||
void bindExtrinsicTo(const OBStreamType &targetStreamType, const OBExtrinsic &extrinsic) {
|
||||
ob_error *error = nullptr;
|
||||
ob_stream_profile_set_extrinsic_to_type(const_cast<ob_stream_profile_t *>(impl_),targetStreamType,extrinsic, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if frame object is compatible with the given type.
|
||||
*
|
||||
* @tparam T Given type.
|
||||
* @return bool return result.
|
||||
*/
|
||||
template <typename T> bool is() const;
|
||||
|
||||
/**
|
||||
* @brief Converts object type to target type.
|
||||
*
|
||||
* @tparam T Target type.
|
||||
* @return std::shared_ptr<T> Return the result. Throws an exception if conversion is not possible.
|
||||
*/
|
||||
template <typename T> std::shared_ptr<T> as() {
|
||||
if(!is<T>()) {
|
||||
throw std::runtime_error("Unsupported operation. Object's type is not the required type.");
|
||||
}
|
||||
|
||||
return std::dynamic_pointer_cast<T>(shared_from_this());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts object type to target type (const version).
|
||||
*
|
||||
* @tparam T Target type.
|
||||
* @return std::shared_ptr<T> Return the result. Throws an exception if conversion is not possible.
|
||||
*/
|
||||
template <typename T> std::shared_ptr<const T> as() const {
|
||||
if(!is<T>()) {
|
||||
throw std::runtime_error("Unsupported operation. Object's type is not the required type.");
|
||||
}
|
||||
|
||||
return std::static_pointer_cast<const T>(shared_from_this());
|
||||
}
|
||||
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
OBFormat format() const {
|
||||
return getFormat();
|
||||
}
|
||||
|
||||
OBStreamType type() const {
|
||||
return getType();
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit StreamProfile(const ob_stream_profile_t *impl) : impl_(impl) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class representing a video stream profile.
|
||||
*/
|
||||
class VideoStreamProfile : public StreamProfile {
|
||||
public:
|
||||
explicit VideoStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
|
||||
|
||||
~VideoStreamProfile() noexcept override = default;
|
||||
|
||||
/**
|
||||
* @brief Return the frame rate of the stream.
|
||||
*
|
||||
* @return uint32_t Return the frame rate of the stream.
|
||||
*/
|
||||
uint32_t getFps() const {
|
||||
ob_error *error = nullptr;
|
||||
auto fps = ob_video_stream_profile_get_fps(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return fps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the width of the stream.
|
||||
*
|
||||
* @return uint32_t Return the width of the stream.
|
||||
*/
|
||||
uint32_t getWidth() const {
|
||||
ob_error *error = nullptr;
|
||||
auto width = ob_video_stream_profile_get_width(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the height of the stream.
|
||||
*
|
||||
* @return uint32_t Return the height of the stream.
|
||||
*/
|
||||
uint32_t getHeight() const {
|
||||
ob_error *error = nullptr;
|
||||
auto height = ob_video_stream_profile_get_height(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the intrinsic parameters of the stream.
|
||||
*
|
||||
* @return OBCameraIntrinsic Return the intrinsic parameters.
|
||||
*/
|
||||
OBCameraIntrinsic getIntrinsic() const {
|
||||
ob_error *error = nullptr;
|
||||
auto intrinsic = ob_video_stream_profile_get_intrinsic(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return intrinsic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the intrinsic parameters of the stream.
|
||||
*
|
||||
* @param intrinsic The intrinsic parameters.
|
||||
*/
|
||||
void setIntrinsic(const OBCameraIntrinsic &intrinsic) {
|
||||
ob_error *error = nullptr;
|
||||
ob_video_stream_profile_set_intrinsic(const_cast<ob_stream_profile_t *>(impl_), intrinsic, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the distortion parameters of the stream.
|
||||
* @brief Brown distortion model
|
||||
*
|
||||
* @return OBCameraDistortion Return the distortion parameters.
|
||||
*/
|
||||
OBCameraDistortion getDistortion() const {
|
||||
ob_error *error = nullptr;
|
||||
auto distortion = ob_video_stream_profile_get_distortion(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return distortion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the distortion parameters of the stream.
|
||||
*
|
||||
* @param distortion The distortion parameters.
|
||||
*/
|
||||
void setDistortion(const OBCameraDistortion &distortion) {
|
||||
ob_error *error = nullptr;
|
||||
ob_video_stream_profile_set_distortion(const_cast<ob_stream_profile_t *>(impl_), distortion, &error);
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
public:
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
uint32_t fps() const {
|
||||
return getFps();
|
||||
}
|
||||
|
||||
uint32_t width() const {
|
||||
return getWidth();
|
||||
}
|
||||
|
||||
uint32_t height() const {
|
||||
return getHeight();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class representing an accelerometer stream profile.
|
||||
*/
|
||||
class AccelStreamProfile : public StreamProfile {
|
||||
public:
|
||||
explicit AccelStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
|
||||
|
||||
~AccelStreamProfile() noexcept override = default;
|
||||
|
||||
/**
|
||||
* @brief Return the full scale range.
|
||||
*
|
||||
* @return OBAccelFullScaleRange Return the scale range value.
|
||||
*/
|
||||
OBAccelFullScaleRange getFullScaleRange() const {
|
||||
ob_error *error = nullptr;
|
||||
auto fullScaleRange = ob_accel_stream_profile_get_full_scale_range(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return fullScaleRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the sampling frequency.
|
||||
*
|
||||
* @return OBAccelFullScaleRange Return the sampling frequency.
|
||||
*/
|
||||
OBAccelSampleRate getSampleRate() const {
|
||||
ob_error *error = nullptr;
|
||||
auto sampleRate = ob_accel_stream_profile_get_sample_rate(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the intrinsic parameters of the stream.
|
||||
*
|
||||
* @return OBAccelIntrinsic Return the intrinsic parameters.
|
||||
*/
|
||||
OBAccelIntrinsic getIntrinsic() const {
|
||||
ob_error *error = nullptr;
|
||||
auto intrinsic = ob_accel_stream_profile_get_intrinsic(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return intrinsic;
|
||||
}
|
||||
|
||||
public:
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
OBAccelFullScaleRange fullScaleRange() const {
|
||||
return getFullScaleRange();
|
||||
}
|
||||
|
||||
OBAccelSampleRate sampleRate() const {
|
||||
return getSampleRate();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class representing a gyroscope stream profile.
|
||||
*/
|
||||
class GyroStreamProfile : public StreamProfile {
|
||||
public:
|
||||
explicit GyroStreamProfile(const ob_stream_profile_t *impl) : StreamProfile(impl) {}
|
||||
|
||||
~GyroStreamProfile() noexcept override = default;
|
||||
|
||||
/**
|
||||
* @brief Return the full scale range.
|
||||
*
|
||||
* @return OBAccelFullScaleRange Return the scale range value.
|
||||
*/
|
||||
OBGyroFullScaleRange getFullScaleRange() const {
|
||||
ob_error *error = nullptr;
|
||||
auto fullScaleRange = ob_gyro_stream_profile_get_full_scale_range(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return fullScaleRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the sampling frequency.
|
||||
*
|
||||
* @return OBAccelFullScaleRange Return the sampling frequency.
|
||||
*/
|
||||
OBGyroSampleRate getSampleRate() const {
|
||||
ob_error *error = nullptr;
|
||||
auto sampleRate = ob_gyro_stream_profile_get_sample_rate(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the intrinsic parameters of the stream.
|
||||
*
|
||||
* @return OBGyroIntrinsic Return the intrinsic parameters.
|
||||
*/
|
||||
OBGyroIntrinsic getIntrinsic() const {
|
||||
ob_error *error = nullptr;
|
||||
auto intrinsic = ob_gyro_stream_get_intrinsic(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return intrinsic;
|
||||
}
|
||||
|
||||
public:
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
OBGyroFullScaleRange fullScaleRange() const {
|
||||
return getFullScaleRange();
|
||||
}
|
||||
|
||||
OBGyroSampleRate sampleRate() const {
|
||||
return getSampleRate();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> bool StreamProfile::is() const {
|
||||
switch(this->getType()) {
|
||||
case OB_STREAM_VIDEO:
|
||||
case OB_STREAM_IR:
|
||||
case OB_STREAM_IR_LEFT:
|
||||
case OB_STREAM_IR_RIGHT:
|
||||
case OB_STREAM_COLOR:
|
||||
case OB_STREAM_DEPTH:
|
||||
case OB_STREAM_RAW_PHASE:
|
||||
case OB_STREAM_CONFIDENCE:
|
||||
return typeid(T) == typeid(VideoStreamProfile);
|
||||
case OB_STREAM_ACCEL:
|
||||
return typeid(T) == typeid(AccelStreamProfile);
|
||||
case OB_STREAM_GYRO:
|
||||
return typeid(T) == typeid(GyroStreamProfile);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class StreamProfileFactory {
|
||||
public:
|
||||
static std::shared_ptr<StreamProfile> create(const ob_stream_profile_t *impl) {
|
||||
ob_error *error = nullptr;
|
||||
const auto type = ob_stream_profile_get_type(impl, &error);
|
||||
Error::handle(&error);
|
||||
switch(type) {
|
||||
case OB_STREAM_IR:
|
||||
case OB_STREAM_IR_LEFT:
|
||||
case OB_STREAM_IR_RIGHT:
|
||||
case OB_STREAM_DEPTH:
|
||||
case OB_STREAM_COLOR:
|
||||
case OB_STREAM_VIDEO:
|
||||
case OB_STREAM_CONFIDENCE:
|
||||
return std::make_shared<VideoStreamProfile>(impl);
|
||||
case OB_STREAM_ACCEL:
|
||||
return std::make_shared<AccelStreamProfile>(impl);
|
||||
case OB_STREAM_GYRO:
|
||||
return std::make_shared<GyroStreamProfile>(impl);
|
||||
default: {
|
||||
ob_error *err = ob_create_error(OB_STATUS_ERROR, "Unsupported stream type.", "StreamProfileFactory::create", "", OB_EXCEPTION_TYPE_INVALID_VALUE);
|
||||
Error::handle(&err);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class StreamProfileList {
|
||||
protected:
|
||||
const ob_stream_profile_list_t *impl_;
|
||||
|
||||
public:
|
||||
explicit StreamProfileList(ob_stream_profile_list_t *impl) : impl_(impl) {}
|
||||
~StreamProfileList() noexcept {
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_stream_profile_list(impl_, &error);
|
||||
Error::handle(&error, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the number of StreamProfile objects.
|
||||
*
|
||||
* @return uint32_t Return the number of StreamProfile objects.
|
||||
*/
|
||||
uint32_t getCount() const {
|
||||
ob_error *error = nullptr;
|
||||
auto count = ob_stream_profile_list_get_count(impl_, &error);
|
||||
Error::handle(&error);
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the StreamProfile object at the specified index.
|
||||
*
|
||||
* @param index The index of the StreamProfile object to be retrieved. Must be in the range [0, count-1]. Throws an exception if the index is out of range.
|
||||
* @return std::shared_ptr<StreamProfile> Return the StreamProfile object.
|
||||
*/
|
||||
std::shared_ptr<StreamProfile> getProfile(uint32_t index) const {
|
||||
ob_error *error = nullptr;
|
||||
auto profile = ob_stream_profile_list_get_profile(impl_, index, &error);
|
||||
Error::handle(&error);
|
||||
return StreamProfileFactory::create(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Match the corresponding video stream profile based on the passed-in parameters. If multiple Match are found, the first one in the list is
|
||||
* returned by default. Throws an exception if no matching profile is found.
|
||||
*
|
||||
* @param width The width of the stream. Pass OB_WIDTH_ANY if no matching condition is required.
|
||||
* @param height The height of the stream. Pass OB_HEIGHT_ANY if no matching condition is required.
|
||||
* @param format The type of the stream. Pass OB_FORMAT_ANY if no matching condition is required.
|
||||
* @param fps The frame rate of the stream. Pass OB_FPS_ANY if no matching condition is required.
|
||||
* @return std::shared_ptr<VideoStreamProfile> Return the matching resolution.
|
||||
*/
|
||||
std::shared_ptr<VideoStreamProfile> getVideoStreamProfile(int width = OB_WIDTH_ANY, int height = OB_HEIGHT_ANY, OBFormat format = OB_FORMAT_ANY,
|
||||
int fps = OB_FPS_ANY) const {
|
||||
ob_error *error = nullptr;
|
||||
auto profile = ob_stream_profile_list_get_video_stream_profile(impl_, width, height, format, fps, &error);
|
||||
Error::handle(&error);
|
||||
auto vsp = StreamProfileFactory::create(profile);
|
||||
return vsp->as<VideoStreamProfile>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Match the corresponding accelerometer stream profile based on the passed-in parameters. If multiple Match are found, the first one in the list
|
||||
* is returned by default. Throws an exception if no matching profile is found.
|
||||
*
|
||||
* @param fullScaleRange The full scale range. Pass 0 if no matching condition is required.
|
||||
* @param sampleRate The sampling frequency. Pass 0 if no matching condition is required.
|
||||
*/
|
||||
std::shared_ptr<AccelStreamProfile> getAccelStreamProfile(OBAccelFullScaleRange fullScaleRange, OBAccelSampleRate sampleRate) const {
|
||||
ob_error *error = nullptr;
|
||||
auto profile = ob_stream_profile_list_get_accel_stream_profile(impl_, fullScaleRange, sampleRate, &error);
|
||||
Error::handle(&error);
|
||||
auto asp = StreamProfileFactory::create(profile);
|
||||
return asp->as<AccelStreamProfile>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Match the corresponding gyroscope stream profile based on the passed-in parameters. If multiple Match are found, the first one in the list is
|
||||
* returned by default. Throws an exception if no matching profile is found.
|
||||
*
|
||||
* @param fullScaleRange The full scale range. Pass 0 if no matching condition is required.
|
||||
* @param sampleRate The sampling frequency. Pass 0 if no matching condition is required.
|
||||
*/
|
||||
std::shared_ptr<GyroStreamProfile> getGyroStreamProfile(OBGyroFullScaleRange fullScaleRange, OBGyroSampleRate sampleRate) const {
|
||||
ob_error *error = nullptr;
|
||||
auto profile = ob_stream_profile_list_get_gyro_stream_profile(impl_, fullScaleRange, sampleRate, &error);
|
||||
Error::handle(&error);
|
||||
auto gsp = StreamProfileFactory::create(profile);
|
||||
return gsp->as<GyroStreamProfile>();
|
||||
}
|
||||
|
||||
public:
|
||||
// The following interfaces are deprecated and are retained here for compatibility purposes.
|
||||
uint32_t count() const {
|
||||
return getCount();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ob
|
||||
@@ -0,0 +1,145 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "libobsensor/h/ObTypes.h"
|
||||
#include "libobsensor/h/TypeHelper.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace ob {
|
||||
class TypeHelper {
|
||||
public:
|
||||
/**
|
||||
* @brief Convert OBFormat to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBFormat type.
|
||||
* @return OBFormat of "string" type.
|
||||
*/
|
||||
static std::string convertOBFormatTypeToString(const OBFormat &type) {
|
||||
return ob_format_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBFrameType to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBFrameType type.
|
||||
* @return OBFrameType of "string" type.
|
||||
*/
|
||||
static std::string convertOBFrameTypeToString(const OBFrameType &type) {
|
||||
return ob_frame_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBStreamType to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBStreamType type.
|
||||
* @return OBStreamType of "string" type.
|
||||
*/
|
||||
static std::string convertOBStreamTypeToString(const OBStreamType &type) {
|
||||
return ob_stream_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBSensorType to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBSensorType type.
|
||||
* @return OBSensorType of "string" type.
|
||||
*/
|
||||
static std::string convertOBSensorTypeToString(const OBSensorType &type) {
|
||||
return ob_sensor_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBIMUSampleRate to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBIMUSampleRate type.
|
||||
* @return OBIMUSampleRate of "string" type.
|
||||
*/
|
||||
static std::string convertOBIMUSampleRateTypeToString(const OBIMUSampleRate &type) {
|
||||
return ob_imu_rate_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBGyroFullScaleRange to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBGyroFullScaleRange type.
|
||||
* @return OBGyroFullScaleRange of "string" type.
|
||||
*/
|
||||
static std::string convertOBGyroFullScaleRangeTypeToString(const OBGyroFullScaleRange &type) {
|
||||
return ob_gyro_range_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBAccelFullScaleRange to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBAccelFullScaleRange type.
|
||||
* @return OBAccelFullScaleRange of "string" type.
|
||||
*/
|
||||
static std::string convertOBAccelFullScaleRangeTypeToString(const OBAccelFullScaleRange &type) {
|
||||
return ob_accel_range_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBFrameMetadataType to " string " type and then return.
|
||||
*
|
||||
* @param[in] type OBFrameMetadataType type.
|
||||
* @return OBFrameMetadataType of "string" type.
|
||||
*/
|
||||
static std::string convertOBFrameMetadataTypeToString(const OBFrameMetadataType &type) {
|
||||
return ob_meta_data_type_to_string(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert OBSensorType to OBStreamType type and then return.
|
||||
*
|
||||
* @param[in] type OBSensorType type.
|
||||
* @return OBStreamType type.
|
||||
*/
|
||||
static OBStreamType convertSensorTypeToStreamType(OBSensorType type) {
|
||||
return ob_sensor_type_to_stream_type(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the given sensor type is a video sensor.
|
||||
* @brief Video sensors are sensors that produce video frames.
|
||||
* @brief The following sensor types are considered video sensors:
|
||||
* OB_SENSOR_COLOR,
|
||||
* OB_SENSOR_DEPTH,
|
||||
* OB_SENSOR_IR,
|
||||
* OB_SENSOR_IR_LEFT,
|
||||
* OB_SENSOR_IR_RIGHT,
|
||||
* OB_SENSOR_CONFIDENCE,
|
||||
*
|
||||
* @param type The sensor type
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
static bool isVideoSensorType(OBSensorType type) {
|
||||
return ob_is_video_sensor_type(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the given stream type is a video stream.
|
||||
* @brief Video streams are streams that contain video frames.
|
||||
* @brief The following stream types are considered video streams:
|
||||
* OB_STREAM_VIDEO,
|
||||
* OB_STREAM_DEPTH,
|
||||
* OB_STREAM_COLOR,
|
||||
* OB_STREAM_IR,
|
||||
* OB_STREAM_IR_LEFT,
|
||||
* OB_STREAM_IR_RIGHT,
|
||||
* OB_STREAM_CONFIDENCE,
|
||||
*
|
||||
* @param type The stream type to check.
|
||||
* @return true if the given stream type is a video stream, false otherwise.
|
||||
*/
|
||||
static bool isVideoStreamType(OBStreamType type) {
|
||||
return ob_is_video_stream_type(type);
|
||||
}
|
||||
};
|
||||
} // namespace ob
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
#include <libobsensor/h/ObTypes.h>
|
||||
@@ -0,0 +1,190 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file Utils.hpp
|
||||
* @brief The SDK utils class
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "libobsensor/h/Utils.h"
|
||||
#include "Device.hpp"
|
||||
#include "Types.hpp"
|
||||
#include "Frame.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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;
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
};
|
||||
} // namespace ob
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) Orbbec Inc. All Rights Reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/**
|
||||
* @file Version.hpp
|
||||
* @brief Provides functions to retrieve version information of the SDK.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "libobsensor/h/Version.h"
|
||||
|
||||
namespace ob {
|
||||
class Version {
|
||||
public:
|
||||
/**
|
||||
* @brief Get the full version number of the SDK.
|
||||
* @brief The full version number equals to: major * 10000 + minor * 100 + patch
|
||||
*
|
||||
* @return int The full version number of the SDK.
|
||||
*/
|
||||
static int getVersion() {
|
||||
return ob_get_version();
|
||||
}
|
||||
/**
|
||||
* @brief Get the major version number of the SDK.
|
||||
*
|
||||
* @return int The major version number of the SDK.
|
||||
*/
|
||||
static int getMajor() {
|
||||
return ob_get_major_version();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the minor version number of the SDK.
|
||||
*
|
||||
* @return int The minor version number of the SDK.
|
||||
*/
|
||||
static int getMinor() {
|
||||
return ob_get_minor_version();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the patch version number of the SDK.
|
||||
*
|
||||
* @return int The patch version number of the SDK.
|
||||
*/
|
||||
static int getPatch() {
|
||||
return ob_get_patch_version();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the stage version of the SDK.
|
||||
* @brief The stage version string is a vendor defined string for some special releases.
|
||||
*
|
||||
* @return char* The stage version string of the SDK.
|
||||
*/
|
||||
static const char *getStageVersion() {
|
||||
return ob_get_stage_version();
|
||||
}
|
||||
};
|
||||
} // namespace ob
|
||||
|
||||
Reference in New Issue
Block a user