OrbbecSDK 2.5.5
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
Utils.hpp
Go to the documentation of this file.
1// Copyright (c) Orbbec Inc. All Rights Reserved.
2// Licensed under the MIT License.
3
9#pragma once
10#include "libobsensor/h/Utils.h"
11#include "Device.hpp"
12#include "Types.hpp"
13#include "Frame.hpp"
14
15#include <memory>
16
17namespace ob {
18class Device;
19
21public:
31 static bool transformation3dto3d(const OBPoint3f source_point3f, OBExtrinsic extrinsic, OBPoint3f *target_point3f) {
32 ob_error *error = NULL;
33 bool result = ob_transformation_3d_to_3d(source_point3f, extrinsic, target_point3f, &error);
34 Error::handle(&error);
35 return result;
36 }
37
49 static bool transformation2dto3d(const OBPoint2f source_point2f, const float source_depth_pixel_value, const OBCameraIntrinsic source_intrinsic,
50 OBExtrinsic extrinsic, OBPoint3f *target_point3f) {
51 ob_error *error = NULL;
52 bool result = ob_transformation_2d_to_3d(source_point2f, source_depth_pixel_value, source_intrinsic, extrinsic, target_point3f, &error);
53 Error::handle(&error);
54 return result;
55 }
56
68 static bool transformation3dto2d(const OBPoint3f source_point3f, const OBCameraIntrinsic target_intrinsic, const OBCameraDistortion target_distortion,
69 OBExtrinsic extrinsic, OBPoint2f *target_point2f) {
70 ob_error *error = NULL;
71 bool result = ob_transformation_3d_to_2d(source_point3f, target_intrinsic, target_distortion, extrinsic, target_point2f, &error);
72 Error::handle(&error);
73 return result;
74 }
75
90 static bool transformation2dto2d(const OBPoint2f source_point2f, const float source_depth_pixel_value, const OBCameraIntrinsic source_intrinsic,
91 const OBCameraDistortion source_distortion, const OBCameraIntrinsic target_intrinsic,
92 const OBCameraDistortion target_distortion, OBExtrinsic extrinsic, OBPoint2f *target_point2f) {
93 ob_error *error = NULL;
94 bool result = ob_transformation_2d_to_2d(source_point2f, source_depth_pixel_value, source_intrinsic, source_distortion, target_intrinsic,
95 target_distortion, extrinsic, target_point2f, &error);
96 Error::handle(&error);
97 return result;
98 }
99
100public:
101 // The following interfaces are deprecated and are retained here for compatibility purposes.
102 static bool calibration3dTo3d(const OBCalibrationParam calibrationParam, const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType,
103 const OBSensorType targetSensorType, OBPoint3f *targetPoint3f) {
104 ob_error *error = NULL;
105 bool result = ob_calibration_3d_to_3d(calibrationParam, sourcePoint3f, sourceSensorType, targetSensorType, targetPoint3f, &error);
106 Error::handle(&error);
107 return result;
108 }
109
110 static bool calibration2dTo3d(const OBCalibrationParam calibrationParam, const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue,
111 const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint3f *targetPoint3f) {
112 ob_error *error = NULL;
113 bool result =
114 ob_calibration_2d_to_3d(calibrationParam, sourcePoint2f, sourceDepthPixelValue, sourceSensorType, targetSensorType, targetPoint3f, &error);
115 Error::handle(&error);
116 return result;
117 }
118
119 static bool calibration3dTo2d(const OBCalibrationParam calibrationParam, const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType,
120 const OBSensorType targetSensorType, OBPoint2f *targetPoint2f) {
121 ob_error *error = NULL;
122 bool result = ob_calibration_3d_to_2d(calibrationParam, sourcePoint3f, sourceSensorType, targetSensorType, targetPoint2f, &error);
123 Error::handle(&error);
124 return result;
125 }
126
127 static bool calibration2dTo2d(const OBCalibrationParam calibrationParam, const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue,
128 const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint2f *targetPoint2f) {
129 ob_error *error = NULL;
130 bool result =
131 ob_calibration_2d_to_2d(calibrationParam, sourcePoint2f, sourceDepthPixelValue, sourceSensorType, targetSensorType, targetPoint2f, &error);
132 Error::handle(&error);
133 return result;
134 }
135
136 static std::shared_ptr<ob::Frame> transformationDepthFrameToColorCamera(std::shared_ptr<ob::Device> device, std::shared_ptr<ob::Frame> depthFrame,
137 uint32_t targetColorCameraWidth, uint32_t targetColorCameraHeight) {
138 ob_error *error = NULL;
139
140 // unsafe operation, need to cast const to non-const
141 auto unConstImpl = const_cast<ob_frame *>(depthFrame->getImpl());
142
143 auto result = transformation_depth_frame_to_color_camera(device->getImpl(), unConstImpl, targetColorCameraWidth, targetColorCameraHeight, &error);
144 Error::handle(&error);
145 return std::make_shared<ob::Frame>(result);
146 }
147
148 static bool transformationInitXYTables(const OBCalibrationParam calibrationParam, const OBSensorType sensorType, float *data, uint32_t *dataSize,
149 OBXYTables *xyTables) {
150 ob_error *error = NULL;
151 bool result = transformation_init_xy_tables(calibrationParam, sensorType, data, dataSize, xyTables, &error);
152 Error::handle(&error);
153 return result;
154 }
155
156 static void transformationDepthToPointCloud(OBXYTables *xyTables, const void *depthImageData, void *pointCloudData) {
157 ob_error *error = NULL;
158 transformation_depth_to_pointcloud(xyTables, depthImageData, pointCloudData, &error);
159 Error::handle(&error, false);
160 }
161
162 static void transformationDepthToRGBDPointCloud(OBXYTables *xyTables, const void *depthImageData, const void *colorImageData, void *pointCloudData) {
163 ob_error *error = NULL;
164 transformation_depth_to_rgbd_pointcloud(xyTables, depthImageData, colorImageData, pointCloudData, &error);
165 Error::handle(&error, false);
166 }
167};
168
170public:
182 static bool savePointcloudToPly(const char *fileName, std::shared_ptr<ob::Frame> frame, bool saveBinary, bool useMesh, float meshThreshold) {
183 ob_error *error = NULL;
184 auto unConstImpl = const_cast<ob_frame *>(frame->getImpl());
185 bool result = ob_save_pointcloud_to_ply(fileName, unConstImpl, saveBinary, useMesh, meshThreshold, &error);
186 Error::handle(&error, false);
187 return result;
188 }
189};
190} // namespace ob
Device related types, including operations such as getting and creating a device, setting and obtaini...
Frame related type, which is mainly used to obtain frame data and frame information.
struct ob_frame_t ob_frame
Definition ObTypes.h:33
OBSensorType
Enumeration value describing the sensor type.
Definition ObTypes.h:128
struct OBPoint OBPoint3f
struct OBD2CTransform OBExtrinsic
OB_EXPORT bool ob_transformation_3d_to_2d(const OBPoint3f source_point3f, const OBCameraIntrinsic target_intrinsic, const OBCameraDistortion target_distortion, OBExtrinsic extrinsic, OBPoint2f *target_point2f, ob_error **error)
Transform a 3d point of a source coordinate system into a 2d pixel coordinate of the target camera.
OB_EXPORT bool ob_calibration_3d_to_3d(const ob_calibration_param calibration_param, const ob_point3f source_point3f, const ob_sensor_type source_sensor_type, const ob_sensor_type target_sensor_type, ob_point3f *target_point3f, ob_error **error)
OB_EXPORT void transformation_depth_to_rgbd_pointcloud(ob_xy_tables *xy_tables, const void *depth_image_data, const void *color_image_data, void *pointcloud_data, ob_error **error)
OB_EXPORT void transformation_depth_to_pointcloud(ob_xy_tables *xy_tables, const void *depth_image_data, void *pointcloud_data, ob_error **error)
OB_EXPORT bool ob_calibration_2d_to_3d(const ob_calibration_param calibration_param, const ob_point2f source_point2f, const float source_depth_pixel_value, const ob_sensor_type source_sensor_type, const ob_sensor_type target_sensor_type, ob_point3f *target_point3f, ob_error **error)
OB_EXPORT bool ob_transformation_3d_to_3d(const OBPoint3f source_point3f, OBExtrinsic extrinsic, OBPoint3f *target_point3f, ob_error **error)
Transform a 3d point of a source coordinate system into a 3d point of the target coordinate system.
OB_EXPORT bool ob_calibration_3d_to_2d(const ob_calibration_param calibration_param, const ob_point3f source_point3f, const ob_sensor_type source_sensor_type, const ob_sensor_type target_sensor_type, ob_point2f *target_point2f, ob_error **error)
OB_EXPORT bool transformation_init_xy_tables(const ob_calibration_param calibration_param, const ob_sensor_type sensor_type, float *data, uint32_t *data_size, ob_xy_tables *xy_tables, ob_error **error)
OB_EXPORT ob_frame * transformation_depth_frame_to_color_camera(ob_device *device, ob_frame *depth_frame, uint32_t target_color_camera_width, uint32_t target_color_camera_height, ob_error **error)
OB_EXPORT bool ob_transformation_2d_to_3d(const OBPoint2f source_point2f, const float source_depth_pixel_value, const OBCameraIntrinsic source_intrinsic, OBExtrinsic extrinsic, OBPoint3f *target_point3f, ob_error **error)
Transform a 2d pixel coordinate with an associated depth value of the source camera into a 3d point o...
OB_EXPORT bool ob_save_pointcloud_to_ply(const char *file_name, ob_frame *frame, bool save_binary, bool use_mesh, float mesh_threshold, ob_error **error)
save point cloud to ply file.
OB_EXPORT bool ob_calibration_2d_to_2d(const ob_calibration_param calibration_param, const ob_point2f source_point2f, const float source_depth_pixel_value, const ob_sensor_type source_sensor_type, const ob_sensor_type target_sensor_type, ob_point2f *target_point2f, ob_error **error)
OB_EXPORT bool ob_transformation_2d_to_2d(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)
Transform a 2d pixel coordinate with an associated depth value of the source camera into a 2d pixel c...
static bool calibration3dTo2d(const OBCalibrationParam calibrationParam, const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint2f *targetPoint2f)
Definition Utils.hpp:119
static bool transformation2dto3d(const OBPoint2f source_point2f, const float source_depth_pixel_value, const OBCameraIntrinsic source_intrinsic, OBExtrinsic extrinsic, OBPoint3f *target_point3f)
Transform a 2d pixel coordinate with an associated depth value of the source camera into a 3d point o...
Definition Utils.hpp:49
static bool calibration2dTo2d(const OBCalibrationParam calibrationParam, const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue, const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint2f *targetPoint2f)
Definition Utils.hpp:127
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)
Transform a 2d pixel coordinate with an associated depth value of the source camera into a 2d pixel c...
Definition Utils.hpp:90
static bool calibration3dTo3d(const OBCalibrationParam calibrationParam, const OBPoint3f sourcePoint3f, const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint3f *targetPoint3f)
Definition Utils.hpp:102
static bool transformation3dto3d(const OBPoint3f source_point3f, OBExtrinsic extrinsic, OBPoint3f *target_point3f)
Transform a 3d point of a source coordinate system into a 3d point of the target coordinate system.
Definition Utils.hpp:31
static bool transformationInitXYTables(const OBCalibrationParam calibrationParam, const OBSensorType sensorType, float *data, uint32_t *dataSize, OBXYTables *xyTables)
Definition Utils.hpp:148
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)
Definition Utils.hpp:136
static bool transformation3dto2d(const OBPoint3f source_point3f, const OBCameraIntrinsic target_intrinsic, const OBCameraDistortion target_distortion, OBExtrinsic extrinsic, OBPoint2f *target_point2f)
Transform a 3d point of a source coordinate system into a 2d pixel coordinate of the target camera.
Definition Utils.hpp:68
static void transformationDepthToPointCloud(OBXYTables *xyTables, const void *depthImageData, void *pointCloudData)
Definition Utils.hpp:156
static void transformationDepthToRGBDPointCloud(OBXYTables *xyTables, const void *depthImageData, const void *colorImageData, void *pointCloudData)
Definition Utils.hpp:162
static bool calibration2dTo3d(const OBCalibrationParam calibrationParam, const OBPoint2f sourcePoint2f, const float sourceDepthPixelValue, const OBSensorType sourceSensorType, const OBSensorType targetSensorType, OBPoint3f *targetPoint3f)
Definition Utils.hpp:110
static void handle(ob_error **error, bool throw_exception=true)
A static function to handle the ob_error and throw an exception if needed.
Definition Error.hpp:38
static bool savePointcloudToPly(const char *fileName, std::shared_ptr< ob::Frame > frame, bool saveBinary, bool useMesh, float meshThreshold)
save point cloud to ply file.
Definition Utils.hpp:182
Definition Context.hpp:19
calibration parameters
Definition ObTypes.h:467
Structure for distortion parameters.
Definition ObTypes.h:425
Structure for camera intrinsic parameters.
Definition ObTypes.h:388
2D point structure in the SDK
Definition ObTypes.h:777
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:117