31 #include <opencv2/imgproc/types_c.h>
32 #if CV_MAJOR_VERSION > 3
33 #include <opencv2/videoio/videoio_c.h>
34 #if CV_MAJOR_VERSION > 4
35 #include <opencv2/videoio/legacy/constants_c.h>
48 const std::string & path,
52 Camera(imageRate, localTransform),
54 rectifyImages_(rectifyImages),
64 const std::string & pathLeft,
65 const std::string & pathRight,
69 Camera(imageRate, localTransform),
72 rectifyImages_(rectifyImages),
86 Camera(imageRate, localTransform),
87 rectifyImages_(rectifyImages),
102 Camera(imageRate, localTransform),
103 rectifyImages_(rectifyImages),
105 usbDevice_(deviceLeft),
106 usbDevice2_(deviceRight),
163 ULOGGER_ERROR(
"CameraStereoVideo: Failed to create a capture object!");
171 unsigned int guid = (
unsigned int)
capture_.get(CV_CAP_PROP_GUID);
172 if (guid != 0 && guid != 0xffffffff)
179 if(!calibrationFolder.empty() && !
cameraName_.empty())
183 UWARN(
"Missing calibration files for camera \"%s\" in \"%s\" folder, you should calibrate the camera!",
188 UINFO(
"Stereo parameters: fx=%f cx=%f cy=%f baseline=%f",
204 UWARN(
"Desired resolution of %dx%d is set but calibration has "
205 "been loaded with resolution %dx%d, using calibration resolution.",
212 bool resolutionSet =
false;
222 int actualWidth =
int(
capture_.get(CV_CAP_PROP_FRAME_WIDTH));
223 int actualHeight =
int(
capture_.get(CV_CAP_PROP_FRAME_HEIGHT));
228 UERROR(
"Calibration resolution (%dx%d) cannot be set to camera driver, "
229 "actual resolution is %dx%d. You would have to re-calibrate with one "
230 "supported format by your camera. "
231 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
232 "formats by your camera. For side-by-side format, you should set listed width/2.",
234 actualWidth/(
capture2_.isOpened()?1:2), actualHeight);
242 bool resolutionSet =
false;
244 resolutionSet = resolutionSet &&
capture_.set(CV_CAP_PROP_FRAME_HEIGHT,
_height);
247 resolutionSet = resolutionSet &&
capture2_.set(CV_CAP_PROP_FRAME_WIDTH,
_width);
248 resolutionSet = resolutionSet &&
capture2_.set(CV_CAP_PROP_FRAME_HEIGHT,
_height);
252 int actualWidth =
int(
capture_.get(CV_CAP_PROP_FRAME_WIDTH));
253 int actualHeight =
int(
capture_.get(CV_CAP_PROP_FRAME_HEIGHT));
258 UWARN(
"Desired resolution (%dx%d) cannot be set to camera driver, "
259 "actual resolution is %dx%d. "
260 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
261 "formats by your camera. For side-by-side format, you should set listed width/2.",
263 actualWidth/(
capture2_.isOpened()?1:2), actualHeight);
271 bool fpsSupported =
false;
280 double actualFPS =
capture_.get(cv::CAP_PROP_FPS);
288 UWARN(
"Desired FPS (%f Hz) cannot be set to camera driver, "
289 "actual FPS is %f Hz. We will throttle to lowest FPS. "
290 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
291 "formats by your camera.",
307 int fourcc = cv::VideoWriter::fourcc(fourccUpperCase.at(0), fourccUpperCase.at(1), fourccUpperCase.at(2), fourccUpperCase.at(3));
308 bool fourccSupported =
false;
309 fourccSupported =
capture_.set(CV_CAP_PROP_FOURCC, fourcc);
312 fourccSupported = fourccSupported &&
capture2_.set(CV_CAP_PROP_FOURCC, fourcc);
316 int actualFourcc =
int(
capture_.get(CV_CAP_PROP_FOURCC));
318 if(!fourccSupported || actualFourcc != fourcc)
320 UWARN(
"Camera doesn't support provided FOURCC \"%s\". "
321 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
322 "formats by your camera.", fourccUpperCase.c_str());
327 UERROR(
"FOURCC parameter should be 4 characters, current value is \"%s\"",
_fourcc.c_str());
334 UERROR(
"Parameter \"rectifyImages\" is set, but no stereo model is loaded or valid.");
366 leftImage = cv::Mat(
img, cv::Rect( 0, 0,
img.size().width/2,
img.size().height ));
367 rightImage = cv::Mat(
img, cv::Rect(
img.size().width/2, 0,
img.size().width/2,
img.size().height ));
373 else if(leftImage.cols != rightImage.cols || leftImage.rows != rightImage.rows)
375 UERROR(
"Left and right streams don't have image of the same size: left=%dx%d right=%dx%d",
376 leftImage.cols, leftImage.rows, rightImage.cols, rightImage.rows);
381 bool rightCvt =
false;
382 if(rightImage.type() != CV_8UC1)
385 cv::cvtColor(rightImage, tmp, CV_BGR2GRAY);
397 leftImage = leftImage.clone();
400 rightImage = rightImage.clone();
413 ULOGGER_WARN(
"The camera must be initialized before requesting an image.");