I am using OpenCV 2.4.5 on Ubuntu 12.04 64-bit. I would like to be able to set the input resolution from my Logitech C310 webcam. The camera supports up to 1280x960 at a speed of 30 frames per second, and I can view video in this resolution in guvcview. But OpenCV always receives video only at 640x480.
Attempting to change the resolution with cap.set (CV_CAP_PROP_FRAME_WIDTH, 1280) and cap.set (CV_CAP_PROP_FRAME_HEIGHT, 960) immediately after creating the VideoCapture cap does not affect; trying to set them immediately before getting each frame, the program will immediately work. I also can not reduce the resolution with this method. I also get the error message "HIGHGUI ERROR: V4L / V4L2: VIDIOC_S_CROP". I think this may be related because it appears once when VideoCapture is created, and once when I try to set the width and height (but, which is strange if I do not try to set only one of them).
I know that I am not the first to have this problem, but I still have to find a solution after a lot of googling and cleaning SO and other places on the Internet (among many things that I have already tried to no avail, the answer to this question StackOverflow: Increasing camera capture resolution in OpenCV ). Is this a bug in OpenCV? If so, it's pretty egregious.
Here is an example code that shows the problem (only a modified version of the OpenCV video display code):
#include <cv.h> #include <highgui.h> 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 >> image; imshow("Video", image); if(waitKey(10) == 99 ) break; } return }
Be that as it may, it gives me two "HIGHGUI ERROR", as described above, and I get an output of 640x480. I know that 160x120 is the resolution supported by my camera from running v4l2-ctl --list-formats-ext . If I uncomment the two commented lines in a while loop, the program will immediately work.
They can be related or have possible solutions: http://answers.opencv.org/question/11427/decreasing-capture-resolution-of-webcam/ , http://answers.opencv.org/question/30062/error- setting-resolution-of-video-capture-device /
opencv v4l2 v4l logitech
erobertc May 6 '13 at 1:19 2013-05-06 01:19
source share