Skip to content

Commit fb327a2

Browse files
3Ddaiweizhonghong322
authored andcommitted
[1.9.x][sample]:update sample code ref v1.9.5
1 parent 3f22e57 commit fb327a2

File tree

15 files changed

+369
-424
lines changed

15 files changed

+369
-424
lines changed

examples/c/Sample-ColorViewer/color_viewer.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#include "window.hpp"
2-
3-
#include <condition_variable>
42
#include <iostream>
5-
#include <mutex>
6-
#include <thread>
7-
#include <cstdlib>
83

94
extern "C" {
5+
#include <stdlib.h>
106
#include <libobsensor/h/Error.h>
117
#include <libobsensor/h/Frame.h>
128
#include <libobsensor/h/ObTypes.h>
@@ -21,12 +17,6 @@ extern "C" {
2117
* to demonstrate how to open color stream and get frames.
2218
*/
2319

24-
// create global variable
25-
Window *win = nullptr; // rendering display window, based on opencv
26-
ob_error *error = NULL; // Used to return SDK interface error information
27-
ob_pipeline *pipe = nullptr; // pipeline, used to open the color stream after connecting the device
28-
ob_device *device = nullptr; // device, obtained through the pipeline, and the corresponding sensor can be obtained through the device
29-
3020
void check_error(ob_error *error) {
3121
if(error) {
3222
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) {
3828
}
3929

4030
int main(int argc, char **args) {
31+
Window *win = nullptr; // rendering display window, based on opencv
32+
ob_error *error = NULL; // Used to return SDK interface error information
33+
ob_pipeline *pipeline = nullptr; // pipeline, used to open the color stream after connecting the device
34+
ob_device *device = nullptr; // device, obtained through the pipeline, and the corresponding sensor can be obtained through the device
35+
4136
// Create a pipeline to open the color stream after connecting the device
42-
pipe = ob_create_pipeline(&error);
37+
pipeline = ob_create_pipeline(&error);
4338
check_error(error);
4439

4540
// Create config to configure the resolution, frame rate, and format of the color stream
@@ -48,7 +43,7 @@ int main(int argc, char **args) {
4843

4944
// Configure the color stream
5045
ob_stream_profile *color_profile = nullptr;
51-
ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_COLOR, &error);
46+
ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_COLOR, &error);
5247
if(error) {
5348
printf("Current device is not support color sensor!\n");
5449
exit(EXIT_FAILURE);
@@ -68,11 +63,11 @@ int main(int argc, char **args) {
6863
check_error(error);
6964

7065
// Get Device through Pipeline
71-
device = ob_pipeline_get_device(pipe, &error);
66+
device = ob_pipeline_get_device(pipeline, &error);
7267
check_error(error);
7368

7469
// Start the pipeline with config
75-
ob_pipeline_start_with_config(pipe, config, &error);
70+
ob_pipeline_start_with_config(pipeline, config, &error);
7671
check_error(error);
7772

7873
// Create a rendering display window
@@ -86,7 +81,7 @@ int main(int argc, char **args) {
8681
// Wait in a loop, and exit after the window receives the "ESC_KEY" key
8782
while(*win) {
8883
// Wait for up to 100ms for a frameset in blocking mode.
89-
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error);
84+
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipeline, 100, &error);
9085
check_error(error);
9186

9287
if(frameset == nullptr) {
@@ -105,7 +100,7 @@ int main(int argc, char **args) {
105100
};
106101

107102
// stop the pipeline
108-
ob_pipeline_stop(pipe, &error);
103+
ob_pipeline_stop(pipeline, &error);
109104
check_error(error);
110105

111106
// destroy window
@@ -124,7 +119,7 @@ int main(int argc, char **args) {
124119
check_error(error);
125120

126121
// destroy the pipeline
127-
ob_delete_pipeline(pipe, &error);
122+
ob_delete_pipeline(pipeline, &error);
128123
check_error(error);
129124

130125
return 0;

examples/c/Sample-DepthViewer/depth_viewer.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "window.hpp"
2-
3-
#include <condition_variable>
42
#include <iostream>
5-
#include <mutex>
6-
#include <thread>
73

84
extern "C" {
95
#include <stdlib.h>
@@ -19,11 +15,6 @@ extern "C" {
1915
*This sample is written in C++ code, based on the C language version API of OrbbecSDK.
2016
*/
2117

22-
// Create global variables
23-
Window *win = nullptr; // render window, based on opencv
24-
ob_error *error = NULL; // Used to return SDK interface error information
25-
ob_pipeline *pipe = nullptr; // pipeline, used to open the depth stream after connecting the device
26-
2718
void check_error(ob_error *error) {
2819
if(error) {
2920
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) {
3526
}
3627

3728
int main(int argc, char **args) {
29+
Window *win = nullptr; // render window, based on opencv
30+
ob_error *error = NULL; // Used to return SDK interface error information
31+
ob_pipeline *pipeline = nullptr; // pipeline, used to open the depth stream after connecting the device
32+
3833
// Create a pipeline to open the depth stream after connecting the device
39-
pipe = ob_create_pipeline(&error);
34+
pipeline = ob_create_pipeline(&error);
4035
check_error(error);
4136

4237
// Create config to configure the resolution, frame rate, and format of the depth stream
@@ -45,7 +40,7 @@ int main(int argc, char **args) {
4540

4641
// Configure the depth stream
4742
ob_stream_profile *depth_profile = NULL;
48-
ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_DEPTH, &error);
43+
ob_stream_profile_list *profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_DEPTH, &error);
4944
check_error(error);
5045

5146
// 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) {
6257
check_error(error);
6358

6459
// Start the pipeline with config
65-
ob_pipeline_start_with_config(pipe, config, &error);
60+
ob_pipeline_start_with_config(pipeline, config, &error);
6661
check_error(error);
6762

6863
// Create a window for rendering, and set the resolution of the window
@@ -76,7 +71,7 @@ int main(int argc, char **args) {
7671
// Wait in a loop, exit after the window receives the "esc" key
7772
while(*win) {
7873
// Wait for up to 100ms for a frameset in blocking mode.
79-
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error);
74+
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipeline, 100, &error);
8075
check_error(error);
8176

8277
if(frameset == nullptr) {
@@ -117,7 +112,7 @@ int main(int argc, char **args) {
117112
};
118113

119114
// stop the pipeline
120-
ob_pipeline_stop(pipe, &error);
115+
ob_pipeline_stop(pipeline, &error);
121116
check_error(error);
122117

123118
// destroy the window
@@ -132,7 +127,7 @@ int main(int argc, char **args) {
132127
check_error(error);
133128

134129
// destroy the pipeline
135-
ob_delete_pipeline(pipe, &error);
130+
ob_delete_pipeline(pipeline, &error);
136131
check_error(error);
137132

138133
return 0;

examples/c/Sample-DepthWorkMode/depth_work_mode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ int main(int argc, char **argv) {
4242
ob_error *error = NULL;
4343

4444
// Create a pipeline to open the depth stream after connecting the device
45-
ob_pipeline *pipe = ob_create_pipeline(&error);
45+
ob_pipeline *pipeline = ob_create_pipeline(&error);
4646
check_error(error);
4747

4848
// Get the device through the pipeline
49-
ob_device *dev = ob_pipeline_get_device(pipe, &error);
49+
ob_device *dev = ob_pipeline_get_device(pipeline, &error);
5050
check_error(error);
5151

5252
// 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) {
132132
check_error(error);
133133

134134
// destroy the pipeline
135-
ob_delete_pipeline(pipe, &error);
135+
ob_delete_pipeline(pipeline, &error);
136136
check_error(error);
137137

138138
return 0;

examples/c/Sample-DoubleInfraredViewer/double_infrared_viewer.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "window.hpp"
2-
3-
#include <condition_variable>
42
#include <iostream>
5-
#include <mutex>
6-
#include <thread>
73

84
extern "C" {
95
#include <stdlib.h>
@@ -19,11 +15,6 @@ extern "C" {
1915
*This sample is written in C++ code, based on the C language version API of OrbbecSDK.
2016
*/
2117

22-
// Create global variables
23-
Window *win = nullptr; // render window, based on opencv
24-
ob_error *error = NULL; // Used to return SDK interface error information
25-
ob_pipeline *pipe = nullptr; // pipeline, used to open the Infrared stream after connecting the device
26-
2718
void check_error(ob_error *error) {
2819
if(error) {
2920
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) {
3526
}
3627

3728
int main(int argc, char **args) {
29+
Window *win = nullptr; // render window, based on opencv
30+
ob_error *error = NULL; // Used to return SDK interface error information
31+
ob_pipeline *pipeline = nullptr; // pipeline, used to open the Infrared stream after connecting the device
32+
3833
// Create a pipeline to open the Infrared stream after connecting the device
39-
pipe = ob_create_pipeline(&error);
34+
pipeline = ob_create_pipeline(&error);
4035
check_error(error);
4136

4237
// Create config to configure the resolution, frame rate, and format of the Infrared stream
@@ -45,7 +40,7 @@ int main(int argc, char **args) {
4540

4641
// Configure the infrared stream(IR_LEFT)
4742
ob_stream_profile *ir_left_profile = NULL;
48-
ob_stream_profile_list *ir_left_profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_IR_LEFT, &error);
43+
ob_stream_profile_list *ir_left_profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_IR_LEFT, &error);
4944
check_error(error);
5045

5146
if(ir_left_profiles == nullptr) {
@@ -63,7 +58,7 @@ int main(int argc, char **args) {
6358

6459
// Configure the infrared stream(IR_RIGHT)
6560
ob_stream_profile *ir_right_profile = NULL;
66-
ob_stream_profile_list *ir_right_profiles = ob_pipeline_get_stream_profile_list(pipe, OB_SENSOR_IR_RIGHT, &error);
61+
ob_stream_profile_list *ir_right_profiles = ob_pipeline_get_stream_profile_list(pipeline, OB_SENSOR_IR_RIGHT, &error);
6762
check_error(error);
6863

6964
// 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) {
7570
check_error(error);
7671

7772
// Start the pipeline with config
78-
ob_pipeline_start_with_config(pipe, config, &error);
73+
ob_pipeline_start_with_config(pipeline, config, &error);
7974
check_error(error);
8075

8176
// Create a rendering display window
@@ -85,7 +80,7 @@ int main(int argc, char **args) {
8580
// Wait in a loop, exit after the window receives the "esc" key
8681
while(*win) {
8782
// Wait for up to 100ms for a frameset in blocking mode.
88-
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error);
83+
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipeline, 100, &error);
8984
check_error(error);
9085

9186
if(frameset == nullptr) {
@@ -111,7 +106,7 @@ int main(int argc, char **args) {
111106
};
112107

113108
// stop the pipeline
114-
ob_pipeline_stop(pipe, &error);
109+
ob_pipeline_stop(pipeline, &error);
115110
check_error(error);
116111

117112
// destroy the window
@@ -134,7 +129,7 @@ int main(int argc, char **args) {
134129
check_error(error);
135130

136131
// destroy the pipeline
137-
ob_delete_pipeline(pipe, &error);
132+
ob_delete_pipeline(pipeline, &error);
138133
check_error(error);
139134

140135
return 0;

0 commit comments

Comments
 (0)