Skip to content

Commit 00cd1e8

Browse files
committed
Handle connection lost in Camera Control Example
1 parent 6b332b9 commit 00cd1e8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

examples/zed_oc_control_example.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int main(int argc, char *argv[])
114114

115115
// ----> Set Video parameters
116116
sl_oc::video::VideoParams params;
117-
params.res = sl_oc::video::RESOLUTION::VGA;
117+
params.res = sl_oc::video::RESOLUTION::HD2K;
118118
params.fps = sl_oc::video::FPS::FPS_15;
119119
params.verbose = verbose;
120120
// <---- Set Video parameters
@@ -146,12 +146,14 @@ int main(int argc, char *argv[])
146146
updateAllCtrlValues(cap);
147147

148148
uint64_t last_ts=0;
149+
uint16_t not_a_new_frame = 0;
150+
int frame_timeout_msec = 100;
149151

150152
// Infinite video grabbing loop
151153
while (1)
152154
{
153155
// 3) Get last available frame
154-
const sl_oc::video::Frame frame = cap.getLastFrame();
156+
const sl_oc::video::Frame frame = cap.getLastFrame(frame_timeout_msec);
155157
img_w = frame.width;
156158
img_h = frame.height;
157159

@@ -178,6 +180,7 @@ int main(int argc, char *argv[])
178180
// ----> If the frame is valid we can display it
179181
if(frame.data!=nullptr && frame.timestamp!=last_ts)
180182
{
183+
not_a_new_frame=0;
181184
#if 0
182185
// ----> Video Debug information
183186

@@ -201,6 +204,17 @@ int main(int argc, char *argv[])
201204
// 4.c) Show frame
202205
showImage( win_name, frameBGR, params.res );
203206
}
207+
else if(frame.timestamp==last_ts)
208+
{
209+
not_a_new_frame++;
210+
std::cout << "Not a new frame #" << not_a_new_frame << std::endl;
211+
212+
if( not_a_new_frame>=(3000/frame_timeout_msec)) // Lost connection for 5 seconds
213+
{
214+
std::cout << "Camera connection lost. Closing..." << std::endl;
215+
break;
216+
}
217+
}
204218
// <---- If the frame is valid we can display it
205219

206220
// ----> Keyboard handling

src/videocapture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ bool VideoCapture::openCamera( uint8_t devId )
390390
if(mParams.verbose)
391391
{
392392
std::string msg = std::string("Cannot open '") + mDevName + "': ["
393-
+ std::to_string(errno) +std::string("] ") + std::string(strerror(errno));
393+
+ std::to_string(errno) + std::string("] ") + std::string(strerror(errno));
394394
ERROR_OUT(mParams.verbose,msg);
395395
}
396396

0 commit comments

Comments
 (0)