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),
65 const std::string & pathLeft,
66 const std::string & pathRight,
70 Camera(imageRate, localTransform),
73 rectifyImages_(rectifyImages),
88 Camera(imageRate, localTransform),
89 rectifyImages_(rectifyImages),
105 Camera(imageRate, localTransform),
106 rectifyImages_(rectifyImages),
108 usbDevice_(deviceLeft),
109 usbDevice2_(deviceRight),
112 rightGrayScale_(
true)
167 ULOGGER_ERROR(
"CameraStereoVideo: Failed to create a capture object!");
175 unsigned int guid = (
unsigned int)
capture_.get(CV_CAP_PROP_GUID);
176 if (guid != 0 && guid != 0xffffffff)
183 if(!calibrationFolder.empty() && !
cameraName_.empty())
187 UWARN(
"Missing calibration files for camera \"%s\" in \"%s\" folder, you should calibrate the camera!",
192 UINFO(
"Stereo parameters: fx=%f cx=%f cy=%f baseline=%f",
208 UWARN(
"Desired resolution of %dx%d is set but calibration has "
209 "been loaded with resolution %dx%d, using calibration resolution.",
216 bool resolutionSet =
false;
226 int actualWidth =
int(
capture_.get(CV_CAP_PROP_FRAME_WIDTH));
227 int actualHeight =
int(
capture_.get(CV_CAP_PROP_FRAME_HEIGHT));
232 UERROR(
"Calibration resolution (%dx%d) cannot be set to camera driver, "
233 "actual resolution is %dx%d. You would have to re-calibrate with one "
234 "supported format by your camera. "
235 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
236 "formats by your camera. For side-by-side format, you should set listed width/2.",
238 actualWidth/(
capture2_.isOpened()?1:2), actualHeight);
246 bool resolutionSet =
false;
248 resolutionSet = resolutionSet &&
capture_.set(CV_CAP_PROP_FRAME_HEIGHT,
_height);
251 resolutionSet = resolutionSet &&
capture2_.set(CV_CAP_PROP_FRAME_WIDTH,
_width);
252 resolutionSet = resolutionSet &&
capture2_.set(CV_CAP_PROP_FRAME_HEIGHT,
_height);
256 int actualWidth =
int(
capture_.get(CV_CAP_PROP_FRAME_WIDTH));
257 int actualHeight =
int(
capture_.get(CV_CAP_PROP_FRAME_HEIGHT));
262 UWARN(
"Desired resolution (%dx%d) cannot be set to camera driver, "
263 "actual resolution is %dx%d. "
264 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
265 "formats by your camera. For side-by-side format, you should set listed width/2.",
267 actualWidth/(
capture2_.isOpened()?1:2), actualHeight);
275 bool fpsSupported =
false;
284 double actualFPS =
capture_.get(cv::CAP_PROP_FPS);
292 UWARN(
"Desired FPS (%f Hz) cannot be set to camera driver, "
293 "actual FPS is %f Hz. We will throttle to lowest FPS. "
294 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
295 "formats by your camera.",
311 int fourcc = cv::VideoWriter::fourcc(fourccUpperCase.at(0), fourccUpperCase.at(1), fourccUpperCase.at(2), fourccUpperCase.at(3));
312 bool fourccSupported =
false;
313 fourccSupported =
capture_.set(CV_CAP_PROP_FOURCC, fourcc);
316 fourccSupported = fourccSupported &&
capture2_.set(CV_CAP_PROP_FOURCC, fourcc);
320 int actualFourcc =
int(
capture_.get(CV_CAP_PROP_FOURCC));
322 if(!fourccSupported || actualFourcc != fourcc)
324 UWARN(
"Camera doesn't support provided FOURCC \"%s\". "
325 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
326 "formats by your camera.", fourccUpperCase.c_str());
331 UERROR(
"FOURCC parameter should be 4 characters, current value is \"%s\"",
_fourcc.c_str());
338 UERROR(
"Parameter \"rectifyImages\" is set, but no stereo model is loaded or valid.");
370 leftImage = cv::Mat(
img, cv::Rect( 0, 0,
img.size().width/2,
img.size().height ));
371 rightImage = cv::Mat(
img, cv::Rect(
img.size().width/2, 0,
img.size().width/2,
img.size().height ));
377 else if(leftImage.cols != rightImage.cols || leftImage.rows != rightImage.rows)
379 UERROR(
"Left and right streams don't have image of the same size: left=%dx%d right=%dx%d",
380 leftImage.cols, leftImage.rows, rightImage.cols, rightImage.rows);
385 bool rightCvt =
false;
389 cv::cvtColor(rightImage, tmp, CV_BGR2GRAY);
401 leftImage = leftImage.clone();
404 rightImage = rightImage.clone();
417 ULOGGER_WARN(
"The camera must be initialized before requesting an image.");