title: OpenCV: can't set resolution of video capture
body: <p>I am using OpenCV 2.4.5 on Ubuntu 12.04 64-bit. I would like to be able to set the resolution of the input from my Logitech C310 webcam. The camera supports up to 1280x960 at 30fps, and I am able to view the video at this resolution in guvcview. But OpenCV always gets the video at only 640x480. </p>
  
  <p>Trying to change the resolution with cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280) and cap.set(CV_CAP_PROP_FRAME_HEIGHT, 960) immediately after the VideoCapture cap is created has no effect; trying to set them immediately before getting every frame causes the program to crash immediately. I cannot reduce the resolution with this method either. I am also getting the error "HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP". I think this may be related, because it appears once when the VideoCapture is created, and once when I try to set the width and height (but, oddly, not if I try to set only one of them).</p>
  
  <p>I know I'm not the first to have this problem, but I have yet to find a solution after much Googling and scouring of SO and elsewhere on the internet (among the many things I've already tried to no avail is the answer to this StackOverflow question: <a href="https://stackoverflow.com/questions/14287/increasing-camera-capture-resolution-in-opencv">Increasing camera capture resolution in OpenCV</a>). Is this a bug in OpenCV? If so, it's a rather glaring one. </p>
  
  <p>Here's an example of code that exhibits the problem (just a modified version of OpenCV's video display code):</p>
  
  <pre><code>#include &lt;cv.h&gt;
  #include &lt;highgui.h&gt;
  using namespace cv;
  
  int main(int argc, char** argv)
  {
      VideoCapture cap(0); // open the default camera
      if(!cap.isOpened())  // check if we succeeded
              return -1;
  
      cap.set(CV_CAP_PROP_FRAME_WIDTH, 160);
      cap.set(CV_CAP_PROP_FRAME_HEIGHT, 120);
  
      Mat image;
      namedWindow("Video", CV_WINDOW_AUTOSIZE);
  
      while(1)
      {
              // cap.set(CV_CAP_PROP_FRAME_WIDTH, 160);
              // cap.set(CV_CAP_PROP_FRAME_HEIGHT, 120);
              cap &gt;&gt; image;
  
              imshow("Video", image);
  
              if(waitKey(10) == 99 ) break;
      }
      return 
  }
  </code></pre>
  
  <p>As it is, that gets me two "HIGHGUI ERROR"s as described above and I get a 640x480 output. I know that 160x120 is a resolution that my camera supports from running <code>v4l2-ctl --list-formats-ext</code>. If I uncomment the two commented-out lines in the while loop, the program crashes immediately. </p>
  
  <p>These might be related or have possible solutions: <a href="http://answers.opencv.org/question/11427/decreasing-capture-resolution-of-webcam/" rel="nofollow noreferrer">http://answers.opencv.org/question/11427/decreasing-capture-resolution-of-webcam/</a>, <a href="http://answers.opencv.org/question/30062/error-setting-resolution-of-video-capture-device/" rel="nofollow noreferrer">http://answers.opencv.org/question/30062/error-setting-resolution-of-video-capture-device/</a></p>