Ask Your Question
2

How to set or get VideoCapture properties?

asked 2013-01-30 14:02:22 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

I'm trying to modify the properties of a 720p HD Logitech usb webcam, in order to change their fps or image format, size.

But opencv generates the following error:

HIGHGUI ERROR: V4L2: Unable to get property <Unknown string> property (5) - Invalid argument.

The code:

# include <iostream>
# include <opencv2/core/core.hpp>
# include <opencv2/highgui/highgui.hpp>
# include <opencv2/imgproc/imgproc.hpp>    
using namespace std;

int main () {    
cv :: VideoCapture cap (0); // open the default camera

if (! cap.isOpened ()) // check if we succeeded
return -1;

cv :: Mat edges;
cv :: namedWindow ("edges", 1);

for (;;)
{
 cv :: Mat frame;
 cap >> frame; // get a new frame from camera

// This function generate error

cap.get double val = (CV_CAP_PROP_FPS);
cout << val << endl;

cv :: cvtColor (frame, edges, CV_BGR2GRAY);
cv :: GaussianBlur (edges, edges, cv :: Size (7,7), 1.5, 1.5);
cv :: Canny (edges, edges, 0, 30, 3);
cv :: imshow ("edges", edges);

if (cv :: waitKey (30)> = 0) break;
}

return 0;
}

I would appreciate some help.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2013-02-01 03:58:00 -0600

dom__dom gravatar image

Hey,

I believe your error is in this line:

cap.get double val = (CV_CAP_PROP_FPS);

try this instead:

double val = cap.get(CV_CAP_PROP_FPS);

Hope that helps

edit flag offensive delete link more
0

answered 2013-02-04 03:36:30 -0600

Geppertm gravatar image

Hey, the problem is that CV_CAP_PROP_FPS isn´t implemented yet. If you look at highgui/src/cap_libv4l2.cpp you´ll find this switch case in function icvGetPropertyCAM_V4L ...

  switch (property_id) {
case CV_CAP_PROP_FRAME_WIDTH:
case CV_CAP_PROP_FRAME_HEIGHT:
  CLEAR (capture->form);
  capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form)) {
      /* display an error message, and return an error code */
      perror ("VIDIOC_G_FMT");
    if (v4l1_ioctl (capture->deviceHandle, VIDIOCGWIN, &capture->captureWindow) < 0) {
      fprintf (stderr, "HIGHGUI ERROR: V4L:cap_libv4l: Unable to determine size of incoming image\n");
      icvCloseCAM_V4L(capture);
      return -1;
    } else {
      int retval = (property_id == CV_CAP_PROP_FRAME_WIDTH)?capture->captureWindow.width:capture->captureWindow.height;
      return retval / 0xFFFF;
    }
  }
  return (property_id == CV_CAP_PROP_FRAME_WIDTH)?capture->form.fmt.pix.width:capture->form.fmt.pix.height;
case CV_CAP_PROP_BRIGHTNESS:
  sprintf(name, "Brightness");
  capture->control.id = V4L2_CID_BRIGHTNESS;
  break;
case CV_CAP_PROP_CONTRAST:
  sprintf(name, "Contrast");
  capture->control.id = V4L2_CID_CONTRAST;
  break;
case CV_CAP_PROP_SATURATION:
  sprintf(name, "Saturation");
  capture->control.id = V4L2_CID_SATURATION;
  break;
case CV_CAP_PROP_HUE:
  sprintf(name, "Hue");
  capture->control.id = V4L2_CID_HUE;
  break;
case CV_CAP_PROP_GAIN:
  sprintf(name, "Gain");
  capture->control.id = V4L2_CID_GAIN;
  break;
case CV_CAP_PROP_EXPOSURE:
  sprintf(name, "Exposure");
  capture->control.id = V4L2_CID_EXPOSURE;
  break;
case CV_CAP_PROP_FOCUS:
  sprintf(name, "Focus");
  capture->control.id = V4L2_CID_FOCUS_ABSOLUTE;
  break;
default:
  sprintf(name, "<unknown property string>");
  capture->control.id = property_id;

....

As you can see your error is the default case. But you can modify this file. But i think it is easy to implement, try:

    case CV_CAP_PROP_FPS:
  sprintf(name, "Focus");
  return capture->GetFrameRate() ;

I´ve did the same with CV_CAP_PROP_FOCUS an it works fine.

Best

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-01-30 14:02:22 -0600

Seen: 31,287 times

Last updated: Feb 04 '13