@@ -39,7 +39,7 @@ using namespace std;
3939using namespace sl ;
4040
4141// Sample functions
42- void updateCameraSettings (char key, sl::Camera &zed);
42+ void updateCameraSettings (char key, sl::Camera &zed, InitParameters &init_params );
4343void switchCameraSettings ();
4444void printHelp ();
4545void print (string msg_prefix, ERROR_CODE err_code = ERROR_CODE::SUCCESS, string msg_suffix = " " );
@@ -58,26 +58,26 @@ cv::Point origin_rect;
5858
5959static void onMouse (int event, int x, int y, int , void *) {
6060 switch (event) {
61- case cv::EVENT_LBUTTONDOWN:
62- {
63- origin_rect = cv::Point (x, y);
64- selectInProgress = true ;
65- break ;
66- }
61+ case cv::EVENT_LBUTTONDOWN:
62+ {
63+ origin_rect = cv::Point (x, y);
64+ selectInProgress = true ;
65+ break ;
66+ }
6767
68- case cv::EVENT_LBUTTONUP:
69- {
70- selectInProgress = false ;
71- break ;
72- }
68+ case cv::EVENT_LBUTTONUP:
69+ {
70+ selectInProgress = false ;
71+ break ;
72+ }
7373
74- case cv::EVENT_RBUTTONDOWN:
75- {
76- // Reset selection
77- selectInProgress = false ;
78- selection_rect = sl::Rect (0 , 0 , 0 , 0 );
79- break ;
80- }
74+ case cv::EVENT_RBUTTONDOWN:
75+ {
76+ // Reset selection
77+ selectInProgress = false ;
78+ selection_rect = sl::Rect (0 , 0 , 0 , 0 );
79+ break ;
80+ }
8181 }
8282
8383 if (selectInProgress) {
@@ -88,6 +88,9 @@ static void onMouse(int event, int x, int y, int, void*) {
8888 }
8989}
9090
91+
92+ bool must_grab = true ;
93+
9194int main (int argc, char **argv) {
9295
9396 // Create a ZED Camera object
@@ -97,7 +100,7 @@ int main(int argc, char **argv) {
97100 init_parameters.sdk_verbose = true ;
98101 init_parameters.camera_resolution = sl::RESOLUTION::AUTO;
99102 init_parameters.depth_mode = sl::DEPTH_MODE::NONE; // no depth computation required here
100- init_parameters.async_grab_camera_recovery = true ;
103+ init_parameters.async_grab_camera_recovery = false ;
101104 init_parameters.enable_image_validity_check = 1 ;
102105 parseArgs (argc, argv, init_parameters);
103106
@@ -135,6 +138,9 @@ int main(int argc, char **argv) {
135138 char key = ' ' ;
136139 while (key != ' q' ) {
137140 // Check that a new image is successfully acquired
141+ if (!must_grab)
142+ continue ;
143+
138144 returned_state = zed.grab ();
139145
140146 if (returned_state == ERROR_CODE::CORRUPTED_FRAME) {
@@ -146,10 +152,8 @@ int main(int argc, char **argv) {
146152 if (health.low_depth_reliability ) std::cout << " Low depth reliability - " ;
147153 if (health.low_motion_sensors_reliability ) std::cout << " Low motion sensors reliability - " ;
148154 std::cout << std::endl;
149- } else if (returned_state != ERROR_CODE::SUCCESS)
150- std::cout << " returned_state " << returned_state << std::endl;
151- int current_value = 10 ;
152- zed.getCameraSettings (VIDEO_SETTINGS::EXPOSURE, current_value);
155+ }
156+
153157 if (returned_state <= ERROR_CODE::SUCCESS) {
154158 // Retrieve left image
155159 zed.retrieveImage (zed_image, VIEW::SIDE_BY_SIDE);
@@ -171,7 +175,7 @@ int main(int argc, char **argv) {
171175
172176 key = cv::waitKey (10 );
173177 // Change camera settings with keyboard
174- updateCameraSettings (key, zed);
178+ updateCameraSettings (key, zed,init_parameters );
175179 }
176180
177181 // Exit
@@ -182,61 +186,71 @@ int main(int argc, char **argv) {
182186/* *
183187 This function updates camera settings
184188 **/
185- void updateCameraSettings (char key, sl::Camera &zed) {
189+ void updateCameraSettings (char key, sl::Camera &zed, sl::InitParameters& init_params ) {
186190 int current_value;
187191
188192 // Keyboard shortcuts
189193 switch (key) {
190194
191- // Switch to the next camera parameter
192- case ' s' :
193- switchCameraSettings ();
194- zed.getCameraSettings (camera_settings_, current_value);
195- std::cout << " Current Value : " << current_value << std::endl;
196- break ;
197-
198- // Increase camera settings value ('+' key)
199- case ' +' :
200- zed.getCameraSettings (camera_settings_, current_value);
201- zed.setCameraSettings (camera_settings_, current_value + step_camera_setting);
202- zed.getCameraSettings (camera_settings_, current_value);
203- print (str_camera_settings + " : " + std::to_string (current_value));
204- break ;
205-
206- // Decrease camera settings value ('-' key)
207- case ' -' :
208- zed.getCameraSettings (camera_settings_, current_value);
209- current_value = current_value > 0 ? current_value - step_camera_setting : 0 ; // take care of the 'default' value parameter: VIDEO_SETTINGS_VALUE_AUTO
210- zed.setCameraSettings (camera_settings_, current_value);
211- zed.getCameraSettings (camera_settings_, current_value);
212- print (str_camera_settings + " : " + std::to_string (current_value));
213- break ;
214-
215- // switch LED On :
216- case ' l' :
217- led_on = !led_on;
218- zed.setCameraSettings (sl::VIDEO_SETTINGS::LED_STATUS, led_on);
219- break ;
220-
221- // Reset to default parameters
222- case ' r' :
223- print (" Reset all settings to default\n " );
224- for (int s = (int ) VIDEO_SETTINGS::BRIGHTNESS; s <= (int ) VIDEO_SETTINGS::WHITEBALANCE_TEMPERATURE; s++)
225- zed.setCameraSettings (static_cast <VIDEO_SETTINGS> (s), sl::VIDEO_SETTINGS_VALUE_AUTO);
226- break ;
227-
228- case ' a' :
229- {
230- cout << " [Sample] set AEC_AGC_ROI on target [" << selection_rect.x << " ," << selection_rect.y << " ," << selection_rect.width << " ," << selection_rect.height << " ]\n " ;
231- zed.setCameraSettings (VIDEO_SETTINGS::AEC_AGC_ROI, selection_rect, sl::SIDE::BOTH);
232- }
233- break ;
234-
235- case ' f' :
236- print (" reset AEC_AGC_ROI to full res" );
237- zed.setCameraSettings (VIDEO_SETTINGS::AEC_AGC_ROI, selection_rect, sl::SIDE::BOTH, true );
238- break ;
239-
195+ // Switch to the next camera parameter
196+ case ' s' :
197+ switchCameraSettings ();
198+ zed.getCameraSettings (camera_settings_, current_value);
199+ std::cout << " Current Value : " << current_value << std::endl;
200+ break ;
201+
202+ // Increase camera settings value ('+' key)
203+ case ' +' :
204+ zed.getCameraSettings (camera_settings_, current_value);
205+ zed.setCameraSettings (camera_settings_, current_value + step_camera_setting);
206+ zed.getCameraSettings (camera_settings_, current_value);
207+ print (str_camera_settings + " : " + std::to_string (current_value));
208+ break ;
209+
210+ // Decrease camera settings value ('-' key)
211+ case ' -' :
212+ zed.getCameraSettings (camera_settings_, current_value);
213+ current_value = current_value > 0 ? current_value - step_camera_setting : 0 ; // take care of the 'default' value parameter: VIDEO_SETTINGS_VALUE_AUTO
214+ zed.setCameraSettings (camera_settings_, current_value);
215+ zed.getCameraSettings (camera_settings_, current_value);
216+ print (str_camera_settings + " : " + std::to_string (current_value));
217+ break ;
218+
219+ // switch LED On :
220+ case ' l' :
221+ led_on = !led_on;
222+ zed.setCameraSettings (sl::VIDEO_SETTINGS::LED_STATUS, led_on);
223+ break ;
224+
225+ // Reset to default parameters
226+ case ' r' :
227+ print (" Reset all settings to default\n " );
228+ for (int s = (int ) VIDEO_SETTINGS::BRIGHTNESS; s <= (int ) VIDEO_SETTINGS::WHITEBALANCE_TEMPERATURE; s++)
229+ zed.setCameraSettings (static_cast <VIDEO_SETTINGS> (s), sl::VIDEO_SETTINGS_VALUE_AUTO);
230+ break ;
231+
232+ case ' a' :
233+ {
234+ cout << " [Sample] set AEC_AGC_ROI on target [" << selection_rect.x << " ," << selection_rect.y << " ," << selection_rect.width << " ," << selection_rect.height << " ]\n " ;
235+ zed.setCameraSettings (VIDEO_SETTINGS::AEC_AGC_ROI, selection_rect, sl::SIDE::BOTH);
236+ }
237+ break ;
238+
239+ case ' f' :
240+ print (" reset AEC_AGC_ROI to full res" );
241+ zed.setCameraSettings (VIDEO_SETTINGS::AEC_AGC_ROI, selection_rect, sl::SIDE::BOTH, true );
242+ break ;
243+
244+ case ' b' :
245+ must_grab =false ;
246+ sl::sleep_ms (100 ); // / Wait 100ms to make sure no grab is performed
247+ zed.close (); // / Make sure that the camera is closed before rebooting it.
248+ sl::Camera::reboot (0 ); // / Reboot the first camera found. This is similar to unplug/plug the camera
249+ sl::sleep_ms (3000 ); // / Sleep for 3 scs for making sure the camera is available
250+ std::cout<<" Rebooting camera" <<std::endl;
251+ sl::ERROR_CODE err_ = zed.open (init_params);
252+ must_grab = true ;
253+ break ;
240254 }
241255}
242256
@@ -274,6 +288,7 @@ void printHelp() {
274288 cout << " * Toggle camera LED: 'l' (lower L)\n " ;
275289 cout << " * Reset all parameters: 'r'\n " ;
276290 cout << " * Reset exposure ROI to full image 'f'\n " ;
291+ cout << " * Reboot camera while in use: 'b'\n " ;
277292 cout << " * Use mouse to select an image area to apply exposure (press 'a')\n " ;
278293 cout << " * Exit : 'q'\n\n " ;
279294}
0 commit comments