Skip to content

Commit e339741

Browse files
committed
added status return code to videoSource::Capture()
1 parent 4bb0c74 commit e339741

File tree

16 files changed

+108
-93
lines changed

16 files changed

+108
-93
lines changed

Diff for: examples/actionnet/actionnet.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,16 @@ int main( int argc, char** argv )
132132
*/
133133
while( !signal_recieved )
134134
{
135-
// capture next image image
135+
// capture next image
136136
uchar3* image = NULL;
137-
138-
if( !input->Capture(&image) )
137+
int status = 0;
138+
139+
if( !input->Capture(&image, &status) )
139140
{
140-
// check for EOS
141-
if( !input->IsStreaming() )
142-
break;
143-
144-
LogError("actionnet: failed to capture next frame\n");
145-
continue;
141+
if( status == videoSource::TIMEOUT )
142+
continue;
143+
144+
break; // EOS
146145
}
147146

148147
// classify the action sequence
@@ -175,7 +174,7 @@ int main( int argc, char** argv )
175174

176175
// check if the user quit
177176
if( !output->IsStreaming() )
178-
signal_recieved = true;
177+
break;
179178
}
180179

181180
// print out timing info

Diff for: examples/backgroundnet/backgroundnet.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,16 @@ int main( int argc, char** argv )
178178
*/
179179
while( !signal_recieved )
180180
{
181-
// capture next image image
181+
// capture next image
182182
pixelType* imgInput = NULL;
183-
184-
if( !input->Capture(&imgInput) )
183+
int status = 0;
184+
185+
if( !input->Capture(&imgInput, &status) )
185186
{
186-
// check for EOS
187-
if( !input->IsStreaming() )
188-
break;
189-
190-
LogError("backgroundnet: failed to capture next frame\n");
191-
continue;
187+
if( status == videoSource::TIMEOUT )
188+
continue;
189+
190+
break; // EOS
192191
}
193192

194193
// process image
@@ -216,7 +215,7 @@ int main( int argc, char** argv )
216215

217216
// check if the user quit
218217
if( !output->IsStreaming() )
219-
signal_recieved = true;
218+
break;
220219
}
221220

222221
// print out timing info

Diff for: examples/depthnet/depthnet.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,16 @@ int main( int argc, char** argv )
208208
*/
209209
while( !signal_recieved )
210210
{
211-
// capture next image image
211+
// capture next image
212212
pixelType* imgInput = NULL;
213-
214-
if( !input->Capture(&imgInput) )
213+
int status = 0;
214+
215+
if( !input->Capture(&imgInput, &status) )
215216
{
216-
// check for EOS
217-
if( !input->IsStreaming() )
218-
break;
219-
220-
LogError("depthnet: failed to capture next frame\n");
221-
continue;
217+
if( status == videoSource::TIMEOUT )
218+
continue;
219+
220+
break; // EOS
222221
}
223222

224223
// allocate buffers for this size frame
@@ -256,7 +255,7 @@ int main( int argc, char** argv )
256255

257256
// check if the user quit
258257
if( !output->IsStreaming() )
259-
signal_recieved = true;
258+
break;
260259
}
261260

262261
// wait for the GPU to finish

Diff for: examples/detectnet/detectnet.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "detectNet.h"
2727
#include "objectTracker.h"
2828

29-
3029
#include <signal.h>
3130

3231

@@ -67,6 +66,7 @@ int usage()
6766
return 0;
6867
}
6968

69+
7070
int main( int argc, char** argv )
7171
{
7272
/*
@@ -129,17 +129,16 @@ int main( int argc, char** argv )
129129
*/
130130
while( !signal_recieved )
131131
{
132-
// capture next image image
132+
// capture next image
133133
uchar3* image = NULL;
134+
int status = 0;
134135

135-
if( !input->Capture(&image) )
136+
if( !input->Capture(&image, &status) )
136137
{
137-
// check for EOS
138-
if( !input->IsStreaming() && input->GetFrameCount() > 0 )
139-
break;
140-
141-
LogError("detectnet: failed to capture video frame\n");
142-
continue;
138+
if( status == videoSource::TIMEOUT )
139+
continue;
140+
141+
break; // EOS
143142
}
144143

145144
// detect objects in the frame
@@ -173,7 +172,7 @@ int main( int argc, char** argv )
173172

174173
// check if the user quit
175174
if( !output->IsStreaming() )
176-
signal_recieved = true;
175+
break;
177176
}
178177

179178
// print out timing info

Diff for: examples/imagenet/imagenet.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,16 @@ int main( int argc, char** argv )
142142
*/
143143
while( !signal_recieved )
144144
{
145-
// capture next image image
145+
// capture next image
146146
uchar3* image = NULL;
147-
148-
if( !input->Capture(&image) )
147+
int status = 0;
148+
149+
if( !input->Capture(&image, &status) )
149150
{
150-
// check for EOS
151-
if( !input->IsStreaming() )
152-
break;
153-
154-
LogError("imagenet: failed to capture next frame\n");
155-
continue;
151+
if( status == videoSource::TIMEOUT )
152+
continue;
153+
154+
break; // EOS
156155
}
157156

158157
// classify image - note that if you only want the top class, you can simply run this instead:
@@ -191,7 +190,7 @@ int main( int argc, char** argv )
191190

192191
// check if the user quit
193192
if( !output->IsStreaming() )
194-
signal_recieved = true;
193+
break;
195194
}
196195

197196
// print out timing info

Diff for: examples/posenet/posenet.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,16 @@ int main( int argc, char** argv )
119119
*/
120120
while( !signal_recieved )
121121
{
122-
// capture next image image
122+
// capture next image
123123
uchar3* image = NULL;
124-
125-
if( !input->Capture(&image) )
124+
int status = 0;
125+
126+
if( !input->Capture(&image, &status) )
126127
{
127-
// check for EOS
128-
if( !input->IsStreaming() )
129-
break;
130-
131-
LogError("posenet: failed to capture next frame\n");
132-
continue;
128+
if( status == videoSource::TIMEOUT )
129+
continue;
130+
131+
break; // EOS
133132
}
134133

135134
// run pose estimation
@@ -155,7 +154,7 @@ int main( int argc, char** argv )
155154

156155
// check if the user quit
157156
if( !output->IsStreaming() )
158-
signal_recieved = true;
157+
break;
159158
}
160159

161160
// print out timing info

Diff for: examples/segnet/segnet.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,16 @@ int main( int argc, char** argv )
218218
*/
219219
while( !signal_recieved )
220220
{
221-
// capture next image image
221+
// capture next image
222222
pixelType* imgInput = NULL;
223-
224-
if( !input->Capture(&imgInput) )
223+
int status = 0;
224+
225+
if( !input->Capture(&imgInput, &status) )
225226
{
226-
// check for EOS
227-
if( !input->IsStreaming() )
228-
break;
229-
230-
LogError("segnet: failed to capture video frame\n");
231-
continue;
227+
if( status == videoSource::TIMEOUT )
228+
continue;
229+
230+
break; // EOS
232231
}
233232

234233
// allocate buffers for this size frame
@@ -284,7 +283,7 @@ int main( int argc, char** argv )
284283

285284
// check if the user quit
286285
if( !output->IsStreaming() )
287-
signal_recieved = true;
286+
break;
288287
}
289288

290289
// wait for the GPU to finish

Diff for: python/examples/actionnet.py

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
# capture the next image
5858
img = input.Capture()
5959

60+
if img is None: # timeout
61+
continue
62+
6063
# classify the action sequence
6164
class_id, confidence = net.Classify(img)
6265
class_desc = net.GetClassDesc(class_id)

Diff for: python/examples/backgroundnet.py

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def replaceBackground(img_input):
8080
# capture the next image (with alpha channel)
8181
img_input = input.Capture(format='rgba8')
8282

83+
if img_input is None: # timeout
84+
continue
85+
8386
# perform background removal
8487
net.Process(img_input, filter=args.filter_mode)
8588

Diff for: python/examples/depthnet.py

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
# capture the next image
6767
img_input = input.Capture()
6868

69+
if img_input is None: # timeout
70+
continue
71+
6972
# allocate buffers for this size image
7073
buffers.Alloc(img_input.shape, img_input.format)
7174

Diff for: python/examples/detectnet-snap.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@
7474

7575
# process frames until the user exits
7676
while True:
77-
# capture the next image
78-
img = input.Capture()
77+
# capture the next image
78+
img = input.Capture()
79+
80+
if img is None: # timeout
81+
continue
7982

8083
# detect objects in the image (with overlay)
8184
detections = net.Detect(img, overlay=args.overlay)

Diff for: python/examples/detectnet.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,32 @@
6060
# input_blob="input_0", output_cvg="scores", output_bbox="boxes",
6161
# threshold=args.threshold)
6262

63-
# process frames until the user exits
63+
# process frames until EOS or the user exits
6464
while True:
65-
# capture the next image
66-
img = input.Capture()
65+
# capture the next image
66+
img = input.Capture()
6767

68-
# detect objects in the image (with overlay)
69-
detections = net.Detect(img, overlay=args.overlay)
68+
if img is None: # timeout
69+
continue
70+
71+
# detect objects in the image (with overlay)
72+
detections = net.Detect(img, overlay=args.overlay)
7073

71-
# print the detections
72-
print("detected {:d} objects in image".format(len(detections)))
74+
# print the detections
75+
print("detected {:d} objects in image".format(len(detections)))
7376

74-
for detection in detections:
75-
print(detection)
77+
for detection in detections:
78+
print(detection)
7679

77-
# render the image
78-
output.Render(img)
80+
# render the image
81+
output.Render(img)
7982

80-
# update the title bar
81-
output.SetStatus("{:s} | Network {:.0f} FPS".format(args.network, net.GetNetworkFPS()))
82-
83-
# print out performance info
84-
net.PrintProfilerTimes()
85-
86-
# exit on input/output EOS
87-
if not input.IsStreaming() or not output.IsStreaming():
88-
break
83+
# update the title bar
84+
output.SetStatus("{:s} | Network {:.0f} FPS".format(args.network, net.GetNetworkFPS()))
8985

86+
# print out performance info
87+
net.PrintProfilerTimes()
9088

89+
# exit on input/output EOS
90+
if not input.IsStreaming() or not output.IsStreaming():
91+
break

Diff for: python/examples/imagenet.py

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
# capture the next image
6666
img = input.Capture()
6767

68+
if img is None: # timeout
69+
continue
70+
6871
# classify the image and get the topK predictions
6972
# if you only want the top class, you can simply run:
7073
# class_id, confidence = net.Classify(img)

Diff for: python/examples/posenet.py

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
# capture the next image
5858
img = input.Capture()
5959

60+
if img is None: # timeout
61+
continue
62+
6063
# perform pose estimation (with overlay)
6164
poses = net.Process(img, overlay=opt.overlay)
6265

Diff for: python/examples/segnet.py

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
# capture the next image
7878
img_input = input.Capture()
7979

80+
if img_input is None: # timeout
81+
continue
82+
8083
# allocate buffers for this size image
8184
buffers.Alloc(img_input.shape, img_input.format)
8285

0 commit comments

Comments
 (0)