Skip to content

Commit c574b54

Browse files
committed
Fix merge
2 parents ccc926a + a98a856 commit c574b54

10 files changed

+179
-67
lines changed

CMakeLists.txt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ endif()
3030
option(BUILD_VIDEO "Build the ZED Open Capture Video Modules (only for Linux)" ON)
3131
option(BUILD_SENSORS "Build the ZED Open Capture Sensors Modules" ON)
3232
option(BUILD_EXAMPLES "Build the ZED Open Capture examples" ON)
33+
option(DEBUG_CAM_REG "Add functions to log the values of the registers of camera" OFF)
3334

3435
############################################################################
3536
# Sources
@@ -72,6 +73,11 @@ list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake")
7273

7374
############################################################################
7475
# Generate libraries
76+
if(DEBUG_CAM_REG)
77+
message("* Registers logging available")
78+
add_definitions(-DSENSOR_LOG_AVAILABLE)
79+
endif()
80+
7581
if(BUILD_SENSORS)
7682
message("* Sensors module available")
7783
add_definitions(-DSENSORS_MOD_AVAILABLE)
@@ -162,16 +168,18 @@ if(BUILD_EXAMPLES)
162168
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
163169
)
164170

165-
##### Video with AEG/AGC reisters log
166-
add_executable(${PROJECT_NAME}_video_reg_log "${PROJECT_SOURCE_DIR}/examples/zed_oc_video_reg_log.cpp")
167-
set_target_properties(${PROJECT_NAME}_video_reg_log PROPERTIES PREFIX "")
168-
target_link_libraries(${PROJECT_NAME}_video_reg_log
169-
${PROJECT_NAME}
170-
${OpenCV_LIBS}
171-
)
172-
install(TARGETS ${PROJECT_NAME}_video_reg_log
173-
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
174-
)
171+
if(DEBUG_CAM_REG)
172+
##### Video with AEG/AGC reisters log
173+
add_executable(${PROJECT_NAME}_video_reg_log "${PROJECT_SOURCE_DIR}/examples/zed_oc_video_reg_log.cpp")
174+
set_target_properties(${PROJECT_NAME}_video_reg_log PROPERTIES PREFIX "")
175+
target_link_libraries(${PROJECT_NAME}_video_reg_log
176+
${PROJECT_NAME}
177+
${OpenCV_LIBS}
178+
)
179+
install(TARGETS ${PROJECT_NAME}_video_reg_log
180+
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
181+
)
182+
endif()
175183
endif()
176184

177185
if(BUILD_SENSORS)

examples/zed_oc_control_example.cpp

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ static void resetControls( sl_oc::video::VideoCapture &cap );
7878
// ----> Global variables
7979
cv::String win_name = "Stream RGB"; // Name of the stream window
8080
bool selectInProgress = false; // Indicates that an AECAGC ROI is being drawn
81+
bool selectLeft = false;
82+
bool selectRight = false;
8183
cv::Rect aecagc_roi_left = {0,0,0,0}; // The current agcaec ROI rectangle
8284
cv::Rect aecagc_roi_right = {0,0,0,0}; // The current agcaec ROI rectangle
8385
cv::Point origin_roi = {0,0}; // Click point for AECAGC ROI
@@ -101,7 +103,8 @@ uint8_t gamma_val;
101103
bool autoAECAGC=false;
102104
bool autoWB=false;
103105

104-
bool applyAECAGCrect=false;
106+
bool applyAECAGCrectLeft=false;
107+
bool applyAECAGCrectRight=false;
105108
// <---- Global variables
106109

107110
// The main function
@@ -143,30 +146,41 @@ int main(int argc, char *argv[])
143146
updateAllCtrlValues(cap);
144147

145148
uint64_t last_ts=0;
149+
uint16_t not_a_new_frame = 0;
150+
int frame_timeout_msec = 100;
146151

147152
// Infinite video grabbing loop
148153
while (1)
149154
{
150155
// 3) Get last available frame
151-
const sl_oc::video::Frame frame = cap.getLastFrame();
156+
const sl_oc::video::Frame frame = cap.getLastFrame(frame_timeout_msec);
152157
img_w = frame.width;
153158
img_h = frame.height;
154159

155160
// 3a) Apply AEC AGC ROI if necessary
156-
if(applyAECAGCrect)
161+
if(applyAECAGCrectLeft)
157162
{
158-
applyAECAGCrect = false;
163+
applyAECAGCrectLeft = false;
159164
cap.setROIforAECAGC( sl_oc::video::CAM_SENS_POS::LEFT,
160165
aecagc_roi_left.x, aecagc_roi_left.y,
161166
aecagc_roi_left.width, aecagc_roi_left.height);
167+
selectLeft=false;
168+
selectRight=false;
169+
}
170+
if(applyAECAGCrectRight)
171+
{
172+
applyAECAGCrectRight = false;
162173
cap.setROIforAECAGC( sl_oc::video::CAM_SENS_POS::RIGHT,
163-
aecagc_roi_right.x, aecagc_roi_left.y,
164-
aecagc_roi_left.width, aecagc_roi_left.height);
174+
aecagc_roi_right.x, aecagc_roi_right.y,
175+
aecagc_roi_right.width, aecagc_roi_right.height);
176+
selectLeft=false;
177+
selectRight=false;
165178
}
166179

167180
// ----> If the frame is valid we can display it
168181
if(frame.data!=nullptr && frame.timestamp!=last_ts)
169182
{
183+
not_a_new_frame=0;
170184
#if 0
171185
// ----> Video Debug information
172186

@@ -190,6 +204,17 @@ int main(int argc, char *argv[])
190204
// 4.c) Show frame
191205
showImage( win_name, frameBGR, params.res );
192206
}
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+
}
193218
// <---- If the frame is valid we can display it
194219

195220
// ----> Keyboard handling
@@ -220,10 +245,12 @@ void handleKeyboard( sl_oc::video::VideoCapture &cap, int key )
220245

221246
switch(key)
222247
{
248+
#ifdef SENSOR_LOG_AVAILABLE
223249
case 'L':
224250
{
225-
logging = cap.enableAecAgcSensLogging( !logging, 5 );
226-
std::cout << std::string("*** AEC/AGC registers loggin: ") << (logging?std::string("ENABLED"):std::string("DISABLED")) << std::endl;
251+
logging = !logging;
252+
cap.enableAecAgcSensLogging( logging, 5 );
253+
std::cout << std::string("*** AEC/AGC registers logging: ") << (logging?std::string("ENABLED"):std::string("DISABLED")) << std::endl;
227254
}
228255
break;
229256

@@ -234,6 +261,7 @@ void handleKeyboard( sl_oc::video::VideoCapture &cap, int key )
234261
std::cout << std::string("*** AEC/AGC registers reset: ") << (res?std::string("OK"):std::string("KO")) << std::endl;
235262
}
236263
break;
264+
#endif
237265

238266
case 'l':
239267
{
@@ -320,8 +348,10 @@ void handleKeyboard( sl_oc::video::VideoCapture &cap, int key )
320348
std::cout << " * '+' -> Increase the current control value" << std::endl;
321349
std::cout << " * '-' -> Decrease the current control value" << std::endl;
322350
std::cout << " * '0' .. '9' -> Set the current control value" << std::endl;
351+
#ifdef SENSOR_LOG_AVAILABLE
323352
std::cout << " * 'L' -> Toggle AGC/AEC registers logging" << std::endl;
324353
std::cout << " * 'f' -> Fix AGC/AEC registers" << std::endl;
354+
#endif
325355
}
326356
}
327357

@@ -372,7 +402,16 @@ void handleMouse(int event, int x, int y, int, void*)
372402

373403
if(autoAECAGC && (activeControl==Gain || activeControl==Exposure))
374404
{
375-
applyAECAGCrect = true;
405+
if(selectLeft)
406+
{
407+
selectLeft=false;
408+
applyAECAGCrectLeft = true;
409+
}
410+
if(selectRight)
411+
{
412+
selectRight=false;
413+
applyAECAGCrectRight = true;
414+
}
376415
}
377416
break;
378417
}
@@ -383,7 +422,8 @@ void handleMouse(int event, int x, int y, int, void*)
383422
selectInProgress = false;
384423
aecagc_roi_left = cv::Rect(0,0,img_w/2,img_h);
385424
aecagc_roi_right = cv::Rect(0,0,img_w/2,img_h);
386-
applyAECAGCrect = true;
425+
applyAECAGCrectLeft = true;
426+
applyAECAGCrectRight = true;
387427
break;
388428
}
389429
}
@@ -402,6 +442,7 @@ void handleMouse(int event, int x, int y, int, void*)
402442
{
403443
x = MAX(x,0);
404444
x = MIN(x,img_w/2-1);
445+
selectLeft = true;
405446

406447
aecagc_roi_left.x = MIN(x, or_x);
407448
aecagc_roi_left.y = MIN(y, or_y);
@@ -414,6 +455,7 @@ void handleMouse(int event, int x, int y, int, void*)
414455
x -= img_w/2;
415456
x = MAX(x,0);
416457
x = MIN(x,img_w/2-1);
458+
selectRight = true;
417459

418460
aecagc_roi_right.x = MIN(x, or_x);
419461
aecagc_roi_right.y = MIN(y, or_y);

examples/zed_oc_sync_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ uint64_t mcu_sync_ts=0;
5252
int main(int argc, char *argv[])
5353
{
5454
// Set the verbose level
55-
sl_oc::VERBOSITY verbose = sl_oc::VERBOSITY::ERROR;
55+
sl_oc::VERBOSITY verbose = sl_oc::VERBOSITY::INFO;
5656

5757
// ----> Set the video parameters
5858
sl_oc::video::VideoParams params;

examples/zed_oc_video_reg_log.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,22 @@ int main(int argc, char *argv[])
6060
// Enable AGC/AEG registers logging
6161
cap.enableAecAgcSensLogging(false);
6262

63+
uint64_t last_ts=0;
64+
uint16_t not_a_new_frame = 0;
65+
int frame_timeout_msec = 100;
66+
6367
int f_count = 0;
6468
// Infinite video grabbing loop
6569
while (1)
6670
{
6771
// Get last available frame
68-
const sl_oc::video::Frame frame = cap.getLastFrame();
72+
const sl_oc::video::Frame frame = cap.getLastFrame(frame_timeout_msec);
6973

7074
// ----> If the frame is valid we can display it
71-
if(frame.data!=nullptr)
75+
if(frame.data!=nullptr && frame.timestamp!=last_ts)
7276
{
77+
last_ts = frame.timestamp;
78+
not_a_new_frame=0;
7379
#ifdef TEST_FPS
7480
if(lastFrameTs!=0)
7581
{
@@ -89,6 +95,7 @@ int main(int argc, char *argv[])
8995
#endif
9096

9197

98+
9299
if (f_count%10==0)
93100
{
94101
/* cap.
@@ -101,6 +108,14 @@ int main(int argc, char *argv[])
101108
cap.setColorBars(0,false);
102109
}
103110

111+
// if (f_count!=0 && f_count%10==0)
112+
// {
113+
// cap.saveAllISPRegisters("ov580_lr_"+std::to_string(f_count)+".csv");
114+
// cap.saveAllSensorsRegisters("ov4689_lr_"+std::to_string(f_count)+".csv");
115+
// std::cout<<" Save Data for f_count "<<f_count<<std::endl;
116+
// }
117+
118+
104119

105120
// ----> Conversion from YUV 4:2:2 to BGR for visualization
106121
cv::Mat frameYUV = cv::Mat( frame.height, frame.width, CV_8UC2, frame.data );
@@ -112,6 +127,21 @@ int main(int argc, char *argv[])
112127
// Show frame
113128
cv::imshow( "Stream RGB", frameBGR );
114129
}
130+
else
131+
{
132+
not_a_new_frame++;
133+
std::cout << "Not a new frame #" << not_a_new_frame << std::endl;
134+
135+
if( not_a_new_frame>=(1000/frame_timeout_msec)) // Lost connection for 1 seconds
136+
{
137+
cap.saveAllISPRegisters("ov580_lr_"+std::to_string(f_count)+"_not_a_new _frame.csv");
138+
cap.saveAllSensorsRegisters("ov4689_lr_"+std::to_string(f_count)+"_not_a_new _frame.csv");
139+
std::cout<<" Save Data for f_count "<<f_count<<std::endl;
140+
141+
std::cout << "Camera connection lost. Closing..." << std::endl;
142+
break;
143+
}
144+
}
115145
// <---- If the frame is valid we can display it
116146

117147
// ----> Keyboard handling

include/defines.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ static const uint16_t SL_USB_PROD_ZED_M_REVA = 0xf680; //!< Old ZED-M bina
7777
static const uint16_t SL_USB_PROD_ZED_REVB = 0xf582; //!< CBS ZED Firmware Product ID
7878
static const uint16_t SL_USB_PROD_ZED_M_REVB = 0xf682; //!< CBS ZED-M Firmware Product ID
7979
static const uint16_t SL_USB_PROD_ZED_2_REVB = 0xf780; //!< CBS ZED 2 Firmware Product ID
80+
static const uint16_t SL_USB_PROD_ZED_2i = 0xf880; //!< CBS ZED 2i Firmware Product ID
8081
static const uint16_t SL_USB_PROD_MCU_ZEDM_REVA= 0xf681; //!< MCU sensor device for ZED-M
8182
static const uint16_t SL_USB_PROD_MCU_ZED2_REVA = 0xf781; //!< MCU sensor device for ZED2
83+
static const uint16_t SL_USB_PROD_MCU_ZED2i_REVA = 0xf881; //!< MCU sensor device for ZED2i
8284

8385
enum VERBOSITY {
8486
NONE = 0,

include/sensorcapture.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ class SL_OC_EXPORT SensorCapture
148148

149149
/*!
150150
* \brief Get the list of the serial number of all the available devices
151+
* \param refresh if true USB device tree is parsed to search for modifications (new device connected/disconnected)
151152
* \return a vector containing the serial number of all the available devices
152153
*/
153-
std::vector<int> getDeviceList();
154+
std::vector<int> getDeviceList(bool refresh=false);
154155

155156
/*!
156157
* \brief Open a connection to the MCU of a ZED Mini or a ZED2 camera using the specified serial number or searching
@@ -204,14 +205,16 @@ class SL_OC_EXPORT SensorCapture
204205
#ifdef VIDEO_MOD_AVAILABLE
205206
void updateTimestampOffset(uint64_t frame_ts); //!< Called by VideoCapture to update timestamp offset
206207
inline void setStartTimestamp(uint64_t start_ts){mStartSysTs=start_ts;} //!< Called by VideoCapture to sync timestamps reference point
207-
inline void setVideoPtr(video::VideoCapture* videoPtr){mVideoPtr=videoPtr;} //!< Called by VideoCapture to set the pointer to it
208+
inline void setVideoPtr(video::VideoCapture* videoPtr){mVideoPtr=videoPtr;} //!< Called by VideoCapture to set the pointer to it
208209
#endif
209210

210211
private:
211212
void grabThreadFunc(); //!< The sensor data grabbing thread function
212213

213214
bool startCapture(); //!< Start data capture thread
214-
void reset(); //!< Reset connection
215+
216+
bool open(uint16_t pid, int serial_number); //!< Open the USB connection
217+
void close(); //!< Close the USB connection
215218

216219
int enumerateDevices(); //!< Populates the mSlDevPid map with serial number and PID of the available devices
217220

include/videocapture.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ class SL_OC_EXPORT VideoCapture
340340
*/
341341
int getSerialNumber();
342342

343+
/*!
344+
* \brief Utils fct to set Color Bars on Image
345+
*/
346+
void setColorBars(int side, bool c);
347+
348+
#ifdef SENSOR_LOG_AVAILABLE
343349
/*!
344350
* \brief Start logging to file of AEG/AGC camera registers
345351
* \param enable set to true to enable logging
@@ -348,13 +354,6 @@ class SL_OC_EXPORT VideoCapture
348354
*/
349355
bool enableAecAgcSensLogging(bool enable, int frame_skip=10);
350356

351-
352-
353-
/*!
354-
* \brief Utils fct to set Color Bars on Image
355-
*/
356-
void setColorBars(int side, bool c);
357-
358357
/*!
359358
* \brief Save all ISP camera registers into a file
360359
* \param filename csv filename
@@ -368,6 +367,7 @@ class SL_OC_EXPORT VideoCapture
368367
* \note CSV file will contain Adress , L value, R value
369368
*/
370369
void saveAllSensorsRegisters(std::string filename);
370+
#endif
371371

372372

373373
#ifdef SENSORS_MOD_AVAILABLE
@@ -458,10 +458,10 @@ class SL_OC_EXPORT VideoCapture
458458
return std::string(buf);
459459
}
460460

461+
#ifdef SENSOR_LOG_AVAILABLE
461462
void saveLogDataLeft();
462463
void saveLogDataRight();
463-
464-
464+
#endif
465465

466466
private:
467467
// Flags
@@ -501,6 +501,7 @@ class SL_OC_EXPORT VideoCapture
501501

502502
bool mFirstFrame=true; //!< Used to initialize the timestamp start point
503503

504+
#ifdef SENSOR_LOG_AVAILABLE
504505
// ----> Registers logging
505506
bool mLogEnable=false;
506507
std::string mLogFilenameLeft;
@@ -509,6 +510,7 @@ class SL_OC_EXPORT VideoCapture
509510
std::ofstream mLogFileRight;
510511
int mLogFrameSkip=10;
511512
// <---- Registers logging
513+
#endif
512514

513515

514516
#ifdef SENSORS_MOD_AVAILABLE

0 commit comments

Comments
 (0)