ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

manual focus with usb_cam

asked 2012-07-03 17:22:27 -0600

dinamex gravatar image

updated 2012-07-07 07:34:02 -0600

Hi all,

I would like to know how I could manually set the focal length. I know that I can set the autofocus option to false in the launchfile of the usb_cam package but where or how can I use the camera then?

Because now just everything is blurry and I don't know where to start looking. Thank you.

EDIT I found that there is a different in the binary (which doesen't have the option) and the installation from source (which offers the option in the launchfile). I looked up the libusb source code and I found the following at the end but I have no idea how to enable/disable or to set the focus manually.

// enables/disables auto focus
void usb_cam_camera_set_auto_focus(int value)
  struct v4l2_queryctrl queryctrl;
  struct v4l2_ext_control control;

  memset(&queryctrl, 0, sizeof(queryctrl)); = V4L2_CID_FOCUS_AUTO;

  if (-1 == xioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if (errno != EINVAL) {     
    } else {
      printf("V4L2_CID_FOCUS_AUTO is not supported\n");
  } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf("V4L2_CID_FOCUS_AUTO is not supported\n");
  } else {
   memset(&control, 0, sizeof(control)); = V4L2_CID_FOCUS_AUTO;
    control.value = value;

    if (-1 == xioctl(fd, VIDIOC_S_CTRL, &control)) {

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-05 06:47:49 -0600

As far as I can tell, libusb_cam does not have any code for setting the V4L2_CID_FOCUS_ABSOLUTE property, which means that you cannot set the focus value without editing the usb_cam driver.

At the same time, editing a local copy of the driver should not be too hard. Take a look at the v4l2 specification here, and see how to set the property. Alternatively, you can use the uvc_camera package which I believe already sets this property, but hard codes the value.

edit flag offensive delete link more


I tried the uvc camera pkg but have problems to use it. I created a new question for that.

dinamex gravatar image dinamex  ( 2012-07-07 07:34:53 -0600 )edit

Question Tools


Asked: 2012-07-03 17:22:27 -0600

Seen: 1,531 times

Last updated: Jul 07 '12