Search code examples
c++opencvwebcamresolution

Query maximum webcam resolution in OpenCV


I'm dealing with several types of cameras and I need to know the maximum resolution each one is capable.

Is there a way to query such property in OpenCV?

If not, is there any other way? The application will work under Windows (by the moment) and all the project is being developed using C++.


Solution

  • A trick that's working for me:

    Just set to a very high resolution (above the capabilities of any usual capture device), then get the current resolution. You will see that the device will automatically switch to his maximum value.

    Code example in Python with OpenCV 3.0:

    HIGH_VALUE = 10000
    WIDTH = HIGH_VALUE
    HEIGHT = HIGH_VALUE
    
    self.__capture = cv2.VideoCapture(0)
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    self.__capture.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH)
    self.__capture.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT)
    
    width = int(self.__capture.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(self.__capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
    

    Hope it helps.