17 #include <opencv2/core/core.hpp>
18 #include <opencv2/imgproc/imgproc.hpp>
19 #include <opencv2/core/core_c.h>
27 struct timeval epochtime;
28 struct timespec vsTime;
30 gettimeofday(&epochtime,
nullptr);
31 clock_gettime(CLOCK_MONOTONIC, &vsTime);
33 double uptime = vsTime.tv_sec + vsTime.tv_nsec / 1000000000.0;
34 double epoch = epochtime.tv_sec + epochtime.tv_usec / 1000000.0;
35 return epoch - uptime;
41 if (config.
check(key)) {
48 #define NOT_PRESENT -1
49 int V4L_camera::convertYARP_to_V4L(
int feature)
53 return V4L2_CID_BRIGHTNESS;
56 return V4L2_CID_EXPOSURE;
58 return V4L2_CID_SHARPNESS;
62 return V4L2_CID_SATURATION;
64 return V4L2_CID_GAMMA;
68 return V4L2_CID_IRIS_ABSOLUTE;
122 use_exposure_absolute =
false;
132 configIntrins =
false;
136 pixel_fmt_leo = V4L2_PIX_FMT_SGRBG8;
146 int V4L_camera::convertV4L_to_YARP_format(
int format)
149 case V4L2_PIX_FMT_GREY:
151 case V4L2_PIX_FMT_Y16:
153 case V4L2_PIX_FMT_RGB24:
156 case V4L2_PIX_FMT_BGR24:
158 case V4L2_PIX_FMT_SGRBG8:
160 case V4L2_PIX_FMT_SBGGR8:
162 case V4L2_PIX_FMT_SBGGR16:
164 case V4L2_PIX_FMT_SGBRG8:
166 case V4L2_PIX_FMT_SRGGB8:
168 case V4L2_PIX_FMT_YUV420:
170 case V4L2_PIX_FMT_YUV444:
172 case V4L2_PIX_FMT_YYUV:
174 case V4L2_PIX_FMT_YUV411P:
180 void V4L_camera::populateConfigurations()
182 struct v4l2_fmtdesc fmt;
183 struct v4l2_frmsizeenum frmsize;
184 struct v4l2_frmivalenum frmival;
187 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
189 while (ioctl(param.
fd, VIDIOC_ENUM_FMT, &fmt) >= 0) {
190 memset(&frmsize, 0,
sizeof(v4l2_frmsizeenum));
191 frmsize.pixel_format = fmt.pixelformat;
193 frmsize.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
194 while (xioctl(param.
fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) {
195 if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
196 memset(&frmival, 0,
sizeof(v4l2_frmivalenum));
198 frmival.pixel_format = fmt.pixelformat;
199 frmival.width = frmsize.discrete.width;
200 frmival.height = frmsize.discrete.height;
201 frmsize.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
202 while (xioctl(param.
fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival) >= 0) {
205 c.
width = frmival.width;
206 c.
height = frmival.height;
207 c.
framerate = (1.0 * frmival.discrete.denominator) / frmival.discrete.numerator;
227 if (!fromConfig(config)) {
238 if (!S_ISCHR(st.st_mode)) {
244 param.
fd = v4l2_open(param.
deviceId.c_str(), O_RDWR | O_NONBLOCK, 0);
247 if (-1 == param.
fd) {
255 v4l2_close(param.
fd);
259 param.
fd = v4l2_open(param.
deviceId.c_str(), O_RDWR | O_NONBLOCK, 0);
262 if (-1 == param.
fd) {
271 enumerate_controls();
273 if (!check_V4L2_control(V4L2_CID_EXPOSURE)) {
274 use_exposure_absolute = check_V4L2_control(V4L2_CID_EXPOSURE_ABSOLUTE);
280 populateConfigurations();
288 if (!white_balance.
isNull()) {
329 bool res = deviceInit();
339 return configFx && configFy;
351 return configIntrins;
357 mirror = (ioctl(param.
fd, V4L2_CID_HFLIP) != 0);
363 int ret = ioctl(param.
fd, V4L2_CID_HFLIP, &mirror);
365 yCError(
USBCAMERA) <<
"V4L2_CID_HFLIP - Unable to mirror image-" << strerror(errno);
373 if (config.
check(
"verbose")) {
377 if (!config.
check(
"width")) {
384 if (!config.
check(
"height")) {
391 if (!config.
check(
"framerate")) {
398 if (!config.
check(
"d")) {
399 yCError(
USBCAMERA) <<
"No camera identifier was specified! (e.g. '--d /dev/video0' on Linux OS)";
406 if (!config.
check(
"camModel")) {
407 yCInfo(
USBCAMERA) <<
"No 'camModel' was specified, working with 'standard' uvc";
410 std::map<std::string, supported_cams>::iterator it = camMap.find(config.
find(
"camModel").
asString());
411 if (it != camMap.end()) {
417 for (it = camMap.begin(); it != camMap.end(); it++) {
426 yCDebug(
USBCAMERA) <<
"-------------------------------\nusbCamera: Using leopard camera!!";
427 bit_shift = config.
check(
"shift",
Value(bit_shift),
"right shift of <n> bits").asInt32();
428 bit_bayer = config.
check(
"bit_bayer",
Value(bit_bayer),
"uses <n> bits bayer conversion").asInt32();
431 pixel_fmt_leo = V4L2_PIX_FMT_SGRBG8;
435 pixel_fmt_leo = V4L2_PIX_FMT_SGRBG10;
439 pixel_fmt_leo = V4L2_PIX_FMT_SGRBG12;
443 yCError(
USBCAMERA) <<
"bayer conversion with " << bit_bayer <<
"not supported";
448 yCDebug(
USBCAMERA) << bit_shift <<
"bits of right shift applied to raw data";
453 if (config.
check(
"crop")) {
460 Value isDual = config.
check(
"dual",
Value(0),
"Is this a dual camera? Two cameras merged into a single frame");
470 if (!config.
check(
"pixelType")) {
481 param.
pixelType = convertV4L_to_YARP_format(param.
src_fmt.fmt.pix.pixelformat);
490 yCError(
USBCAMERA,
"no valid pixel format found!! This should not happen!!");
495 retM = Value::makeList(
"1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0");
496 configFx = config.
check(
"horizontalFov");
497 configFy = config.
check(
"verticalFov");
498 configPPx = config.
check(
"principalPointX");
499 configPPy = config.
check(
"principalPointY");
500 configRet = config.
check(
"rectificationMatrix");
501 configDistM = config.
check(
"distortionModel");
503 bt = config.
findGroup(
"cameraDistortionModelGroup");
509 "fields k1, k2, k3, t1, t2, name are required when using cameraDistortionModelGroup";
510 configIntrins =
false;
514 configIntrins =
true;
517 configIntrins =
false;
519 param.
horizontalFov = config.
check(
"horizontalFov",
Value(0.0),
"desired horizontal fov of test image").asFloat64();
520 param.
verticalFov = config.
check(
"verticalFov",
Value(0.0),
"desired vertical fov of test image").asFloat64();
521 if (config.
check(
"mirror")) {
524 "mirroring disabled by default")
531 param.
intrinsic.
put(
"focalLengthX", config.
check(
"focalLengthX",
Value(0.0),
"Horizontal component of the focal lenght").asFloat64());
532 param.
intrinsic.
put(
"focalLengthY", config.
check(
"focalLengthY",
Value(0.0),
"Vertical component of the focal lenght").asFloat64());
533 param.
intrinsic.
put(
"principalPointX", config.
check(
"principalPointX",
Value(0.0),
"X coordinate of the principal point").asFloat64());
534 param.
intrinsic.
put(
"principalPointY", config.
check(
"principalPointY",
Value(0.0),
"Y coordinate of the principal point").asFloat64());
535 param.
intrinsic.
put(
"rectificationMatrix", config.
check(
"rectificationMatrix", *retM,
"Matrix that describes the lens' distortion"));
536 param.
intrinsic.
put(
"distortionModel", config.
check(
"distortionModel",
Value(
""),
"Reference to group of parameters describing the distortion model of the camera").asString());
546 param.
intrinsic.
put(
"k1", bt.
check(
"k1",
Value(0.0),
"Radial distortion coefficient of the lens").asFloat64());
547 param.
intrinsic.
put(
"k2", bt.
check(
"k2",
Value(0.0),
"Radial distortion coefficient of the lens").asFloat64());
548 param.
intrinsic.
put(
"k3", bt.
check(
"k3",
Value(0.0),
"Radial distortion coefficient of the lens").asFloat64());
558 int V4L_camera::getfd()
563 bool V4L_camera::threadInit()
572 void V4L_camera::run()
574 if (full_FrameRead()) {
581 if ((timeElapsed = timeNow - timeStart) > 1.0f) {
582 yCInfo(
USBCAMERA,
"frames acquired %d in %f sec", frameCounter, timeElapsed);
588 void V4L_camera::threadRelease()
597 bool V4L_camera::deviceInit()
599 struct v4l2_capability cap;
600 struct v4l2_cropcap cropcap;
601 struct v4l2_crop crop;
602 struct v4l2_streamparm frameint;
605 if (-1 == xioctl(param.
fd, VIDIOC_QUERYCAP, &cap)) {
606 if (EINVAL == errno) {
616 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
625 if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
633 if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
646 cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
648 if (0 == xioctl(param.
fd, VIDIOC_CROPCAP, &cropcap)) {
649 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
650 crop.c = cropcap.defrect;
655 xioctl(param.
fd, VIDIOC_S_CROP, &crop);
661 _v4lconvert_data = v4lconvert_create(param.
fd);
662 if (_v4lconvert_data ==
nullptr) {
663 yCError(
USBCAMERA) <<
"Failed to initialize v4lconvert. Conversion to required format may not work";
682 param.
dst_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
685 param.
dst_fmt.fmt.pix.field = V4L2_FIELD_NONE;
688 if (v4lconvert_try_format(_v4lconvert_data, &(param.
dst_fmt), &(param.
src_fmt)) != 0) {
689 yCError(
USBCAMERA,
"v4lconvert_try_format -> Error is: %s", v4lconvert_get_error_message(_v4lconvert_data));
697 yCWarning(
USBCAMERA) <<
"Conversion from HW supported configuration into user requested format will require addictional step.\n"
698 <<
"Performance issue may arise.";
704 double inputFF = (double)param.
dst_fmt.fmt.pix.width / (
double)param.
dst_fmt.fmt.pix.height;
707 if (outputFF < inputFF) {
741 if (-1 == xioctl(param.
fd, VIDIOC_S_FMT, ¶m.
src_fmt)) {
747 if (param.
fps != -1) {
751 frameint.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
752 frameint.parm.capture.timeperframe.numerator = 1;
753 frameint.parm.capture.timeperframe.denominator = param.
fps;
754 if (-1 == xioctl(param.
fd, VIDIOC_S_PARM, &frameint)) {
782 readInit(param.
src_fmt.fmt.pix.sizeimage);
790 userptrInit(param.
src_fmt.fmt.pix.sizeimage);
802 bool V4L_camera::deviceUninit()
823 param.
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
824 param.
req.memory = V4L2_MEMORY_MMAP;
825 if (xioctl(param.
fd, VIDIOC_REQBUFS, ¶m.
req) < 0) {
826 yCError(
USBCAMERA,
"VIDIOC_REQBUFS - Failed to delete buffers: %s (errno %d)", strerror(errno), errno);
839 if (param.
buffers !=
nullptr) {
859 v4lconvert_destroy(_v4lconvert_data);
875 if (param.
fd != -1) {
879 if (-1 == v4l2_close(param.
fd)) {
965 int V4L_camera::xioctl(
int fd,
int request,
void* argp)
970 r = v4l2_ioctl(fd, request, argp);
971 }
while (-1 == r && EINTR == errno);
983 void V4L_camera::enumerate_menu()
991 if (0 == ioctl(param.
fd, VIDIOC_QUERYMENU, &
querymenu)) {
1001 bool V4L_camera::enumerate_controls()
1006 if (0 == ioctl(param.
fd, VIDIOC_QUERYCTRL, &
queryctrl)) {
1007 if (
queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
1013 if (
queryctrl.type == V4L2_CTRL_TYPE_MENU) {
1017 if (errno == EINVAL) {
1027 if (0 == ioctl(param.
fd, VIDIOC_QUERYCTRL, &
queryctrl)) {
1028 if (
queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
1034 if (
queryctrl.type == V4L2_CTRL_TYPE_MENU) {
1038 if (errno == EINVAL) {
1052 bool V4L_camera::full_FrameRead()
1054 bool got_it =
false;
1055 void* image_ret =
nullptr;
1057 unsigned int numberOfTimeouts;
1063 numberOfTimeouts = 0;
1067 for (
unsigned int i = 0; i < count; i++) {
1069 FD_SET(param.
fd, &fds);
1075 r = select(param.
fd + 1, &fds,
nullptr,
nullptr, &tv);
1078 if (EINTR == errno) {
1082 return image_ret !=
nullptr;
1087 yCWarning(
USBCAMERA,
"timeout while reading image [%d/%d]", numberOfTimeouts, count);
1090 }
else if ((r > 0) && (FD_ISSET(param.
fd, &fds))) {
1110 bool V4L_camera::frameRead()
1113 struct v4l2_buffer buf;
1123 timeStamp.
update(toEpochOffset + buf.timestamp.tv_sec + buf.timestamp.tv_usec / 1000000.0);
1131 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1132 buf.memory = V4L2_MEMORY_MMAP;
1134 if (-1 == xioctl(param.
fd, VIDIOC_DQBUF, &buf)) {
1147 timeStamp.
update(toEpochOffset + buf.timestamp.tv_sec + buf.timestamp.tv_usec / 1000000.0);
1149 if (-1 == xioctl(param.
fd, VIDIOC_QBUF, &buf)) {
1160 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1161 buf.memory = V4L2_MEMORY_USERPTR;
1163 if (-1 == xioctl(param.
fd, VIDIOC_DQBUF, &buf)) {
1181 timeStamp.
update(toEpochOffset + buf.timestamp.tv_sec + buf.timestamp.tv_usec / 1000000.0);
1184 if (-1 == xioctl(param.
fd, VIDIOC_QBUF, &buf)) {
1201 void V4L_camera::imagePreProcess()
1208 const uint _pixelNum = param.
src_fmt.fmt.pix.width * param.
src_fmt.fmt.pix.height;
1210 uint16_t* raw_p = (uint16_t*)param.
raw_image;
1211 for (uint i = 0; i < _pixelNum; i++) {
1212 param.
src_image[i] = (
unsigned char)(raw_p[i] >> bit_shift);
1216 param.
src_fmt.fmt.pix.bytesperline = param.
src_fmt.fmt.pix.width;
1217 param.
src_fmt.fmt.pix.pixelformat = pixel_fmt_leo;
1230 void V4L_camera::imageProcess()
1232 static bool initted =
false;
1241 if (v4lconvert_convert((v4lconvert_data*)_v4lconvert_data,
1249 if ((err % 20) == 0) {
1250 yCError(
USBCAMERA,
"error converting \n\t Error message is: %s", v4lconvert_get_error_message(_v4lconvert_data));
1270 cv::resize(img(crop2), img_right, cvSize(param.
user_width / 2, param.
user_height), 0, 0, cv::INTER_CUBIC);
1286 timeTot += timeElapsed;
1288 if ((myCounter % 60) == 0) {
1300 void V4L_camera::captureStop()
1303 int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1311 ret = xioctl(param.
fd, VIDIOC_STREAMOFF, &type);
1314 yCError(
USBCAMERA,
"VIDIOC_STREAMOFF - Unable to stop capture: %d, %s", errno, strerror(errno));
1324 void V4L_camera::captureStart()
1327 enum v4l2_buf_type type;
1336 struct v4l2_buffer buf;
1339 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1340 buf.memory = V4L2_MEMORY_MMAP;
1343 if (-1 == xioctl(param.
fd, VIDIOC_QBUF, &buf)) {
1348 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1350 if (-1 == xioctl(param.
fd, VIDIOC_STREAMON, &type)) {
1358 struct v4l2_buffer buf;
1362 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1363 buf.memory = V4L2_MEMORY_USERPTR;
1368 if (-1 == xioctl(param.
fd, VIDIOC_QBUF, &buf)) {
1373 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1375 if (-1 == xioctl(param.
fd, VIDIOC_STREAMON, &type)) {
1384 bool V4L_camera::readInit(
unsigned int buffer_size)
1388 if (param.
buffers ==
nullptr) {
1403 bool V4L_camera::mmapInit()
1409 param.
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1410 param.
req.memory = V4L2_MEMORY_MMAP;
1412 if (-1 == xioctl(param.
fd, VIDIOC_REQBUFS, ¶m.
req)) {
1413 if (EINVAL == errno) {
1421 if (param.
req.count < 1) {
1426 if (param.
req.count == 1) {
1427 yCError(
USBCAMERA,
"Only 1 buffer was available, you may encounter performance issue acquiring images from device %s", param.
deviceId.c_str());
1432 if (param.
buffers ==
nullptr) {
1437 struct v4l2_buffer buf;
1442 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1443 buf.memory = V4L2_MEMORY_MMAP;
1446 if (-1 == xioctl(param.
fd, VIDIOC_QUERYBUF, &buf)) {
1451 param.
buffers[param.
n_buffers].
start = v4l2_mmap(
nullptr, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, param.
fd, buf.m.offset);
1460 bool V4L_camera::userptrInit(
unsigned int buffer_size)
1462 unsigned int page_size;
1464 page_size = getpagesize();
1465 buffer_size = (buffer_size + page_size - 1) & ~(page_size - 1);
1470 param.
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1471 param.
req.memory = V4L2_MEMORY_USERPTR;
1473 if (-1 == xioctl(param.
fd, VIDIOC_REQBUFS, ¶m.
req)) {
1474 if (EINVAL == errno) {
1484 if (param.
buffers ==
nullptr) {
1501 bool V4L_camera::set_V4L2_control(uint32_t
id,
double value,
bool verbatim)
1508 struct v4l2_control control;
1513 if (-1 == ioctl(param.
fd, VIDIOC_QUERYCTRL, &
queryctrl)) {
1514 if (errno != EINVAL) {
1522 if (
queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
1526 memset(&control, 0,
sizeof(control));
1529 control.value = value;
1532 if ((V4L2_CID_EXPOSURE ==
id) || (V4L2_CID_EXPOSURE_ABSOLUTE ==
id) || (V4L2_CID_EXPOSURE_AUTO ==
id)) {
1539 if (-1 == ioctl(param.
fd, VIDIOC_S_CTRL, &control)) {
1541 if (errno == ERANGE) {
1542 yCError(
USBCAMERA,
"Normalized input value %f ( equivalent to raw value of %d) was out of range for control %s: Min and Max are: %d - %d", value, control.value,
queryctrl.name,
queryctrl.minimum,
queryctrl.maximum);
1553 bool V4L_camera::check_V4L2_control(uint32_t
id)
1557 struct v4l2_control control;
1559 memset(&control, 0,
sizeof(control));
1565 if (-1 == ioctl(param.
fd, VIDIOC_QUERYCTRL, &
queryctrl)) {
1566 if (errno != EINVAL) {
1574 double V4L_camera::get_V4L2_control(uint32_t
id,
bool verbatim)
1577 struct v4l2_control control;
1579 memset(&control, 0,
sizeof(control));
1585 if (-1 == ioctl(param.
fd, VIDIOC_QUERYCTRL, &
queryctrl)) {
1586 if (errno != EINVAL) {
1593 if (
queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
1596 if (-1 == ioctl(param.
fd, VIDIOC_G_CTRL, &control)) {
1602 return control.value;
1606 if ((V4L2_CID_EXPOSURE ==
id) || (V4L2_CID_EXPOSURE_ABSOLUTE ==
id) || (V4L2_CID_EXPOSURE_AUTO ==
id)) {
1624 bool tmpAuto(
false);
1625 bool tmpOnce(
false);
1629 tmpMan = check_V4L2_control(V4L2_CID_RED_BALANCE) && check_V4L2_control(V4L2_CID_BLUE_BALANCE);
1630 tmpOnce = check_V4L2_control(V4L2_CID_DO_WHITE_BALANCE);
1631 tmpAuto = check_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE);
1635 tmpMan = check_V4L2_control(V4L2_CID_EXPOSURE) || check_V4L2_control(V4L2_CID_EXPOSURE_ABSOLUTE);
1636 tmpAuto = check_V4L2_control(V4L2_CID_EXPOSURE_AUTO);
1640 tmpMan = check_V4L2_control(convertYARP_to_V4L(feature));
1644 *_hasFeature = tmpMan || tmpOnce || tmpAuto;
1653 if (use_exposure_absolute) {
1654 ret = set_V4L2_control(V4L2_CID_EXPOSURE_ABSOLUTE, value);
1656 ret = set_V4L2_control(V4L2_CID_EXPOSURE, value);
1661 ret = set_V4L2_control(convertYARP_to_V4L(feature), value);
1672 if (use_exposure_absolute) {
1673 tmp = get_V4L2_control(V4L2_CID_EXPOSURE_ABSOLUTE);
1675 tmp = get_V4L2_control(V4L2_CID_EXPOSURE);
1680 tmp = get_V4L2_control(convertYARP_to_V4L(feature));
1696 ret &= set_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE,
false);
1697 ret &= set_V4L2_control(V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE, V4L2_WHITE_BALANCE_MANUAL);
1698 ret &= set_V4L2_control(V4L2_CID_RED_BALANCE, value1);
1699 ret &= set_V4L2_control(V4L2_CID_BLUE_BALANCE, value2);
1708 *value1 = get_V4L2_control(V4L2_CID_RED_BALANCE);
1709 *value2 = get_V4L2_control(V4L2_CID_BLUE_BALANCE);
1710 return !((*value1 == -1) || (*value2 == -1));
1723 if (
hasAuto(feature, &_hasAuto)) {
1749 tmp = set_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE, onoff);
1751 isActive_vector[feature] = onoff;
1757 set_V4L2_control(V4L2_LOCK_EXPOSURE,
false);
1761 tmp = set_V4L2_control(V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_AUTO);
1763 tmp = set_V4L2_control(V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_MANUAL);
1767 isActive_vector[feature] = onoff;
1770 bool man = set_V4L2_control(V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_MANUAL);
1772 man = set_V4L2_control(V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_SHUTTER_PRIORITY,
true);
1777 set_V4L2_control(V4L2_LOCK_EXPOSURE,
true);
1778 isActive_vector[feature] = onoff;
1784 isActive_vector[feature] =
true;
1787 isActive_vector[feature] =
false;
1798 double tmp = get_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE);
1809 bool _hasMan(
false);
1810 bool _hasMan2(
false);
1812 double _hasAuto = get_V4L2_control(V4L2_CID_EXPOSURE_AUTO,
true);
1814 *_isActive = (_hasAuto == V4L2_EXPOSURE_AUTO) || _hasMan || _hasMan2;
1830 *_hasAuto = check_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE);
1834 *_hasAuto = check_V4L2_control(V4L2_CID_AUTOBRIGHTNESS);
1838 *_hasAuto = check_V4L2_control(V4L2_CID_AUTOGAIN);
1842 *_hasAuto = check_V4L2_control(V4L2_CID_EXPOSURE_AUTO);
1846 *_hasAuto = check_V4L2_control(V4L2_CID_HUE_AUTO);
1859 *_hasManual = check_V4L2_control(V4L2_CID_RED_BALANCE) && check_V4L2_control(V4L2_CID_BLUE_BALANCE);
1864 *_hasManual = check_V4L2_control(V4L2_CID_EXPOSURE) || check_V4L2_control(V4L2_CID_EXPOSURE_ABSOLUTE);
1875 *_hasOnePush = check_V4L2_control(V4L2_CID_DO_WHITE_BALANCE);
1879 *_hasOnePush =
false;
1891 ret = set_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE,
true);
1893 ret = set_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE,
false);
1899 hasAuto(V4L2_CID_EXPOSURE_AUTO, &_tmpAuto);
1903 ret = set_V4L2_control(V4L2_CID_EXPOSURE_AUTO,
true);
1905 ret = set_V4L2_control(V4L2_CID_EXPOSURE_AUTO,
false);
1915 ret = set_V4L2_control(V4L2_CID_AUTOGAIN,
true);
1918 ret = set_V4L2_control(V4L2_CID_AUTOGAIN,
false);
1929 ret = set_V4L2_control(V4L2_CID_AUTOBRIGHTNESS,
true);
1931 ret = set_V4L2_control(V4L2_CID_AUTOBRIGHTNESS,
false);
1941 ret = set_V4L2_control(V4L2_CID_HUE_AUTO,
true);
1943 ret = set_V4L2_control(V4L2_CID_HUE_AUTO,
false);
1948 yCError(
USBCAMERA) <<
"Feature " << feature <<
" does not support auto mode";
1960 double ret = get_V4L2_control(V4L2_CID_AUTO_WHITE_BALANCE);
1967 double ret = get_V4L2_control(V4L2_CID_EXPOSURE_AUTO);
1973 if (
ret == V4L2_EXPOSURE_MANUAL) {
1987 double ret = get_V4L2_control(V4L2_CID_AUTOBRIGHTNESS);
1998 double ret = get_V4L2_control(V4L2_CID_AUTOGAIN);
2009 double ret = get_V4L2_control(V4L2_CID_HUE_AUTO);
2025 return set_V4L2_control(V4L2_CID_DO_WHITE_BALANCE,
true);
@ YARP_FEATURE_BRIGHTNESS
@ YARP_FEATURE_WHITE_BALANCE
@ YARP_FEATURE_SATURATION
const yarp::os::LogComponent & USBCAMERA()
struct v4l2_queryctrl queryctrl
static double getEpochTimeShift()
struct v4l2_querymenu querymenu
#define DEFAULT_FRAMERATE
#define VIDIOC_REQBUFS_COUNT
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
int getRgbWidth() override
Return the width of each frame.
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool hasOnePush(int feature, bool *_hasOnePush) override
Check if the requested feature has the 'onePush' mode.
bool close() override
close device
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ...
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool hasOnOff(int feature, bool *_hasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
bool getCameraDescription(CameraDescriptor *camera) override
Get a basic description of the camera hw.
int getRgbHeight() override
Return the height of each frame.
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
bool hasAuto(int feature, bool *_hasAuto) override
Check if the requested feature has the 'auto' mode.
int width() const override
Return the width of each frame.
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
bool setOnePush(int feature) override
Set the requested feature to a value (saturation, brightness ...
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ...
bool getActive(int feature, bool *_isActive) override
Get the current status of the feature, on or off.
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
int height() const override
Return the height of each frame.
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool open(yarp::os::Searchable &config) override
open device
bool hasManual(int feature, bool *_hasManual) override
Check if the requested feature has the 'manual' mode.
FeatureMode toFeatureMode(bool _auto)
A simple collection of objects that can be described and transmitted in a portable way.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool isNull() const override
Checks if the object is invalid.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
An abstraction for a periodic thread.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
A class for storing options and configuration information.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
void wait()
Decrement the counter, even if we must wait to do that.
void post()
Increment the counter.
An abstraction for a time stamp and/or sequence number.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool asBool() const
Get boolean value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
bool isNull() const override
Checks if the object is invalid.
virtual std::string asString() const
Get string value.
unsigned char * getRawImage() const
Access to the internal image buffer.
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
void push_back(const T &elem)
Push a new element in the vector: size is changed.
#define YARP_NULLPTR
Expands to either the standard nullptr or to 0 elsewhere.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR16
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR8
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB8
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG8
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG8
void list_cap_v4l2(int fd)
void query_current_image_fmt_v4l2(int fd)
An interface for the device drivers.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
void delay(double seconds)
Wait for a certain number of seconds.
An interface to the operating system, including Port based communication.
int stat(const char *path)
Portable wrapper for the stat() function.
std::string deviceDescription
struct v4l2_format dst_fmt
unsigned char * read_image
yarp::sig::VectorOf< yarp::dev::CameraConfig > configurations
struct v4l2_format src_fmt
unsigned char * raw_image
unsigned char * dst_image_rgb
yarp::os::Property intrinsic
struct v4l2_requestbuffers req
unsigned char * src_image
unsigned int dst_image_size_rgb
unsigned int src_image_size
unsigned int raw_image_size
Struct describing a possible camera configuration.
YarpVocabPixelTypesEnum pixelCoding