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

manual focus with usb_cam

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

dinamex gravatar image

updated 2012-07-07 07:34:02 -0500

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));
  queryctrl.id = V4L2_CID_FOCUS_AUTO;

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

    if (-1 == xioctl(fd, VIDIOC_S_CTRL, &control)) {
      perror("VIDIOC_S_CTRL");
      return;
    }
  }
}

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Comments

I tried the uvc camera pkg but have problems to use it. I created a new question for that. http://answers.ros.org/question/38170/cant-set-any-settings-for-uvc_camera/

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

Question Tools

Stats

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

Seen: 1,568 times

Last updated: Jul 07 '12