Skip to content

Commit

Permalink
[1.9.x][sample]:update sample code ref v1.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
3Ddaiwei authored and zhonghong322 committed Mar 6, 2024
1 parent 3f22e57 commit fb327a2
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 424 deletions.
31 changes: 13 additions & 18 deletions examples/c/Sample-ColorViewer/color_viewer.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include "window.hpp"

#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
#include <cstdlib>

extern "C" {
#include <stdlib.h>
#include <libobsensor/h/Error.h>
#include <libobsensor/h/Frame.h>
#include <libobsensor/h/ObTypes.h>
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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;
Expand Down
25 changes: 10 additions & 15 deletions examples/c/Sample-DepthViewer/depth_viewer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "window.hpp"

#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>

extern "C" {
#include <stdlib.h>
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions examples/c/Sample-DepthWorkMode/depth_work_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 11 additions & 16 deletions examples/c/Sample-DoubleInfraredViewer/double_infrared_viewer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "window.hpp"

#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>

extern "C" {
#include <stdlib.h>
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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;
Expand Down
Loading

0 comments on commit fb327a2

Please sign in to comment.