ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Functions
zed_oc_video_reg_log.cpp File Reference

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file zed_oc_video_reg_log.cpp.

36 {
37  // ----> Create Video Capture
41 
43  if( !cap.initializeVideo() )
44  {
45  std::cerr << "Cannot open camera video capture" << std::endl;
46  std::cerr << "See verbosity level for more details." << std::endl;
47 
48  return EXIT_FAILURE;
49  }
50  std::cout << "Connected to camera sn: " << cap.getSerialNumber() << std::endl;
51  // <---- Create Video Capture
52 
53 #ifdef TEST_FPS
54  // Timestamp to check FPS
55  double lastTime = static_cast<double>(getSteadyTimestamp())/1e9;
56  // Frame timestamp to check FPS
57  uint64_t lastFrameTs = 0;
58 #endif
59 
60  // Enable AGC/AEG registers logging
61  cap.enableAecAgcSensLogging(false);
62 
63  uint64_t last_ts=0;
64  uint16_t not_a_new_frame = 0;
65  int frame_timeout_msec = 100;
66 
67  int f_count = 0;
68  // Infinite video grabbing loop
69  while (1)
70  {
71  // Get last available frame
72  const sl_oc::video::Frame frame = cap.getLastFrame(frame_timeout_msec);
73 
74  // ----> If the frame is valid we can display it
75  if(frame.data!=nullptr && frame.timestamp!=last_ts)
76  {
77  last_ts = frame.timestamp;
78  not_a_new_frame=0;
79 #ifdef TEST_FPS
80  if(lastFrameTs!=0)
81  {
82  // ----> System time
83  double now = static_cast<double>(getSteadyTimestamp())/1e9;
84  double elapsed_sec = now - lastTime;
85  lastTime = now;
86  std::cout << "[System] Frame period: " << elapsed_sec << "sec - Freq: " << 1./elapsed_sec << " Hz" << std::endl;
87  // <---- System time
88 
89  // ----> Frame time
90  double frame_dT = static_cast<double>(frame.timestamp-lastFrameTs)/1e9;
91  std::cout << "[Camera] Frame period: " << frame_dT << "sec - Freq: " << 1./frame_dT << " Hz" << std::endl;
92  // <---- Frame time
93  }
94  lastFrameTs = frame.timestamp;
95 #endif
96 
97 
98 
99  if (f_count%10==0)
100  {
101  /* cap.
102  cap.saveAllISPRegisters("ov580_lr_"+std::to_string(f_count)+".csv");
103  cap.saveAllSensorsRegisters("ov4689_lr_"+std::to_string(f_count)+".csv");
104  std::cout<<" Save Data for f_count "<<f_count<<std::endl;*/
105  if (f_count%20==0)
106  cap.setColorBars(0,true);
107  else
108  cap.setColorBars(0,false);
109  }
110 
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 
119 
120  // ----> Conversion from YUV 4:2:2 to BGR for visualization
121  cv::Mat frameYUV = cv::Mat( frame.height, frame.width, CV_8UC2, frame.data );
122  cv::Mat frameBGR;
123  cv::cvtColor(frameYUV,frameBGR,cv::COLOR_YUV2BGR_YUYV);
124  // <---- Conversion from YUV 4:2:2 to BGR for visualization
125 
126  f_count++;
127  // Show frame
128  showImage( "Stream RGB", frameBGR, params.res );
129  }
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  }
145  // <---- If the frame is valid we can display it
146 
147  // ----> Keyboard handling
148  int key = cv::waitKey( 5 );
149  if(key=='q' || key=='Q') // Quit
150  break;
151  // <---- Keyboard handling
152  }
153 
154  // Disable AGC/AEG registers logging
155  cap.enableAecAgcSensLogging(true);
156 
157  return EXIT_SUCCESS;
158 }
The VideoCapture class provides image grabbing functions and settings control for all the Stereolabs ...
uint64_t getSteadyTimestamp()
Get the current system clock as steady clock, so with no jumps even if the system time changes.
Definition: defines.hpp:63
void showImage(std::string name, cv::UMat &img, sl_oc::video::RESOLUTION res, bool change_name=true, std::string info="")
Rescale the OpenCV T-API images [cv::UMat] according to the selected resolution to better display the...
Definition: ocv_display.hpp:27
@ FPS_60
60 Frames per second. Not available for RESOLUTION::HD2K and RESOLUTION::HD1080.
The Frame struct containing the acquired video frames.
uint64_t timestamp
Timestamp in nanoseconds.
uint16_t height
Frame height.
uint16_t width
Frame width.
uint8_t * data
Frame data in YUV 4:2:2 format.
The camera configuration parameters.
RESOLUTION res
Camera resolution.
FPS fps
Frames per second.
cv::Mat frameBGR
sl_oc::video::VideoParams params
cv::Mat frameYUV

References sl_oc::video::Frame::data, sl_oc::video::VideoCapture::enableAecAgcSensLogging(), sl_oc::video::VideoParams::fps, sl_oc::video::FPS_60, frameBGR, frameYUV, sl_oc::video::VideoCapture::getLastFrame(), sl_oc::video::VideoCapture::getSerialNumber(), getSteadyTimestamp(), sl_oc::video::HD720, sl_oc::video::Frame::height, sl_oc::video::VideoCapture::initializeVideo(), params, sl_oc::video::VideoParams::res, sl_oc::video::VideoCapture::saveAllISPRegisters(), sl_oc::video::VideoCapture::saveAllSensorsRegisters(), sl_oc::video::VideoCapture::setColorBars(), sl_oc::tools::showImage(), sl_oc::video::Frame::timestamp, and sl_oc::video::Frame::width.