From fb327a2feceeaeb925e08525bfc5fb682f0af5e3 Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 6 Mar 2024 17:39:31 +0800 Subject: [PATCH] [1.9.x][sample]:update sample code ref v1.9.5 --- .../c/Sample-ColorViewer/color_viewer.cpp | 31 +- .../c/Sample-DepthViewer/depth_viewer.cpp | 25 +- .../Sample-DepthWorkMode/depth_work_mode.cpp | 6 +- .../double_infrared_viewer.cpp | 27 +- .../Sample-InfraredViewer/infrared_viewer.cpp | 196 ++++----- examples/c/Sample-NetDevice/net_device.cpp | 26 +- examples/c/Sample-PointCloud/point_cloud.c | 17 +- .../cpp/Sample-CommonUsages/CommonUsages.cpp | 4 +- .../DepthPrecisionViewer.cpp | 380 ++++++++---------- .../cpp/Sample-DepthViewer/DepthViewer.cpp | 4 +- .../cpp/Sample-MultiStream/MultiStream.cpp | 49 +-- examples/cpp/Sample-PointCloud/PointCloud.cpp | 4 +- examples/cpp/Sample-SaveToDisk/SaveToDisk.cpp | 4 +- .../SyncAlignViewer.cpp | 4 +- .../Sample-Transformation/Transformation.cpp | 16 +- 15 files changed, 369 insertions(+), 424 deletions(-) diff --git a/examples/c/Sample-ColorViewer/color_viewer.cpp b/examples/c/Sample-ColorViewer/color_viewer.cpp index 3fb08675..8689e4da 100644 --- a/examples/c/Sample-ColorViewer/color_viewer.cpp +++ b/examples/c/Sample-ColorViewer/color_viewer.cpp @@ -1,12 +1,8 @@ #include "window.hpp" - -#include #include -#include -#include -#include extern "C" { +#include #include #include #include @@ -21,12 +17,6 @@ extern "C" { * to demonstrate how to open color stream and get frames. */ -// create global variable -Window *win = nullptr; // rendering display window, based on opencv -ob_error *error = NULL; // Used to return SDK interface error information -ob_pipeline *pipe = nullptr; // pipeline, used to open the color stream after connecting the device -ob_device *device = nullptr; // device, obtained through the pipeline, and the corresponding sensor can be obtained through the device - void check_error(ob_error *error) { if(error) { printf("ob_error was raised: \n\tcall: %s(%s)\n", ob_error_function(error), ob_error_args(error)); @@ -38,8 +28,13 @@ void check_error(ob_error *error) { } int main(int argc, char **args) { + Window *win = nullptr; // rendering display window, based on opencv + ob_error *error = NULL; // Used to return SDK interface error information + ob_pipeline *pipeline = nullptr; // pipeline, used to open the color stream after connecting the device + ob_device *device = nullptr; // device, obtained through the pipeline, and the corresponding sensor can be obtained through the device + // Create a pipeline to open the color stream after connecting the device - pipe = ob_create_pipeline(&error); + pipeline = ob_create_pipeline(&error); check_error(error); // Create config to configure the resolution, frame rate, and format of the color stream @@ -48,7 +43,7 @@ int main(int argc, char **args) { // Configure the color stream ob_stream_profile *color_profile = nullptr; - ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_COLOR, &error); + ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_COLOR, &error); if(error) { printf("Current device is not support color sensor!\n"); exit(EXIT_FAILURE); @@ -68,11 +63,11 @@ int main(int argc, char **args) { check_error(error); // Get Device through Pipeline - device = ob_pipeline_get_device(pipe, &error); + device = ob_pipeline_get_device(pipeline, &error); check_error(error); // Start the pipeline with config - ob_pipeline_start_with_config(pipe, config, &error); + ob_pipeline_start_with_config(pipeline, config, &error); check_error(error); // Create a rendering display window @@ -86,7 +81,7 @@ int main(int argc, char **args) { // Wait in a loop, and exit after the window receives the "ESC_KEY" key while(*win) { // Wait for up to 100ms for a frameset in blocking mode. - ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error); + ob_frame *frameset = ob_pipeline_wait_for_frameset(pipeline, 100, &error); check_error(error); if(frameset == nullptr) { @@ -105,7 +100,7 @@ int main(int argc, char **args) { }; // stop the pipeline - ob_pipeline_stop(pipe, &error); + ob_pipeline_stop(pipeline, &error); check_error(error); // destroy window @@ -124,7 +119,7 @@ int main(int argc, char **args) { check_error(error); // destroy the pipeline - ob_delete_pipeline(pipe, &error); + ob_delete_pipeline(pipeline, &error); check_error(error); return 0; diff --git a/examples/c/Sample-DepthViewer/depth_viewer.cpp b/examples/c/Sample-DepthViewer/depth_viewer.cpp index 854975d4..9e613d05 100644 --- a/examples/c/Sample-DepthViewer/depth_viewer.cpp +++ b/examples/c/Sample-DepthViewer/depth_viewer.cpp @@ -1,9 +1,5 @@ #include "window.hpp" - -#include #include -#include -#include extern "C" { #include @@ -19,11 +15,6 @@ extern "C" { *This sample is written in C++ code, based on the C language version API of OrbbecSDK. */ -// Create global variables -Window *win = nullptr; // render window, based on opencv -ob_error *error = NULL; // Used to return SDK interface error information -ob_pipeline *pipe = nullptr; // pipeline, used to open the depth stream after connecting the device - void check_error(ob_error *error) { if(error) { printf("ob_error was raised: \n\tcall: %s(%s)\n", ob_error_function(error), ob_error_args(error)); @@ -35,8 +26,12 @@ void check_error(ob_error *error) { } int main(int argc, char **args) { + Window *win = nullptr; // render window, based on opencv + ob_error *error = NULL; // Used to return SDK interface error information + ob_pipeline *pipeline = nullptr; // pipeline, used to open the depth stream after connecting the device + // Create a pipeline to open the depth stream after connecting the device - pipe = ob_create_pipeline(&error); + pipeline = ob_create_pipeline(&error); check_error(error); // Create config to configure the resolution, frame rate, and format of the depth stream @@ -45,7 +40,7 @@ int main(int argc, char **args) { // Configure the depth stream ob_stream_profile *depth_profile = NULL; - ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_DEPTH, &error); + ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_DEPTH, &error); check_error(error); // Find the corresponding profile according to the specified format, first look for the y16 format @@ -62,7 +57,7 @@ int main(int argc, char **args) { check_error(error); // Start the pipeline with config - ob_pipeline_start_with_config(pipe, config, &error); + ob_pipeline_start_with_config(pipeline, config, &error); check_error(error); // Create a window for rendering, and set the resolution of the window @@ -76,7 +71,7 @@ int main(int argc, char **args) { // Wait in a loop, exit after the window receives the "esc" key while(*win) { // Wait for up to 100ms for a frameset in blocking mode. - ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error); + ob_frame *frameset = ob_pipeline_wait_for_frameset(pipeline, 100, &error); check_error(error); if(frameset == nullptr) { @@ -117,7 +112,7 @@ int main(int argc, char **args) { }; // stop the pipeline - ob_pipeline_stop(pipe, &error); + ob_pipeline_stop(pipeline, &error); check_error(error); // destroy the window @@ -132,7 +127,7 @@ int main(int argc, char **args) { check_error(error); // destroy the pipeline - ob_delete_pipeline(pipe, &error); + ob_delete_pipeline(pipeline, &error); check_error(error); return 0; diff --git a/examples/c/Sample-DepthWorkMode/depth_work_mode.cpp b/examples/c/Sample-DepthWorkMode/depth_work_mode.cpp index ae7800ad..c5932ad1 100644 --- a/examples/c/Sample-DepthWorkMode/depth_work_mode.cpp +++ b/examples/c/Sample-DepthWorkMode/depth_work_mode.cpp @@ -42,11 +42,11 @@ int main(int argc, char **argv) { ob_error *error = NULL; // Create a pipeline to open the depth stream after connecting the device - ob_pipeline *pipe = ob_create_pipeline(&error); + ob_pipeline *pipeline = ob_create_pipeline(&error); check_error(error); // Get the device through the pipeline - ob_device *dev = ob_pipeline_get_device(pipe, &error); + ob_device *dev = ob_pipeline_get_device(pipeline, &error); check_error(error); // Check whether the camera depth working mode is supported, currently (December 5, 2022) only the Gemini2 binocular camera supports the depth working mode @@ -132,7 +132,7 @@ int main(int argc, char **argv) { check_error(error); // destroy the pipeline - ob_delete_pipeline(pipe, &error); + ob_delete_pipeline(pipeline, &error); check_error(error); return 0; diff --git a/examples/c/Sample-DoubleInfraredViewer/double_infrared_viewer.cpp b/examples/c/Sample-DoubleInfraredViewer/double_infrared_viewer.cpp index 36790466..0b7f0199 100644 --- a/examples/c/Sample-DoubleInfraredViewer/double_infrared_viewer.cpp +++ b/examples/c/Sample-DoubleInfraredViewer/double_infrared_viewer.cpp @@ -1,9 +1,5 @@ #include "window.hpp" - -#include #include -#include -#include extern "C" { #include @@ -19,11 +15,6 @@ extern "C" { *This sample is written in C++ code, based on the C language version API of OrbbecSDK. */ -// Create global variables -Window *win = nullptr; // render window, based on opencv -ob_error *error = NULL; // Used to return SDK interface error information -ob_pipeline *pipe = nullptr; // pipeline, used to open the Infrared stream after connecting the device - void check_error(ob_error *error) { if(error) { printf("ob_error was raised: \n\tcall: %s(%s)\n", ob_error_function(error), ob_error_args(error)); @@ -35,8 +26,12 @@ void check_error(ob_error *error) { } int main(int argc, char **args) { + Window *win = nullptr; // render window, based on opencv + ob_error *error = NULL; // Used to return SDK interface error information + ob_pipeline *pipeline = nullptr; // pipeline, used to open the Infrared stream after connecting the device + // Create a pipeline to open the Infrared stream after connecting the device - pipe = ob_create_pipeline(&error); + pipeline = ob_create_pipeline(&error); check_error(error); // Create config to configure the resolution, frame rate, and format of the Infrared stream @@ -45,7 +40,7 @@ int main(int argc, char **args) { // Configure the infrared stream(IR_LEFT) ob_stream_profile *ir_left_profile = NULL; - ob_stream_profile_list *ir_left_profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_IR_LEFT, &error); + ob_stream_profile_list *ir_left_profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_IR_LEFT, &error); check_error(error); if(ir_left_profiles == nullptr) { @@ -63,7 +58,7 @@ int main(int argc, char **args) { // Configure the infrared stream(IR_RIGHT) ob_stream_profile *ir_right_profile = NULL; - ob_stream_profile_list *ir_right_profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_IR_RIGHT, &error); + ob_stream_profile_list *ir_right_profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_IR_RIGHT, &error); check_error(error); // Find the corresponding profile according to the specified format, first look for the y16 format @@ -75,7 +70,7 @@ int main(int argc, char **args) { check_error(error); // Start the pipeline with config - ob_pipeline_start_with_config(pipe, config, &error); + ob_pipeline_start_with_config(pipeline, config, &error); check_error(error); // Create a rendering display window @@ -85,7 +80,7 @@ int main(int argc, char **args) { // Wait in a loop, exit after the window receives the "esc" key while(*win) { // Wait for up to 100ms for a frameset in blocking mode. - ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error); + ob_frame *frameset = ob_pipeline_wait_for_frameset(pipeline, 100, &error); check_error(error); if(frameset == nullptr) { @@ -111,7 +106,7 @@ int main(int argc, char **args) { }; // stop the pipeline - ob_pipeline_stop(pipe, &error); + ob_pipeline_stop(pipeline, &error); check_error(error); // destroy the window @@ -134,7 +129,7 @@ int main(int argc, char **args) { check_error(error); // destroy the pipeline - ob_delete_pipeline(pipe, &error); + ob_delete_pipeline(pipeline, &error); check_error(error); return 0; diff --git a/examples/c/Sample-InfraredViewer/infrared_viewer.cpp b/examples/c/Sample-InfraredViewer/infrared_viewer.cpp index 6b0c6568..e5079589 100644 --- a/examples/c/Sample-InfraredViewer/infrared_viewer.cpp +++ b/examples/c/Sample-InfraredViewer/infrared_viewer.cpp @@ -1,137 +1,119 @@ -#include -#include -#include -#include - #include "window.hpp" +#include extern "C" { -#include +#include #include #include #include #include #include -#include +#include } /* - *This sample is written in C++ code, based on the C language version API of - *OrbbecSDK. + *This sample is written in C++ code, based on the C language version API of OrbbecSDK. */ -// Create global variables -Window *win = nullptr; // render window, based on opencv -ob_error *error = NULL; // Used to return SDK interface error information -ob_pipeline *pipe = nullptr; // pipeline, used to open the Infrared stream - // after connecting the device - void check_error(ob_error *error) { - if (error) { - printf("ob_error was raised: \n\tcall: %s(%s)\n", ob_error_function(error), - ob_error_args(error)); - printf("\tmessage: %s\n", ob_error_message(error)); - printf("\terror type: %d\n", ob_error_exception_type(error)); - ob_delete_error(error); - exit(EXIT_FAILURE); - } + if(error) { + printf("ob_error was raised: \n\tcall: %s(%s)\n", ob_error_function(error), ob_error_args(error)); + printf("\tmessage: %s\n", ob_error_message(error)); + printf("\terror type: %d\n", ob_error_exception_type(error)); + ob_delete_error(error); + exit(EXIT_FAILURE); + } } int main(int argc, char **args) { - // Create a pipeline to open the Infrared stream after connecting the device - pipe = ob_create_pipeline(&error); - check_error(error); - - // Create config to configure the resolution, frame rate, and format of the - // Infrared stream - ob_config *config = ob_create_config(&error); - check_error(error); - - // Configure the infrared stream - // Please adjust the sensor according to the actual product, some device types - // only have OB_SENSOR_IR_LEFT and OB_SENSOR_IR_RIGHT. - ob_stream_profile *ir_profile = NULL; - ob_stream_profile_list *profiles = - ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_IR, &error); - check_error(error); - - if (profiles == nullptr) { - printf( - "The obtained IR resolution list is NULL. For binocular structured " - "light devices, try using the doubleIr example to turn on the ir data " - "stream. "); - return 0; - } - - // Find the corresponding profile according to the specified format, first - // look for the y16 format - ir_profile = ob_stream_profile_list_get_video_stream_profile( - profiles, 640, OB_HEIGHT_ANY, OB_FORMAT_Y16, 30, &error); - // If the specified format is not found, search for the default profile to - // open the stream - if (error) { - ir_profile = ob_stream_profile_list_get_profile(profiles, - OB_PROFILE_DEFAULT, &error); - ob_delete_error(error); - error = nullptr; - } - - // enable stream - ob_config_enable_stream(config, ir_profile, &error); - check_error(error); - - // Start the pipeline with config - ob_pipeline_start_with_config(pipe, config, &error); - check_error(error); - - // Create a rendering display window - uint32_t width = ob_video_stream_profile_width(ir_profile, &error); - check_error(error); - uint32_t height = ob_video_stream_profile_height(ir_profile, &error); - check_error(error); - win = new Window("InfraredViewer", width, height); - check_error(error); - - // Wait in a loop, exit after the window receives the "esc" key - while (*win) { - // Wait for up to 100ms for a frameset in blocking mode. - ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error); + Window *win = nullptr; // render window, based on opencv + ob_error *error = NULL; // Used to return SDK interface error information + ob_pipeline *pipeline = nullptr; // pipeline, used to open the Infrared stream after connecting the device + + // Create a pipeline to open the Infrared stream after connecting the device + pipeline = ob_create_pipeline(&error); check_error(error); - if (frameset == nullptr) { - continue; - } - // If the open stream type is not OB_SENSOR_IR, use the - // ob_frameset_get_frame interface to get the frame. - ob_frame *ir_frame = ob_frameset_ir_frame(frameset, &error); + // Create config to configure the resolution, frame rate, and format of the Infrared stream + ob_config *config = ob_create_config(&error); + check_error(error); + + // Configure the infrared stream + // Please adjust the sensor according to the actual product, some device types only have OB_SENSOR_IR_LEFT and OB_SENSOR_IR_RIGHT. + ob_stream_profile *ir_profile = NULL; + ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_IR, &error); check_error(error); - if (ir_frame != nullptr) { - // add frame to render, will auto delete frame when render finished - win->addToRender(ir_frame); + + if(profiles == nullptr) { + printf( + "The obtained IR resolution list is NULL. For binocular structured light devices, try using the doubleIr example to turn on the ir data stream. "); + return 0; + } + + // Find the corresponding profile according to the specified format, first look for the y16 format + ir_profile = ob_stream_profile_list_get_video_stream_profile(profiles, 640, OB_HEIGHT_ANY, OB_FORMAT_Y16, 30, &error); + // If the specified format is not found, search for the default profile to open the stream + if(error) { + ir_profile = ob_stream_profile_list_get_profile(profiles, OB_PROFILE_DEFAULT, &error); + ob_delete_error(error); + error = nullptr; } - ob_delete_frame(frameset, &error); + // enable stream + ob_config_enable_stream(config, ir_profile, &error); + check_error(error); + + // Start the pipeline with config + ob_pipeline_start_with_config(pipeline, config, &error); + check_error(error); + + // Create a rendering display window + uint32_t width = ob_video_stream_profile_width(ir_profile, &error); + check_error(error); + uint32_t height = ob_video_stream_profile_height(ir_profile, &error); + check_error(error); + win = new Window("InfraredViewer", width, height); check_error(error); - }; - // stop the pipeline - ob_pipeline_stop(pipe, &error); - check_error(error); + // Wait in a loop, exit after the window receives the "esc" key + while(*win) { + // Wait for up to 100ms for a frameset in blocking mode. + ob_frame *frameset = ob_pipeline_wait_for_frameset(pipeline, 100, &error); + check_error(error); + + if(frameset == nullptr) { + continue; + } + // If the open stream type is not OB_SENSOR_IR, use the ob_frameset_get_frame interface to get the frame. + ob_frame *ir_frame = ob_frameset_ir_frame(frameset, &error); + check_error(error); + if(ir_frame != nullptr) { + // add frame to render, will auto delete frame when render finished + win->addToRender(ir_frame); + } + + ob_delete_frame(frameset, &error); + check_error(error); + }; + + // stop the pipeline + ob_pipeline_stop(pipeline, &error); + check_error(error); - // destroy the window - delete win; + // destroy the window + delete win; - // destroy profile - ob_delete_stream_profile(ir_profile, &error); - check_error(error); + // destroy profile + ob_delete_stream_profile(ir_profile, &error); + check_error(error); - // destroy profile list - ob_delete_stream_profile_list(profiles, &error); - check_error(error); + // destroy profile list + ob_delete_stream_profile_list(profiles, &error); + check_error(error); - // destroy the pipeline - ob_delete_pipeline(pipe, &error); - check_error(error); + // destroy the pipeline + ob_delete_pipeline(pipeline, &error); + check_error(error); - return 0; + return 0; } diff --git a/examples/c/Sample-NetDevice/net_device.cpp b/examples/c/Sample-NetDevice/net_device.cpp index 4497c636..4eac550b 100644 --- a/examples/c/Sample-NetDevice/net_device.cpp +++ b/examples/c/Sample-NetDevice/net_device.cpp @@ -19,15 +19,10 @@ extern "C" { #include } -// Create global variables -Window *win = nullptr; // render window, based on opencv -ob_error *error = NULL; // Used to return SDK interface error information -ob_context *ctx = nullptr; // context, used to create device -ob_device *device = nullptr; // device, used to create pipeline -ob_pipeline *pipe = nullptr; // pipeline, used to open the data stream after connecting the device - ob_frame *current_frameset = nullptr; // The frame used to render std::mutex frameset_mutex; // frameSet mutex +ob_error *error = NULL; // Used to return SDK interface error information + // exception handler void check_error(ob_error *error) { if(error) { @@ -51,6 +46,11 @@ void frameset_callback(ob_frame *frameset, void *user_data) { } int main(int argc, char **args) { + Window *win = nullptr; // render window, based on opencv + ob_context *ctx = nullptr; // context, used to create device + ob_device *device = nullptr; // device, used to create pipeline + ob_pipeline *pipeline = nullptr; // pipeline, used to open the data stream after connecting the device + // create context ctx = ob_create_context(&error); check_error(error); @@ -72,7 +72,7 @@ int main(int argc, char **args) { check_error(error); // Create a pipeline to open the color stream after connecting the device - pipe = ob_create_pipeline_with_device(device, &error); + pipeline = ob_create_pipeline_with_device(device, &error); check_error(error); // Create config to configure the resolution, frame rate, and format of the color stream @@ -81,7 +81,7 @@ int main(int argc, char **args) { ob_stream_profile *color_profile = nullptr; // Get the list of Color stream profiles - ob_stream_profile_list *color_profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_COLOR, &error); + ob_stream_profile_list *color_profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_COLOR, &error); check_error(error); // Select the default stream configuration color_profile = ob_stream_profile_list_get_profile(color_profiles, OB_PROFILE_DEFAULT, &error); @@ -92,7 +92,7 @@ int main(int argc, char **args) { ob_stream_profile *depth_profile = nullptr; // Get the depth stream profile list - ob_stream_profile_list *depth_profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_DEPTH, &error); + ob_stream_profile_list *depth_profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_DEPTH, &error); check_error(error); // Select the default stream configuration depth_profile = ob_stream_profile_list_get_profile(depth_profiles, OB_PROFILE_DEFAULT, &error); @@ -102,7 +102,7 @@ int main(int argc, char **args) { check_error(error); // Start the pipeline with config - ob_pipeline_start_with_callback(pipe, config, frameset_callback, nullptr, &error); + ob_pipeline_start_with_callback(pipeline, config, frameset_callback, nullptr, &error); check_error(error); // Create a rendering display window @@ -178,7 +178,7 @@ int main(int argc, char **args) { }; // stop the pipeline - ob_pipeline_stop(pipe, &error); + ob_pipeline_stop(pipeline, &error); check_error(error); // destroy window @@ -212,7 +212,7 @@ int main(int argc, char **args) { check_error(error); // destroy the pipeline - ob_delete_pipeline(pipe, &error); + ob_delete_pipeline(pipeline, &error); check_error(error); // destroy context diff --git a/examples/c/Sample-PointCloud/point_cloud.c b/examples/c/Sample-PointCloud/point_cloud.c index 5185de1d..a813b7bf 100644 --- a/examples/c/Sample-PointCloud/point_cloud.c +++ b/examples/c/Sample-PointCloud/point_cloud.c @@ -16,8 +16,7 @@ #define KEY_R 82 #define KEY_r 114 -ob_error *error = NULL; // Used to return SDK interface error information -ob_pipeline *pipeline = NULL; // pipeline, used to open the Color and Depth streams after connecting the device +ob_error *error = NULL; // Used to return SDK interface error information void check_error(ob_error *error) { if(error) { @@ -84,6 +83,8 @@ void save_rgb_points_to_ply(ob_frame *frame, const char *fileName) { } int main(int argc, char **argv) { + ob_pipeline *pipeline = NULL; // pipeline, used to open the Color and Depth streams after connecting the device + ob_set_logger_severity(OB_LOG_SEVERITY_ERROR, &error); check_error(error); @@ -150,11 +151,13 @@ int main(int argc, char **argv) { int listCount = ob_stream_profile_list_count(depthProfiles, &error); check_error(error); if(listCount > 0) { - // Select the profile with the same frame rate as color. - int color_fps = ob_video_stream_profile_fps(color_profile, &error); - check_error(error); - depth_profile = ob_stream_profile_list_get_video_stream_profile(depthProfiles, OB_WIDTH_ANY, OB_HEIGHT_ANY, OB_FORMAT_ANY, color_fps, &error); - check_error(error); + if(color_profile) { + // Select the profile with the same frame rate as color. + int color_fps = ob_video_stream_profile_fps(color_profile, &error); + check_error(error); + depth_profile = ob_stream_profile_list_get_video_stream_profile(depthProfiles, OB_WIDTH_ANY, OB_HEIGHT_ANY, OB_FORMAT_ANY, color_fps, &error); + check_error(error); + } if(depth_profile == NULL) { // If no matching profile is found, select the default profile. diff --git a/examples/cpp/Sample-CommonUsages/CommonUsages.cpp b/examples/cpp/Sample-CommonUsages/CommonUsages.cpp index b6dd82f0..204e084d 100644 --- a/examples/cpp/Sample-CommonUsages/CommonUsages.cpp +++ b/examples/cpp/Sample-CommonUsages/CommonUsages.cpp @@ -306,7 +306,9 @@ void startStream() { try { // Select the profile with the same frame rate as color. - profile = depthProfileList->getVideoStreamProfile(OB_WIDTH_ANY, OB_HEIGHT_ANY, OB_FORMAT_ANY, colorProfile->fps()); + if(colorProfile) { + profile = depthProfileList->getVideoStreamProfile(OB_WIDTH_ANY, OB_HEIGHT_ANY, OB_FORMAT_ANY, colorProfile->fps()); + } } catch(...) { profile = nullptr; diff --git a/examples/cpp/Sample-DepthPrecisionViewer/DepthPrecisionViewer.cpp b/examples/cpp/Sample-DepthPrecisionViewer/DepthPrecisionViewer.cpp index 92118a2e..03598740 100644 --- a/examples/cpp/Sample-DepthPrecisionViewer/DepthPrecisionViewer.cpp +++ b/examples/cpp/Sample-DepthPrecisionViewer/DepthPrecisionViewer.cpp @@ -1,235 +1,205 @@ -#include -#include -#include -#include -#include +#include "window.hpp" -#include "libobsensor/hpp/Error.hpp" #include "libobsensor/hpp/Pipeline.hpp" +#include "libobsensor/hpp/Error.hpp" + +#include +#include +#include +#include +#include #include "utils.hpp" -#include "window.hpp" #define ESC 27 const std::map depthUnitMap = { - {OB_PRECISION_1MM, "1.0mm"}, {OB_PRECISION_0MM8, "0.8mm"}, - {OB_PRECISION_0MM4, "0.4mm"}, {OB_PRECISION_0MM1, "0.1mm"}, - {OB_PRECISION_0MM2, "0.2mm"}, {OB_PRECISION_0MM5, "0.5mm"}, - {OB_PRECISION_0MM05, "0.05mm"}, + { OB_PRECISION_1MM, "1.0mm" }, { OB_PRECISION_0MM8, "0.8mm" }, { OB_PRECISION_0MM4, "0.4mm" }, { OB_PRECISION_0MM1, "0.1mm" }, + { OB_PRECISION_0MM2, "0.2mm" }, { OB_PRECISION_0MM5, "0.5mm" }, { OB_PRECISION_0MM05, "0.05mm" }, }; std::vector precisionList; -OBDepthPrecisionLevel curDepthPrecisionLevel = OB_PRECISION_UNKNOWN; -float unit = -1; +OBDepthPrecisionLevel curDepthPrecisionlevel = OB_PRECISION_UNKNOWN; +float unit = -1; static void pressKeyExit(std::string msg) { - if (msg.size() > 0) { - std::cout << msg << std::endl; - } - - while (true) { - // Get the value of the pressed key, if it is the esc key, exit the program - int key = getch(); - if (key == ESC) break; - } + if(msg.size() > 0) { + std::cout << msg << std::endl; + } + + while(true) { + // Get the value of the pressed key, if it is the esc key, exit the program + int key = getch(); + if(key == ESC) + break; + } } // Convert depth precision unit to 1mm void depthPrecisionConversion(std::shared_ptr depthFrame) { - auto size = depthFrame->dataSize(); - auto pixel = static_cast(depthFrame->data()); + auto size = depthFrame->dataSize(); + auto pixel = static_cast(depthFrame->data()); - for (int i = 0; i < size / sizeof(uint16_t); i++) { - pixel[i] = static_cast(pixel[i] * unit); - } + for(int i = 0; i < size / sizeof(uint16_t); i++) { + pixel[i] = static_cast(pixel[i] * unit); + } } int main(int argc, char **argv) try { - // Create a pipeline with default device - ob::Pipeline pipe; - - // Get the device inside the pipeline - auto device = pipe.getDevice(); - - // Get the current D2D mode - if (!device->isPropertySupported(OB_PROP_DISPARITY_TO_DEPTH_BOOL, - OB_PERMISSION_READ_WRITE)) { - pressKeyExit("Current device not support disparity to depth !"); - return -1; - } - // Get the current D2D mode - auto curD2dMode = device->getBoolProperty(OB_PROP_DISPARITY_TO_DEPTH_BOOL); - if (!curD2dMode) { - std::cout << "Current Disparity to depth is software-D2d" << std::endl; - } else { - std::cout << "Current Disparity to depth is hardware-D2d" << std::endl; - } - - // Get the current depthPrecisionLevel - if (!device->isPropertySupported(OB_PROP_DEPTH_PRECISION_LEVEL_INT, - OB_PERMISSION_READ_WRITE)) { - pressKeyExit("Current device not support depthPrecision !"); - return -1; - } - curDepthPrecisionLevel = (OBDepthPrecisionLevel)device->getIntProperty( - OB_PROP_DEPTH_PRECISION_LEVEL_INT); - std::cout << "Current depthPrecision is " - << depthUnitMap.find(curDepthPrecisionLevel)->second << std::endl; - - // Get the depthPrecisionList - if (!device->isPropertySupported(OB_STRUCT_DEPTH_PRECISION_SUPPORT_LIST, - OB_PERMISSION_READ) && - curD2dMode) { - pressKeyExit("Current device not support depthPrecisionList !"); - return -1; - } - auto depthPrecision = - device->getStructuredDataExt(OB_STRUCT_DEPTH_PRECISION_SUPPORT_LIST); - precisionList.clear(); - // Some of the products do not have the same precision list for hardware and - // software - if (curD2dMode) { - int count = 0; - for (int i = 0; i < depthPrecision->dataSize; i += 2) { - auto precision = *((uint16_t *)((uint8_t *)depthPrecision->data + i)); - precisionList.push_back(precision); - std::cout << "precisionList[" << count << "]: " - << depthUnitMap - .find((OBDepthPrecisionLevel)precisionList[count]) - ->second - << std::endl; - count++; + // Create a pipeline with default device + ob::Pipeline pipe; + + // Get the device inside the pipeline + auto device = pipe.getDevice(); + + // Get the current D2D mode + if(!device->isPropertySupported(OB_PROP_DISPARITY_TO_DEPTH_BOOL, OB_PERMISSION_READ_WRITE)) { + pressKeyExit("Current device not support disparity to depth !"); + return -1; + } + // Get the current D2D mode + auto curD2dMode = device->getBoolProperty(OB_PROP_DISPARITY_TO_DEPTH_BOOL); + if(!curD2dMode) { + std::cout << "Current Disparity to depth is software-D2d" << std::endl; + } + else { + std::cout << "Current Disparity to depth is hardware-D2d" << std::endl; + } + + // Get the current depthPrecisionLevel + if(!device->isPropertySupported(OB_PROP_DEPTH_PRECISION_LEVEL_INT, OB_PERMISSION_READ_WRITE)) { + pressKeyExit("Current device not support depthPrecision !"); + return -1; } - } else { - for (int i = 0; i < 6; i++) { - precisionList.push_back(i); - std::cout - << "precisionList[" << i << "]: " - << depthUnitMap.find((OBDepthPrecisionLevel)precisionList[i])->second - << std::endl; + curDepthPrecisionlevel = (OBDepthPrecisionLevel)device->getIntProperty(OB_PROP_DEPTH_PRECISION_LEVEL_INT); + std::cout << "Current depthPrecision is " << depthUnitMap.find(curDepthPrecisionlevel)->second << std::endl; + + // Get the depthPrecisionList + if(!device->isPropertySupported(OB_STRUCT_DEPTH_PRECISION_SUPPORT_LIST, OB_PERMISSION_READ) && curD2dMode) { + pressKeyExit("Current device not support depthPrecisionList !"); + return -1; + } + auto depthPrecision = device->getStructuredDataExt(OB_STRUCT_DEPTH_PRECISION_SUPPORT_LIST); + precisionList.clear(); + // Some of the products do not have the same precision list for hardware and software + if(curD2dMode) { + int count = 0; + for(int i = 0; i < depthPrecision->dataSize; i += 2) { + auto precision = *((uint16_t *)((uint8_t *)depthPrecision->data + i)); + precisionList.push_back(precision); + std::cout << "precisionList[" << count << "]: " << depthUnitMap.find((OBDepthPrecisionLevel)precisionList[count])->second << std::endl; + count++; + } + } + else { + for(int i = 0; i < 6; i++) { + precisionList.push_back(i); + std::cout << "precisionList[" << i << "]: " << depthUnitMap.find((OBDepthPrecisionLevel)precisionList[i])->second << std::endl; + } + } + + // Let the user choose a depthPrecision, then switch + if(precisionList.size() > 0) { + uint32_t index = 0; + std::cout << "Please input the index from above depthPrecisionList, newIndex = "; + std::cin >> index; + if(index >= 0 && index < precisionList.size()) { // legitimacy check + device->setIntProperty(OB_PROP_DEPTH_PRECISION_LEVEL_INT, index); + + // Checking depth accuracy after switching + curDepthPrecisionlevel = (OBDepthPrecisionLevel)device->getIntProperty(OB_PROP_DEPTH_PRECISION_LEVEL_INT); + std::cout << "Current depthPrecision is " << depthUnitMap.find(curDepthPrecisionlevel)->second << std::endl; + } + else { + std::cout << "switchDepthPrecision faild. invalid index: " << index << std::endl; + } } - } - - // Let the user choose a depthPrecision, then switch - if (precisionList.size() > 0) { - uint32_t index = 0; - std::cout - << "Please input the index from above depthPrecisionList, newIndex = "; - std::cin >> index; - if (index >= 0 && index < precisionList.size()) { // legitimacy check - device->setIntProperty(OB_PROP_DEPTH_PRECISION_LEVEL_INT, index); - - // Checking depth accuracy after switching - curDepthPrecisionLevel = (OBDepthPrecisionLevel)device->getIntProperty( - OB_PROP_DEPTH_PRECISION_LEVEL_INT); - std::cout << "Current depthPrecision is " - << depthUnitMap.find(curDepthPrecisionLevel)->second - << std::endl; - } else { - std::cout << "switchDepthPrecision faild. invalid index: " << index - << std::endl; + if(curDepthPrecisionlevel != OB_PRECISION_UNKNOWN) { + switch(curDepthPrecisionlevel) { + case OB_PRECISION_1MM: + unit = 1; + break; + case OB_PRECISION_0MM8: + unit = 0.8; + break; + case OB_PRECISION_0MM4: + unit = 0.4; + break; + case OB_PRECISION_0MM1: + unit = 0.1; + break; + case OB_PRECISION_0MM2: + unit = 0.2; + break; + case OB_PRECISION_0MM5: + unit = 0.5; + break; + case OB_PRECISION_0MM05: + unit = 0.05; + break; + default: + unit = -1; + break; + } } - } - if (curDepthPrecisionLevel != OB_PRECISION_UNKNOWN) { - switch (curDepthPrecisionLevel) { - case OB_PRECISION_1MM: - unit = 1; - break; - case OB_PRECISION_0MM8: - unit = 0.8f; - break; - case OB_PRECISION_0MM4: - unit = 0.4f; - break; - case OB_PRECISION_0MM1: - unit = 0.1f; - break; - case OB_PRECISION_0MM2: - unit = 0.2f; - break; - case OB_PRECISION_0MM5: - unit = 0.5f; - break; - case OB_PRECISION_0MM05: - unit = 0.05f; - break; - default: - unit = -1; - break; + + // Get all stream profiles of the depth camera, including stream resolution, frame rate, and frame format + auto profiles = pipe.getStreamProfileList(OB_SENSOR_DEPTH); + + std::shared_ptr depthProfile = nullptr; + try { + // Find the corresponding profile according to the specified format, first look for the y16 format + depthProfile = profiles->getVideoStreamProfile(640, OB_HEIGHT_ANY, OB_FORMAT_Y16, 30); } - } - - // Get all stream profiles of the depth camera, including stream resolution, - // frame rate, and frame format - auto profiles = pipe.getStreamProfileList(OB_SENSOR_DEPTH); - - std::shared_ptr depthProfile = nullptr; - try { - // Find the corresponding profile according to the specified format, first - // look for the y16 format - depthProfile = - profiles->getVideoStreamProfile(640, OB_HEIGHT_ANY, OB_FORMAT_Y16, 30); - } catch (ob::Error &e) { - // If the specified format is not found, search for the default profile to - // open the stream - depthProfile = std::const_pointer_cast( - profiles->getProfile(OB_PROFILE_DEFAULT)) - ->as(); - } - - // By creating config to configure which streams to enable or disable for the - // pipeline, here the depth stream will be enabled - std::shared_ptr config = std::make_shared(); - config->enableStream(depthProfile); - - // Start the pipeline with config - pipe.start(config); - - device->setBoolProperty(OB_PROP_LDP_BOOL, false); - device->setBoolProperty(OB_PROP_LASER_BOOL, true); - - // Create a window for rendering, and set the resolution of the window - Window app("DepthPrecisionViewer", depthProfile->width(), - depthProfile->height()); - - while (app) { - // Wait for up to 100ms for a frameset in blocking mode. - auto frameSet = pipe.waitForFrames(100); - if (frameSet == nullptr) { - continue; + catch(ob::Error &e) { + // If the specified format is not found, search for the default profile to open the stream + depthProfile = std::const_pointer_cast(profiles->getProfile(OB_PROFILE_DEFAULT))->as(); } - auto depthFrame = frameSet->depthFrame(); + // By creating config to configure which streams to enable or disable for the pipeline, here the depth stream will be enabled + std::shared_ptr config = std::make_shared(); + config->enableStream(depthProfile); + + // Start the pipeline with config + pipe.start(config); + + device->setBoolProperty(OB_PROP_LDP_BOOL, false); + device->setBoolProperty(OB_PROP_LASER_BOOL, true); + + // Create a window for rendering, and set the resolution of the window + Window app("DepthPrecisionViewer", depthProfile->width(), depthProfile->height()); - // Convert depth values to 1mm precision - depthPrecisionConversion(depthFrame); + while(app) { + // Wait for up to 100ms for a frameset in blocking mode. + auto frameSet = pipe.waitForFrames(100); + if(frameSet == nullptr) { + continue; + } - // For Y16 format depth frame, print the distance of the center pixel every - // 30 frames - if (depthFrame->index() % 30 == 0 && - depthFrame->format() == OB_FORMAT_Y16) { - uint32_t width = depthFrame->width(); - uint32_t height = depthFrame->height(); - uint16_t *data = (uint16_t *)depthFrame->data(); + auto depthFrame = frameSet->depthFrame(); - // Pixel value multiplied by scale is the actual distance value in - // millimeters - uint16_t centerDistance = data[width * height / 2 + width / 2]; + // Convert depth values to 1mm precision + depthPrecisionConversion(depthFrame); - // Attention: if the distance is 0, it means that the depth camera cannot - // detect the object(may be out of detection range) - std::cout << "The image center depth value is " << centerDistance - << " mm. " << std::endl; + // For Y16 format depth frame, print the distance of the center pixel every 30 frames + if(depthFrame->index() % 30 == 0 && depthFrame->format() == OB_FORMAT_Y16) { + uint32_t width = depthFrame->width(); + uint32_t height = depthFrame->height(); + uint16_t *data = (uint16_t *)depthFrame->data(); + + // Pixel value multiplied by scale is the actual distance value in millimeters + uint16_t centerDistance = data[width * height / 2 + width / 2]; + + // Attention: if the distance is 0, it means that the depth camera cannot detect the object(may be out of detection range) + std::cout << "The image center depth value is " << centerDistance << " mm. " << std::endl; + } + // Render frame in the window + app.addToRender(depthFrame); } - // Render frame in the window - app.addToRender(depthFrame); - } - - // Stop the pipeline - pipe.stop(); - - return 0; -} catch (ob::Error &e) { - std::cerr << "function:" << e.getName() << "\nargs:" << e.getArgs() - << "\nmessage:" << e.getMessage() - << "\ntype:" << e.getExceptionType() << std::endl; - exit(EXIT_FAILURE); + + // Stop the pipeline + pipe.stop(); + + return 0; +} +catch(ob::Error &e) { + std::cerr << "function:" << e.getName() << "\nargs:" << e.getArgs() << "\nmessage:" << e.getMessage() << "\ntype:" << e.getExceptionType() << std::endl; + exit(EXIT_FAILURE); } diff --git a/examples/cpp/Sample-DepthViewer/DepthViewer.cpp b/examples/cpp/Sample-DepthViewer/DepthViewer.cpp index a1bf7e76..c7ff48fc 100644 --- a/examples/cpp/Sample-DepthViewer/DepthViewer.cpp +++ b/examples/cpp/Sample-DepthViewer/DepthViewer.cpp @@ -28,7 +28,7 @@ int main(int argc, char **argv) try { pipe.start(config); // Create a window for rendering, and set the resolution of the window - Window app("DepthViewer", depthProfile->width(), depthProfile->height()); + Window app("DepthViewer", depthProfile->width(), depthProfile->height()); while(app) { // Wait for up to 100ms for a frameset in blocking mode. @@ -54,7 +54,7 @@ int main(int argc, char **argv) try { } // Render frame in the window - app.addToRender(depthFrame); + app.addToRender(depthFrame); } // Stop the pipeline diff --git a/examples/cpp/Sample-MultiStream/MultiStream.cpp b/examples/cpp/Sample-MultiStream/MultiStream.cpp index 8d967a38..7f533ba9 100644 --- a/examples/cpp/Sample-MultiStream/MultiStream.cpp +++ b/examples/cpp/Sample-MultiStream/MultiStream.cpp @@ -70,31 +70,35 @@ int main(int argc, char **argv) try { irFrame = frameset->irFrame(); }); - auto dev = pipe.getDevice(); - std::shared_ptr accelSensor; - std::shared_ptr gyroSensor; + auto dev = pipe.getDevice(); + auto imuPipeline = std::make_shared(dev); try { - accelSensor = dev->getSensor(OB_SENSOR_ACCEL); - gyroSensor = dev->getSensor(OB_SENSOR_GYRO); + auto accelProfiles = imuPipeline->getStreamProfileList(OB_SENSOR_ACCEL); + auto gyroProfiles = imuPipeline->getStreamProfileList(OB_SENSOR_GYRO); + auto accelProfile = accelProfiles->getProfile(OB_PROFILE_DEFAULT); + auto gyroProfile = gyroProfiles->getProfile(OB_PROFILE_DEFAULT); + std::shared_ptr imuConfig = std::make_shared(); + imuConfig->enableStream(accelProfile); + imuConfig->enableStream(gyroProfile); + imuPipeline->start(imuConfig, [&](std::shared_ptr frame) { + auto frameSet = frame->as(); + auto aFrame = frameSet->getFrame(OB_FRAME_ACCEL); + auto gFrame = frameSet->getFrame(OB_FRAME_GYRO); + + { + std::unique_lock lk(accelFrameMutex); + accelFrame = aFrame; + } + + { + std::unique_lock lk(gyroFrameMutex); + gyroFrame = gFrame; + } + }); } catch(...) { std::cout << "IMU sensor not found!" << std::endl; } - if(accelSensor && gyroSensor) { - auto accelProfiles = accelSensor->getStreamProfileList(); - auto accelProfile = accelProfiles->getProfile(OB_PROFILE_DEFAULT); - accelSensor->start(accelProfile, [&](std::shared_ptr frame) { - std::unique_lock lk(accelFrameMutex); - accelFrame = frame; - }); - - auto gyroProfiles = gyroSensor->getStreamProfileList(); - auto gyroProfile = gyroProfiles->getProfile(OB_PROFILE_DEFAULT); - gyroSensor->start(gyroProfile, [&](std::shared_ptr frame) { - std::unique_lock lk(gyroFrameMutex); - gyroFrame = frame; - }); - } // Create a window for rendering and set the resolution of the window Window app("MultiStream", 1280, 720, RENDER_GRID); @@ -135,9 +139,8 @@ int main(int argc, char **argv) try { // Stop the Pipeline, no frame data will be generated pipe.stop(); - if(accelSensor && gyroSensor) { - accelSensor->stop(); - gyroSensor->stop(); + if(imuPipeline) { + imuPipeline->stop(); } return 0; } diff --git a/examples/cpp/Sample-PointCloud/PointCloud.cpp b/examples/cpp/Sample-PointCloud/PointCloud.cpp index 98212ca8..e41ac9b1 100644 --- a/examples/cpp/Sample-PointCloud/PointCloud.cpp +++ b/examples/cpp/Sample-PointCloud/PointCloud.cpp @@ -105,7 +105,9 @@ int main(int argc, char **argv) try { std::shared_ptr depthProfile; try { // Select the profile with the same frame rate as color. - depthProfile = depthProfileList->getVideoStreamProfile(OB_WIDTH_ANY, OB_HEIGHT_ANY, OB_FORMAT_ANY, colorProfile->fps()); + if(colorProfile) { + depthProfile = depthProfileList->getVideoStreamProfile(OB_WIDTH_ANY, OB_HEIGHT_ANY, OB_FORMAT_ANY, colorProfile->fps()); + } } catch(...) { depthProfile = nullptr; diff --git a/examples/cpp/Sample-SaveToDisk/SaveToDisk.cpp b/examples/cpp/Sample-SaveToDisk/SaveToDisk.cpp index bc0dc70a..54d48607 100644 --- a/examples/cpp/Sample-SaveToDisk/SaveToDisk.cpp +++ b/examples/cpp/Sample-SaveToDisk/SaveToDisk.cpp @@ -46,7 +46,7 @@ int main(int argc, char **argv) try { auto colorProfiles = pipeline.getStreamProfileList(OB_SENSOR_COLOR); std::shared_ptr colorProfile = nullptr; if(colorProfiles) { - colorProfile = std::const_pointer_cast(colorProfiles->getProfile(0))->as(); + colorProfile = std::const_pointer_cast(colorProfiles->getProfile(OB_PROFILE_DEFAULT))->as(); } config->enableStream(colorProfile); } @@ -60,7 +60,7 @@ int main(int argc, char **argv) try { auto depthProfiles = pipeline.getStreamProfileList(OB_SENSOR_DEPTH); std::shared_ptr depthProfile = nullptr; if(depthProfiles) { - depthProfile = std::const_pointer_cast(depthProfiles->getProfile(0))->as(); + depthProfile = std::const_pointer_cast(depthProfiles->getProfile(OB_PROFILE_DEFAULT))->as(); } config->enableStream(depthProfile); diff --git a/examples/cpp/Sample-SyncAlignViewer/SyncAlignViewer.cpp b/examples/cpp/Sample-SyncAlignViewer/SyncAlignViewer.cpp index 520c9b4a..f0413c5e 100644 --- a/examples/cpp/Sample-SyncAlignViewer/SyncAlignViewer.cpp +++ b/examples/cpp/Sample-SyncAlignViewer/SyncAlignViewer.cpp @@ -133,7 +133,7 @@ int main(int argc, char **argv) try { // Get all stream profiles of the color camera, including stream resolution, frame rate, and frame format auto colorProfiles = pipe.getStreamProfileList(OB_SENSOR_COLOR); if(colorProfiles) { - colorProfile = std::const_pointer_cast(colorProfiles->getProfile(0))->as(); + colorProfile = std::const_pointer_cast(colorProfiles->getProfile(OB_PROFILE_DEFAULT))->as(); } config->enableStream(colorProfile); } @@ -146,7 +146,7 @@ int main(int argc, char **argv) try { auto depthProfiles = pipe.getStreamProfileList(OB_SENSOR_DEPTH); std::shared_ptr depthProfile = nullptr; if(depthProfiles) { - depthProfile = std::const_pointer_cast(depthProfiles->getProfile(0))->as(); + depthProfile = std::const_pointer_cast(depthProfiles->getProfile(OB_PROFILE_DEFAULT))->as(); } config->enableStream(depthProfile); diff --git a/examples/cpp/Sample-Transformation/Transformation.cpp b/examples/cpp/Sample-Transformation/Transformation.cpp index 126e279d..f9c18a14 100644 --- a/examples/cpp/Sample-Transformation/Transformation.cpp +++ b/examples/cpp/Sample-Transformation/Transformation.cpp @@ -92,7 +92,7 @@ int depthPointCloudTransformation(std::shared_ptr device, int case_n uint32_t pointcloudSize = depthWidth * depthHeight * sizeof(OBPoint3f); uint8_t *pointcloudData = new uint8_t[pointcloudSize]; - uint32_t tableSize = depthWidth * depthHeight * 2 * sizeof(float); + uint32_t tableSize = depthWidth * depthHeight * 2; float * data = new float[tableSize]; OBXYTables xyTables; if(!ob::CoordinateTransformHelper::transformationInitXYTables(param, OB_SENSOR_DEPTH, data, &tableSize, &xyTables)) { @@ -100,7 +100,7 @@ int depthPointCloudTransformation(std::shared_ptr device, int case_n } int count = 0; - if(number == 1) { + if (case_number == 1) { // Limit up to 10 repetitions while(count++ < 10) { // Wait for a frame of data, the timeout is 100ms @@ -137,9 +137,8 @@ int depthPointCloudTransformation(std::shared_ptr device, int case_n std::cout << "Get depth frame or depth frame failed!" << std::endl; } } - } - else if(number == 2) { - // Limit up to 10 repetitions + } else if (case_number == 2) { + // Limit up to 10 repetitions while(count++ < 10) { // Wait for up to 100ms for a frameset in blocking mode. auto frameset = pipeline->waitForFrames(100); @@ -172,9 +171,8 @@ int depthPointCloudTransformation(std::shared_ptr device, int case_n break; } } - } - else if(number == 3) { - while(count++ < 10) { + } else if (case_number == 3) { + while (count++ < 10) { // Wait for up to 100ms for a frameset in blocking mode. auto frameset = pipeline->waitForFrames(100); if(frameset != nullptr && frameset->depthFrame() != nullptr) { @@ -290,7 +288,7 @@ int RGBPointCloudTransformation(std::shared_ptr device) { auto param = pipeline->getCalibrationParam(config); uint32_t colorWidth = colorProfile->width(); uint32_t colorHeight = colorProfile->height(); - uint32_t tableSize = colorWidth * colorHeight * 2 * sizeof(float); + uint32_t tableSize = colorWidth * colorHeight * 2; float * data = new float[tableSize]; uint32_t pointcloudSize = colorWidth * colorHeight * sizeof(OBColorPoint);