31 #include <opencv2/opencv.hpp>
50 int main(
int argc,
char *argv[])
74 std::cerr <<
"Cannot open camera video capture" << std::endl;
75 std::cerr <<
"Try to enable verbose to get more info" << std::endl;
83 std::cout <<
"Video Capture connected to camera sn: " << camSn << std::endl;
90 std::cerr <<
"Cannot open sensors capture" << std::endl;
91 std::cerr <<
"Try to enable verbose to get more info" << std::endl;
95 std::cout <<
"Sensors Capture connected to camera sn: " << sensCap.
getSerialNumber() << std::endl;
110 cv::Size display_resolution(1024, 576);
116 display_resolution.width = w;
117 display_resolution.height = h;
120 display_resolution.width = w*0.6;
121 display_resolution.height = h*0.6;
125 display_resolution.width = w*0.4;
126 display_resolution.height = h*0.4;
131 cv::Mat frameDisplay(display_resolution.height + h_data, display_resolution.width,CV_8UC3, cv::Scalar(0,0,0));
132 cv::Mat frameData = frameDisplay(cv::Rect(0,0, display_resolution.width, h_data));
133 cv::Mat frameBGRDisplay = frameDisplay(cv::Rect(0,h_data, display_resolution.width, display_resolution.height));
134 cv::Mat
frameBGR(h, w, CV_8UC3, cv::Scalar(0,0,0));
137 uint64_t last_timestamp = 0;
149 std::stringstream videoTs;
152 frame_fps = 1e9/
static_cast<float>(frame.
timestamp-last_timestamp);
163 videoTs << std::fixed << std::setprecision(9) <<
"Video timestamp: " <<
static_cast<double>(last_timestamp)/1e9<<
" sec" ;
164 if( last_timestamp!=0 )
165 videoTs << std::fixed << std::setprecision(1) <<
" [" << frame_fps <<
" Hz]";
169 if(frame.
data!=
nullptr)
174 cv::putText( frameData, videoTs.str(), cv::Point(10,20),cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(241,240,236));
178 cv::putText( frameData,
imuTsStr, cv::Point(10, 35),cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(241,240,236));
181 std::stringstream offsetStr;
183 offsetStr << std::fixed << std::setprecision(9) << std::showpos <<
"Timestamp offset: " << offset <<
" sec [video-sensors]";
184 cv::putText( frameData, offsetStr.str().c_str(), cv::Point(10, 50),cv::FONT_HERSHEY_SIMPLEX, 0.35, cv::Scalar(241,240,236));
193 double avg_offset=sum/(++count);
195 std::stringstream avgOffsetStr;
196 avgOffsetStr << std::fixed << std::setprecision(9) << std::showpos <<
"Avg timestamp offset: " << avg_offset <<
" sec";
197 cv::putText( frameData, avgOffsetStr.str().c_str(), cv::Point(10,62),cv::FONT_HERSHEY_SIMPLEX,0.35, cv::Scalar(241, 240,236));
201 cv::putText( frameData,
"Inertial sensor data:", cv::Point(display_resolution.width/2,20),cv::FONT_HERSHEY_SIMPLEX, 0.6, cv::Scalar(241, 240,236));
202 cv::putText( frameData,
imuAccelStr, cv::Point(display_resolution.width/2+15,42),cv::FONT_HERSHEY_SIMPLEX, 0.6, cv::Scalar(241, 240,236));
203 cv::putText( frameData,
imuGyroStr, cv::Point(display_resolution.width/2+15, 62),cv::FONT_HERSHEY_SIMPLEX, 0.6, cv::Scalar(241, 240,236));
207 cv::resize(
frameBGR, frameBGRDisplay, display_resolution);
209 cv::imshow(
"Stream RGB", frameDisplay);
214 int key = cv::waitKey(1);
219 if(key==
'q' || key==
'Q'|| key==27)
239 uint64_t last_imu_ts = 0;
251 std::stringstream timestamp;
252 std::stringstream accel;
253 std::stringstream gyro;
255 timestamp << std::fixed << std::setprecision(9) <<
"IMU timestamp: " <<
static_cast<double>(imuData.
timestamp)/1e9<<
" sec" ;
257 timestamp << std::fixed << std::setprecision(1) <<
" [" << 1e9/
static_cast<float>(imuData.
timestamp-last_imu_ts) <<
" Hz]";
260 accel << std::fixed << std::showpos << std::setprecision(4) <<
" * Accel: " << imuData.
aX <<
" " << imuData.
aY <<
" " << imuData.
aZ <<
" [m/s^2]";
261 gyro << std::fixed << std::showpos << std::setprecision(4) <<
" * Gyro: " << imuData.
gX <<
" " << imuData.
gY <<
" " << imuData.
gZ <<
" [deg/s]";
The SensorCapture class provides sensor grabbing functions for the Stereolabs ZED Mini and ZED2 camer...
int getSerialNumber()
Retrieve the serial number of the connected camera.
bool initializeSensors(int sn=-1)
Open a connection to the MCU of a ZED Mini or a ZED2 camera using the specified serial number or sear...
const data::Imu & getLastIMUData(uint64_t timeout_usec=1500)
Get the last received IMU data.
The VideoCapture class provides image grabbing functions and settings control for all the Stereolabs ...
const Frame & getLastFrame(uint64_t timeout_msec=100)
Get the last received camera image.
void getFrameSize(int &width, int &height)
Get the size of the camera frame.
bool initializeVideo(int devId=-1)
Open a ZED camera using the specified ID or searching for the first available.
bool enableSensorSync(sensors::SensorCapture *sensCap=nullptr)
Enable synchronizations between Camera frame and Sensors timestamps.
int getSerialNumber()
Retrieve the serial number of the connected camera.
@ FPS_30
30 Frames per second. Not available for RESOLUTION::HD2K.
Contains the acquired Imu data.
float gX
Angular velocity around X axis in °/s.
float aX
Acceleration along X axis in m/s²
ImuStatus valid
Indicates if IMU data are valid.
uint64_t timestamp
Timestamp in nanoseconds.
bool sync
Indicates in IMU data are synchronized with a video frame.
float gZ
Angular velocity around > axis in °/s.
float gY
Angular velocity around Y axis in °/s.
float aY
Acceleration along Y axis in m/s²
float aZ
Acceleration along Z axis in m/s²
The Frame struct containing the acquired video frames.
uint64_t timestamp
Timestamp in nanoseconds.
uint16_t height
Frame height.
uint64_t frame_id
Increasing index of frames.
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.
int main(int argc, char *argv[])
void getSensorThreadFunc(sl_oc::sensors::SensorCapture *sensCap)
sl_oc::video::VideoParams params