31 #if CV_MAJOR_VERSION > 3
32 #include <opencv2/videoio/videoio_c.h>
33 #if CV_MAJOR_VERSION > 4
34 #include <opencv2/videoio/legacy/constants_c.h>
46 Camera(imageRate, localTransform),
47 _rectifyImages(rectifyImages),
49 _usbDevice(usbDevice),
57 const std::string & filePath,
61 Camera(imageRate, localTransform),
63 _rectifyImages(rectifyImages),
76 bool CameraVideo::init(
const std::string & calibrationFolder,
const std::string & cameraName)
108 unsigned int guid = (
unsigned int)
_capture.get(CV_CAP_PROP_GUID);
109 if (guid != 0 && guid != 0xffffffff)
116 if(!calibrationFolder.empty() && !
_guid.empty())
120 UWARN(
"Missing calibration files for camera \"%s\" in \"%s\" folder, you should calibrate the camera!",
121 _guid.c_str(), calibrationFolder.c_str());
125 UINFO(
"Camera parameters: fx=%f fy=%f cx=%f cy=%f",
139 UWARN(
"Desired resolution of %dx%d is set but calibration has "
140 "been loaded with resolution %dx%d, using calibration resolution.",
145 bool resolutionSet =
false;
150 int actualWidth =
int(
_capture.get(CV_CAP_PROP_FRAME_WIDTH));
151 int actualHeight =
int(
_capture.get(CV_CAP_PROP_FRAME_HEIGHT));
156 UERROR(
"Calibration resolution (%dx%d) cannot be set to camera driver, "
157 "actual resolution is %dx%d. You would have to re-calibrate with one "
158 "supported format by your camera. "
159 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
160 "formats by your camera.",
162 actualWidth, actualHeight);
167 int resolutionSet =
false;
169 resolutionSet = resolutionSet &&
_capture.set(CV_CAP_PROP_FRAME_HEIGHT,
_height);
172 int actualWidth =
int(
_capture.get(CV_CAP_PROP_FRAME_WIDTH));
173 int actualHeight =
int(
_capture.get(CV_CAP_PROP_FRAME_HEIGHT));
174 if(!resolutionSet || actualWidth !=
_width || actualHeight !=
_height)
176 UWARN(
"Desired resolution (%dx%d) cannot be set to camera driver, "
177 "actual resolution is %dx%d. "
178 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
179 "formats by your camera.",
188 double actualFPS =
_capture.get(cv::CAP_PROP_FPS);
196 UWARN(
"Desired FPS (%f Hz) cannot be set to camera driver, "
197 "actual FPS is %f Hz. We will throttle to lowest FPS. "
198 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
199 "formats by your camera.",
214 int fourcc = cv::VideoWriter::fourcc(fourccUpperCase.at(0), fourccUpperCase.at(1), fourccUpperCase.at(2), fourccUpperCase.at(3));
216 bool fourccSupported =
_capture.set(CV_CAP_PROP_FOURCC, fourcc);
219 int actualFourcc =
int(
_capture.get(CV_CAP_PROP_FOURCC));
221 if(!fourccSupported || actualFourcc != fourcc)
223 UWARN(
"Camera doesn't support provided FOURCC \"%s\". "
224 "Do \"v4l2-ctl --list-formats-ext\" to list all supported "
225 "formats by your camera.", fourccUpperCase.c_str());
230 UERROR(
"FOURCC parameter should be 4 characters, current value is \"%s\"",
_fourcc.c_str());
236 UERROR(
"Parameter \"rectifyImages\" is set, but no camera model is loaded or valid.");
277 UERROR(
"Camera has been disconnected!");
282 ULOGGER_WARN(
"The camera must be initialized before requesting an image.");