Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf77f896

Browse files
committed
Fix C Sample memory leak and Transformation Sample crash issue
1 parentb88b4cf commitf77f896

File tree

14 files changed

+271
-56
lines changed

14 files changed

+271
-56
lines changed

‎examples/c/Sample-AlignFilterViewer/align_filter_viewer.cpp‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,29 @@ int main(int argc, char **args) {
200200
win->resize(w, h);
201201
resizeWindows =false;
202202
}
203-
204203
win->addToRender({ color_frame, depth_frame });
205204

206205
ob_delete_frame(new_frame_set, &error);
207206
check_error(error);
208207
}
208+
elseif(depth_frame !=nullptr) {
209+
ob_delete_frame(depth_frame, &error);
210+
check_error(error);
211+
}
212+
elseif(color_frame !=nullptr) {
213+
ob_delete_frame(color_frame, &error);
214+
check_error(error);
215+
}
209216
ob_delete_frame(frameset, &error);
210217
check_error(error);
211218
};
212219

213220
ob_delete_filter(align_filter, &error);
214221
check_error(error);
215222

223+
ob_delete_config(config, &error);
224+
check_error(error);
225+
216226
// stop the pipeline
217227
ob_pipeline_stop(pipeline, &error);
218228
check_error(error);

‎examples/c/Sample-ColorViewer/color_viewer.cpp‎

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,40 @@ extern "C" {
1313
}
1414

1515
/*
16-
* This example is written in C++, based on the C language version API of OrbbecSDK,
17-
* to demonstrate how to open color stream and get frames.
16+
* Notes: Currently, only Gemini 330 series devices support Metadata.
1817
*/
18+
constchar *metaDataTypes[] = {"TIMESTAMP",
19+
"SENSOR_TIMESTAMP",
20+
"FRAME_NUMBER",
21+
"AUTO_EXPOSURE",
22+
"EXPOSURE",
23+
"GAIN",
24+
"AUTO_WHITE_BALANCE",
25+
"WHITE_BALANCE",
26+
"BRIGHTNESS",
27+
"CONTRAST",
28+
"SATURATION",
29+
"SHARPNESS",
30+
"BACKLIGHT_COMPENSATION",
31+
"HUE",
32+
"GAMMA",
33+
"POWER_LINE_FREQUENCY",
34+
"LOW_LIGHT_COMPENSATION",
35+
"MANUAL_WHITE_BALANCE",
36+
"ACTUAL_FRAME_RATE",
37+
"FRAME_RATE",
38+
"AE_ROI_LEFT",
39+
"AE_ROI_TOP",
40+
"AE_ROI_RIGHT",
41+
"AE_ROI_BOTTOM",
42+
"EXPOSURE_PRIORITY",
43+
"HDR_SEQUENCE_NAME",
44+
"HDR_SEQUENCE_SIZE",
45+
"HDR_SEQUENCE_INDEX",
46+
"LASER_POWER",
47+
"LASER_POWER_LEVEL",
48+
"LASER_STATUS",
49+
"GPIO_INPUT_DATA" };
1950

2051
voidcheck_error(ob_error *error) {
2152
if(error) {
@@ -88,13 +119,40 @@ int main(int argc, char **args) {
88119
continue;
89120
}
90121

122+
// Get the color frame from the frameset
91123
ob_frame *color_frame =ob_frameset_color_frame(frameset, &error);
92124
check_error(error);
93-
if(color_frame !=nullptr) {
94-
// add frame to render, will auto delete frame when render finished
95-
win->addToRender(color_frame);
125+
if(color_frame ==nullptr) {
126+
ob_delete_frame(frameset, &error);
127+
check_error(error);
128+
continue;
129+
}
130+
131+
// Get the index of the frame
132+
auto index =ob_frame_index(color_frame, &error);
133+
check_error(error);
134+
135+
// print meta data every 30 frames
136+
if(index %30 ==0) {
137+
std::cout <<"*************************** Color Frame #" << index <<" Metadata List ********************************" << std::endl;
138+
for(int metaDataType =0; metaDataType < OB_FRAME_METADATA_TYPE_COUNT; metaDataType++) {
139+
// Check if it is supported metaDataType
140+
if(ob_frame_has_metadata(color_frame, (OBFrameMetadataType)metaDataType, &error)) {
141+
// get metaData value
142+
std::cout << metaDataTypes[metaDataType] <<":" <<ob_frame_get_metadata_value(color_frame, (OBFrameMetadataType)metaDataType, &error)
143+
<< std::endl;
144+
}
145+
else {
146+
std::cout << metaDataTypes[metaDataType] <<":"
147+
<<"unsupported" << std::endl;
148+
}
149+
}
150+
std::cout <<"********************************************************************************" << std::endl << std::endl;
96151
}
97152

153+
// add frame to render, will auto delete frame when render finished
154+
win->addToRender(color_frame);
155+
98156
ob_delete_frame(frameset, &error);
99157
check_error(error);
100158
};
@@ -118,6 +176,10 @@ int main(int argc, char **args) {
118176
ob_delete_device(device, &error);
119177
check_error(error);
120178

179+
// destroy the config
180+
ob_delete_config(config, &error);
181+
check_error(error);
182+
121183
// destroy the pipeline
122184
ob_delete_pipeline(pipeline, &error);
123185
check_error(error);

‎examples/c/Sample-DepthViewer/depth_viewer.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ int main(int argc, char **args) {
126126
ob_delete_stream_profile_list(profiles, &error);
127127
check_error(error);
128128

129+
// destroy the config
130+
ob_delete_config(config, &error);
131+
check_error(error);
132+
129133
// destroy the pipeline
130134
ob_delete_pipeline(pipeline, &error);
131135
check_error(error);

‎examples/c/Sample-DoubleInfraredViewer/double_infrared_viewer.cpp‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int main(int argc, char **args) {
4444
check_error(error);
4545

4646
if(ir_left_profiles ==nullptr) {
47-
printf("The obtainedIR_Left resolution list is NULL. For monocular structured light devices, try opening the IR data stream using the IR example.");
47+
printf("The obtainedIR(Left) resolution list is NULL. For monocular structured light devices, try opening the IR data stream using the IR example.");
4848
return0;
4949
}
5050

@@ -69,6 +69,10 @@ int main(int argc, char **args) {
6969
ob_config_enable_stream(config, ir_right_profile, &error);
7070
check_error(error);
7171

72+
// enable frame sync
73+
ob_pipeline_enable_frame_sync(pipeline, &error);
74+
check_error(error);
75+
7276
// Start the pipeline with config
7377
ob_pipeline_start_with_config(pipeline, config, &error);
7478
check_error(error);
@@ -94,6 +98,17 @@ int main(int argc, char **args) {
9498
check_error(error);
9599

96100
if(ir_left_frame ==nullptr || ir_right_frame ==nullptr) {
101+
if (ir_left_frame)
102+
{
103+
ob_delete_frame(ir_left_frame, &error);
104+
}
105+
106+
if (ir_right_frame)
107+
{
108+
ob_delete_frame(ir_right_frame, &error);
109+
}
110+
111+
ob_delete_frame(frameset, &error);
97112
std::cout <<"left ir frame or right ir frame is null. leftFrame:" << ir_left_frame <<", rightFrame:" << ir_right_frame << std::endl;
98113
continue;
99114
}
@@ -128,6 +143,10 @@ int main(int argc, char **args) {
128143
ob_delete_stream_profile_list(ir_right_profiles, &error);
129144
check_error(error);
130145

146+
// destroy the config
147+
ob_delete_config(config, &error);
148+
check_error(error);
149+
131150
// destroy the pipeline
132151
ob_delete_pipeline(pipeline, &error);
133152
check_error(error);

‎examples/c/Sample-FirmwareUpgrade/firmware_upgrade.cpp‎

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ int main(int argc, char **argv) {
7474
check_error(error);
7575
if(dev_count ==0) {
7676
printf("Device not found!\n");
77+
78+
ob_delete_device_list(dev_list, &error);
79+
check_error(error);
80+
81+
ob_delete_context(ctx, &error);
82+
check_error(error);
7783
return -1;
7884
}
7985

@@ -110,10 +116,28 @@ int main(int argc, char **argv) {
110116
int confirm_char =getch();
111117
if(ESC_KEY == confirm_char) {
112118
printf("\nCancel upgrade firmware\n");
119+
120+
ob_delete_device(dev, &error);
121+
check_error(error);
122+
123+
ob_delete_device_list(dev_list, &error);
124+
check_error(error);
125+
126+
ob_delete_context(ctx, &error);
127+
check_error(error);
113128
return0;
114129
}
115130
elseif('N' == confirm_char ||'n' == confirm_char) {
116131
printf("\nAbort upgrade firmware\n");
132+
133+
ob_delete_device(dev, &error);
134+
check_error(error);
135+
136+
ob_delete_device_list(dev_list, &error);
137+
check_error(error);
138+
139+
ob_delete_context(ctx, &error);
140+
check_error(error);
117141
return0;
118142
}
119143
elseif('Y' == confirm_char ||'y' == confirm_char) {
@@ -130,6 +154,15 @@ int main(int argc, char **argv) {
130154
// Upgrade firmware file Path
131155
if(!upgrade_firmware(dev, firmware_file_path)) {
132156
printf("Upgrade firmware failed\n");
157+
158+
ob_delete_device(dev, &error);
159+
check_error(error);
160+
161+
ob_delete_device_list(dev_list, &error);
162+
check_error(error);
163+
164+
ob_delete_context(ctx, &error);
165+
check_error(error);
133166
return -1;
134167
}
135168
printf("Upgrade firmware complete\n");
@@ -180,6 +213,10 @@ int main(int argc, char **argv) {
180213
std::this_thread::sleep_for(std::chrono::milliseconds(500));
181214
}
182215
}
216+
217+
ob_delete_context(ctx, &error);
218+
check_error(error);
219+
183220
return0;
184221
}
185222

@@ -264,25 +301,10 @@ bool upgrade_firmware(ob_device *device, const char *firmwarePath) {
264301

265302
// Process firmware callback event
266303
voiddevice_upgrade_callback(ob_upgrade_state state,constchar *message,uint8_t percent,void *user_data) {
267-
if(state == STAT_START) {
268-
printf("Upgrade Firmware start\n");
269-
}
270-
elseif(state == STAT_FILE_TRANSFER) {
271-
printf("Upgrade Firmware file transfer, percent: %u\n", (uint32_t)percent);
272-
}
273-
elseif(state == STAT_IN_PROGRESS) {
274-
printf("Upgrade Firmware in progress, percent: %u\n", (uint32_t)percent);
275-
}
276-
elseif(state == STAT_DONE) {
277-
printf("Upgrade Firmware done, percent: %u\n", (uint32_t)percent);
304+
printf("%s (state: %d, percent: %u)\n", message ? message :"", (int)state, (uint32_t)percent);
305+
if(state == STAT_DONE) {
278306
is_upgrade_success_ =true;
279307
}
280-
elseif(state == STAT_VERIFY_IMAGE) {
281-
printf("Upgrade Firmware verify image\n");
282-
}
283-
else {
284-
printf("Upgrade Firmware failed. state: %d, errMsg: %s, percent: %u\n", (int)state, message ? message :"", (uint32_t)percent);
285-
}
286308
}
287309

288310
// Process device change callback event

‎examples/c/Sample-HdrMerge/hdr_merge.cpp‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ int main(int argc, char **args) {
4848
hdr_config.enable =true;// enable Hdr
4949
hdr_config.exposure_1 =7500;
5050
hdr_config.gain_1 =16;
51-
hdr_config.exposure_2 =100;
52-
hdr_config.gain_2 =1;
51+
hdr_config.exposure_2 =1;
52+
hdr_config.gain_2 =16;
5353
ob_device_set_structured_data(dev, OB_STRUCT_DEPTH_HDR_CONFIG, &hdr_config,sizeof(ob_hdr_config), &error);
5454
check_error(error);
5555

@@ -130,15 +130,14 @@ int main(int argc, char **args) {
130130
ob_delete_frame(depth_frame, &error);
131131
check_error(error);
132132
}
133-
else{
133+
else{
134134
// add the original depth frame to the render queue
135135
win->addToRender(depth_frame);// will auto release merged_depth_frame inside the function
136136
}
137137

138138
// release the frameset
139139
ob_delete_frame(frameset, &error);
140140
check_error(error);
141-
142141
}
143142

144143
// close hdr
@@ -164,6 +163,13 @@ int main(int argc, char **args) {
164163
ob_delete_stream_profile_list(profiles, &error);
165164
check_error(error);
166165

166+
// destroy the config
167+
ob_delete_config(config, &error);
168+
check_error(error);
169+
170+
ob_delete_device(dev, &error);
171+
check_error(error);
172+
167173
// destroy the pipeline
168174
ob_delete_pipeline(pipeline, &error);
169175
check_error(error);

‎examples/c/Sample-InfraredViewer/infrared_viewer.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ int main(int argc, char **args) {
111111
ob_delete_stream_profile_list(profiles, &error);
112112
check_error(error);
113113

114+
ob_delete_config(config, &error);
115+
check_error(error);
116+
114117
// destroy the pipeline
115118
ob_delete_pipeline(pipeline, &error);
116119
check_error(error);

‎examples/c/Sample-NetDevice/net_device.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ int main(int argc, char **args) {
168168
win->addToRender({ color_frame, depth_frame });
169169
}
170170
}
171+
else {
172+
if (color_frame !=nullptr) {
173+
ob_delete_frame(color_frame, &error);
174+
check_error(error);
175+
}
176+
if (depth_frame !=nullptr) {
177+
ob_delete_frame(depth_frame, &error);
178+
check_error(error);
179+
}
180+
}
171181
// destroy frameset
172182
ob_delete_frame(frameset_for_render, &error);
173183
check_error(error);
@@ -211,6 +221,10 @@ int main(int argc, char **args) {
211221
ob_delete_device(device, &error);
212222
check_error(error);
213223

224+
// destroy the config
225+
ob_delete_config(config, &error);
226+
check_error(error);
227+
214228
// destroy the pipeline
215229
ob_delete_pipeline(pipeline, &error);
216230
check_error(error);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp