Increase camera capture resolution in OpenCV

In my C / C ++ program, I use OpenCV to capture images from a webcam. The camera ( Logitech QuickCam IM ) can capture with a resolution of 320x240 , 640x480 and 1280x960 . But for some strange reason, OpenCV gives me 320x240 resolution images. Calls to change permission using cvSetCaptureProperty () with other permission values ​​just don't work. How to take a picture using other resolutions using a webcam?

+50
c image opencv webcam
Aug 18 '08 at 7:45
source share
15 answers

There seems to be no solution. Resolution can be increased to 640x480 using this hack , which shares lifebelt77. The following are the details:

Add to highgui.h :

#define CV_CAP_PROP_DIALOG_DISPLAY 8 #define CV_CAP_PROP_DIALOG_FORMAT 9 #define CV_CAP_PROP_DIALOG_SOURCE 10 #define CV_CAP_PROP_DIALOG_COMPRESSION 11 #define CV_CAP_PROP_FRAME_WIDTH_HEIGHT 12 

Add icvSetPropertyCAM_VFW function to cvcap.cpp :

 static int icvSetPropertyCAM_VFW( CvCaptureCAM_VFW* capture, int property_id, double value ) { int result = -1; CAPSTATUS capstat; CAPTUREPARMS capparam; BITMAPINFO btmp; switch( property_id ) { case CV_CAP_PROP_DIALOG_DISPLAY: result = capDlgVideoDisplay(capture->capWnd); //SendMessage(capture->capWnd,WM_CAP_DLG_VIDEODISPLAY,0,0); break; case CV_CAP_PROP_DIALOG_FORMAT: result = capDlgVideoFormat(capture->capWnd); //SendMessage(capture->capWnd,WM_CAP_DLG_VIDEOFORMAT,0,0); break; case CV_CAP_PROP_DIALOG_SOURCE: result = capDlgVideoSource(capture->capWnd); //SendMessage(capture->capWnd,WM_CAP_DLG_VIDEOSOURCE,0,0); break; case CV_CAP_PROP_DIALOG_COMPRESSION: result = capDlgVideoCompression(capture->capWnd); break; case CV_CAP_PROP_FRAME_WIDTH_HEIGHT: capGetVideoFormat(capture->capWnd, &btmp, sizeof(BITMAPINFO)); btmp.bmiHeader.biWidth = floor(value/1000); btmp.bmiHeader.biHeight = value-floor(value/1000)*1000; btmp.bmiHeader.biSizeImage = btmp.bmiHeader.biHeight * btmp.bmiHeader.biWidth * btmp.bmiHeader.biPlanes * btmp.bmiHeader.biBitCount / 8; capSetVideoFormat(capture->capWnd, &btmp, sizeof(BITMAPINFO)); break; default: break; } return result; } 

and edit captureCAM_VFW_vtable as follows:

 static CvCaptureVTable captureCAM_VFW_vtable = { 6, (CvCaptureCloseFunc)icvCloseCAM_VFW, (CvCaptureGrabFrameFunc)icvGrabFrameCAM_VFW, (CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_VFW, (CvCaptureGetPropertyFunc)icvGetPropertyCAM_VFW, (CvCaptureSetPropertyFunc)icvSetPropertyCAM_VFW, // was NULL (CvCaptureGetDescriptionFunc)0 }; 

Now rebuilt highgui.dll .

+15
Aug 18 '08 at 7:46
source share
— -

I use openCV 1.1pre1 on Windows (the video integrated library is used by default with this version of openCv under windows).

Using these instructions, I can set the camera resolution. Note that I call the old cvCreateCameraCapture instead of cvCaptureFromCam.

 capture = cvCreateCameraCapture(cameraIndex); cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 640 ); cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 480 ); videoFrame = cvQueryFrame(capture); 

I tested it with Logitech, Trust and Philips webcams

+41
Apr 3 '09 at 12:40
source share

I already processed the images on Linux and skipped the OpenCV functions built into the camera because it (as you discovered) is incomplete.

Depending on your OS, you may have more luck directly on the hardware through regular channels rather than through openCV. If you are using Linux, video4linux or video4linux2 should provide you with relatively trivial access to USB webcams, and you can use libavc1394 for firewire. Depending on the device and the quality of the code code below, you should be able to start the device with the required parameters in an hour or two.

Edited to add: You are on your own if its Windows. I think this is not much more difficult, but I have never done it.

+5
Aug 19 '08 at 0:20
source share

I highly recommend using VideoInput lib , it supports any DirectShow device (even multiple devices at the same time) and is more configurable. You will spend five minutes to play OpenCV.

+5
Sep 01 '08 at 17:15
source share

Check this ticket: https://code.ros.org/trac/opencv/ticket/376

"The solution is to use a new libv4l-based shell.

  • install libv4l-dev (as it is called in Ubuntu)

  • Repeat cmake, you will see "V4L / V4L2: Using libv4l"

  • repeat make. Now the resolution can be changed. tested with inline isotype on MBP. "

This fixed it for me using Ubuntu and may be working for you.

+5
Oct 28 2018-10-2810:
source share

Code I finally worked in Python as soon as Aaron Haun pointed out that I need to define the arguments to the set function before using them.

 #Camera_Get_Set.py #By Forrest L. Erickson of VRX Company Inc. 8-31-12. #Opens the camera and reads and reports the settings. #Then tries to set for higher resolution. #Workes with Logitech C525 for resolutions 960 by 720 and 1600 by 896 import cv2.cv as cv import numpy CV_CAP_PROP_POS_MSEC = 0 CV_CAP_PROP_POS_FRAMES = 1 CV_CAP_PROP_POS_AVI_RATIO = 2 CV_CAP_PROP_FRAME_WIDTH = 3 CV_CAP_PROP_FRAME_HEIGHT = 4 CV_CAP_PROP_FPS = 5 CV_CAP_PROP_POS_FOURCC = 6 CV_CAP_PROP_POS_FRAME_COUNT = 7 CV_CAP_PROP_BRIGHTNESS = 8 CV_CAP_PROP_CONTRAST = 9 CV_CAP_PROP_SATURATION = 10 CV_CAP_PROP_HUE = 11 CV_CAPTURE_PROPERTIES = tuple({ CV_CAP_PROP_POS_MSEC, CV_CAP_PROP_POS_FRAMES, CV_CAP_PROP_POS_AVI_RATIO, CV_CAP_PROP_FRAME_WIDTH, CV_CAP_PROP_FRAME_HEIGHT, CV_CAP_PROP_FPS, CV_CAP_PROP_POS_FOURCC, CV_CAP_PROP_POS_FRAME_COUNT, CV_CAP_PROP_BRIGHTNESS, CV_CAP_PROP_CONTRAST, CV_CAP_PROP_SATURATION, CV_CAP_PROP_HUE}) CV_CAPTURE_PROPERTIES_NAMES = [ "CV_CAP_PROP_POS_MSEC", "CV_CAP_PROP_POS_FRAMES", "CV_CAP_PROP_POS_AVI_RATIO", "CV_CAP_PROP_FRAME_WIDTH", "CV_CAP_PROP_FRAME_HEIGHT", "CV_CAP_PROP_FPS", "CV_CAP_PROP_POS_FOURCC", "CV_CAP_PROP_POS_FRAME_COUNT", "CV_CAP_PROP_BRIGHTNESS", "CV_CAP_PROP_CONTRAST", "CV_CAP_PROP_SATURATION", "CV_CAP_PROP_HUE"] capture = cv.CaptureFromCAM(0) print ("\nCamera properties before query of frame.") for i in range(len(CV_CAPTURE_PROPERTIES_NAMES)): # camera_valeus =[CV_CAPTURE_PROPERTIES_NAMES, foo] foo = cv.GetCaptureProperty(capture, CV_CAPTURE_PROPERTIES[i]) camera_values =[CV_CAPTURE_PROPERTIES_NAMES[i], foo] # print str(camera_values) print str(CV_CAPTURE_PROPERTIES_NAMES[i]) + ": " + str(foo) print ("\nOpen a window for display of image") cv.NamedWindow("Camera", 1) while True: img = cv.QueryFrame(capture) cv.ShowImage("Camera", img) if cv.WaitKey(10) == 27: break cv.DestroyWindow("Camera") #cv.SetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 1024) #cv.SetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 768) cv.SetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 1600) cv.SetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 896) print ("\nCamera properties after query and display of frame.") for i in range(len(CV_CAPTURE_PROPERTIES_NAMES)): # camera_valeus =[CV_CAPTURE_PROPERTIES_NAMES, foo] foo = cv.GetCaptureProperty(capture, CV_CAPTURE_PROPERTIES[i]) camera_values =[CV_CAPTURE_PROPERTIES_NAMES[i], foo] # print str(camera_values) print str(CV_CAPTURE_PROPERTIES_NAMES[i]) + ": " + str(foo) print ("/nOpen a window for display of image") cv.NamedWindow("Camera", 1) while True: img = cv.QueryFrame(capture) cv.ShowImage("Camera", img) if cv.WaitKey(10) == 27: break cv.DestroyWindow("Camera") 
+5
Sep 03 '12 at 20:26
source share

I use debian and ubuntu, I had the same problem, I could not change the video input resolution using CV_CAP_PROP_FRAME_WIDTH and CV_CAP_PROP_FRAME_HEIGHT

I found out that the reason was the missing library. I installed lib4l-dev via synaptic, restored OpenCV, and the problem is solved!

+4
Apr 28 2018-11-11T00:
source share

I am posting this to ensure that no one else is wasting time with this setproperty function. I spent 2 days on this to see that nothing was working. So I dug up the code (I first installed the library). This is what actually happens - cvSetCaptureProperty, calls setProperty inside the CvCapture class, and now, setProperty does nothing. It just returns false. Instead, I will set about using another library to serve OpenCV video / image capture. I am using OpenCV 2.2

+2
May 01 '11 at 15:16
source share

I found that on Windows (from Win98 to WinXP SP3), OpenCV often uses the Microsoft VFW library to access cameras. The problem is that it is often very slow (say a maximum of 15 FPS frames) and buggy (which is why cvSetCaptureProperty often does not work). Fortunately, you can usually change the resolution in other software (in particular, "AMCAP", which is a demo program that is easily accessible), and this will affect the resolution that OpenCV will use. For example, you can run AMCAP to set the resolution to 640x480, and then OpenCV will use this by default from this point!

But if you can use another Windows camera access library, such as the http://muonics.net/school/spring05/videoInput/ video input library, which accesses the camera using the very efficient DirectShow (part of DirectX). Or, if you have a professional-quality camera, it will often come with a user API that allows you to access the camera, and you can use it for quick access with the ability to change resolution and much more.

0
Nov 11 '10 at 18:32
source share

On Windows, try using the VideoInput library: http://robocraft.ru/blog/computervision/420.html

0
Mar 21 '11 at 15:33
source share

cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH, WIDTH);

cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT, HEIGHT);

cvQueryFrame (capture);

This will not work with OpenCV 2.2, but if you use OpenCV 2.1, it will work fine!

0
Jun 06 2018-11-11T00:
source share

If you are on a Windows platform, try DirectShow (IAMStreamConfig).

http://msdn.microsoft.com/en-us/library/dd319784%28v=vs.85%29.aspx

0
Jun 12 2018-11-12T00:
source share

Only one piece of information that can be valuable to people who have difficulty changing the default capture resolution (640 x 480)! I experimented with such a problem with opencv 2.4.x and one Logitech camera ... and found one workaround!

The behavior that I found is that the default format is set as the initial parameters when starting the camera capture (cvCreateCameraCapture) and all requests for changing the height or width:

 cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, ... 

or

 cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, ... 

not possible later! In fact, I found with the addition of an ioctl function return error that the V4l2 driver returns EBUSY for these requests! Therefore, one way to solve the problem is to change the default value directly in the highgui / cap_v4l.cpp file:

 *#define DEFAULT_V4L_WIDTH 1280 // Originally 640* *#define DEFAULT_V4L_HEIGHT 720 // Originally 480* 

After that, I just recompiled opencv ... and came to get 1280 x 720 without any problems! Of course, the best solution should be to stop acquiring, change the settings, and restart the stream after, but I'm not familiar with opencv for that!

Hope this helps.

Michel BEGEY

0
01 Oct '13 at 4:52
source share

Try the following:

 capture = cvCreateCameraCapture(-1); //set resolution cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, frameWidth); cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, frameHeight); 
-one
05 Oct 2018-10-10
source share
 cvQueryFrame(capture); cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, any_supported_size ); cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, any_supported_size); cvQueryFrame(capture); 

should be enough!

-3
Jun 19 '10 at 17:27
source share



All Articles