Skip to content

Video capture resolution stuck in Windows MSMF backend #12822

Closed

Description

@nerdfever

Open CV 3.4.2
Windows 64 Bit
Python 3.6

See http://answers.opencv.org/question/195388/video-capture-resolution-issue-on-windows/

The poster found the problem on a Logitech HD Webcam C615; I'm seeing the same thing on a Logitech QuickCam Pro 9000.

On Windows 10 x64 with the MSMF backend, if you change video resolution like so:

camera.set(cv2.CAP_PROP_FRAME_WIDTH, x)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, y)

The result is that you'll get a frame of size x,y pixels (if x,y is one of the resolutions supported by the webcam), but that image is in fact a 640x480 image rescaled to size x,y.

The poster at answers.opencv.org above claims that on the DirectShow backend it appears to work correctly (I've only tried the MSMF backend so far).

For example, below are 3 images captured identically at 640x480, 960x720, and 1600x1200 resolution with the MSMF backend from a Logitech QuickCam Pro 9000 (all those are reported by the camera as supported modes). It's pretty obvious they were all captured at the same resolution, then scaled.

20181013_143012_1 640x480

20181013_142952_1 960x720

20181013_143219_1 1600x1200

Activity

  1. nerdfever commented on Oct 21, 2018

    @nerdfever
    Author

    I confirm that switching to the DirectShow backend fixes this.

    It's the MSMF backend that has this problem.

  2. PhilLab commented on May 31, 2019

    @PhilLab
    Contributor

    I am experiencing the same with OpenCV 3.4.3. The default cv::VideoCapture::open() selects MSMF backend and is not able to change the resolution.

    Explicitly requesting cv::CAP_DSHOW works

    Video I/O:
      Video for Windows:           YES
      DC1394:                      NO
      FFMPEG:                      YES (prebuilt binaries)
        avcodec:                   YES (ver 57.107.100)
        avformat:                  YES (ver 57.83.100)
        avutil:                    YES (ver 55.78.100)
        swscale:                   YES (ver 4.8.100)
        avresample:                YES (ver 3.7.0)
      GStreamer:                   NO
      DirectShow:                  YES
      Media Foundation:            YES
    
  3. Python-Regius commented on Dec 11, 2019

    @Python-Regius

    I can confirm that this is still an issue using OpenCV 4.1.2 and that switching to the DirectShow back-end resolves the issue.

    Also if you try using a non 4:3 aspect ratio width and height you will get black boarders.

  4. added
    Hackathon
    on Jan 14, 2020
  5. DMardanbegi commented on Apr 1, 2020

    @DMardanbegi

    This issue has not been resolved and it still exists with MSMF backend.

  6. mshabunin commented on Apr 2, 2020

    @mshabunin
    Contributor

    @dmardanbeigi , please provide more details: platform, OpenCV version, camera model, reproducer code.

    Please note that the fix for this issue is available only on master and 3.4 branches and has not been released yet.

  7. DMardanbegi commented on Apr 8, 2020

    @DMardanbegi

    Isn't 3.4 branch already included in opencv-python 4.0?

    It only works with DSHOW backend and not MSMF.
    Python 3.7.4 (64 bit)
    Windows 10
    opencv-python==4.0.0.21
    opencv-contrib-python==4.0.0.21

    Camera: I tried on both a Quanta UVC camera and the webcam on my HP Spectre x360 (I don't know the details). The resolutions is supported by both cameras.

    Here is the code I use:

    import cv2
    _capture = cv2.VideoCapture(0)# cv2.CAP_DSHOW)
    print(_capture.getBackendName())
    size=(1920, 1080)
    print(_capture.set(cv2.CAP_PROP_FRAME_WIDTH, size[0]))
    print(_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, size[1]))
    _ret, img = _capture.read()
    _ret = True
    cv2.namedWindow("img")
    cv2.resizeWindow('img', size[0],size[1])
    cv2.imshow("img", img)
    while _ret:
        _ret, img = _capture.read()
        key_code = cv2.waitKey(1)
        if (key_code == 27) or (key_code == ord('q')):
            break
        cv2.imshow("calibration", img)
  8. alalek commented on Apr 8, 2020

    @alalek
    Member

    Isn't 3.4 branch already included in opencv-python 4.0?

    Not exactly.
    See release dates instead: https://github.com/opencv/opencv/releases


    Order of changing capturing parameters should be:

    • width
    • height
    • fps
    • [optional] native backend modes / formats.

    You have missed fps.
    For MSMF mode responds for H/W acceleration.

  9. mshabunin commented on Apr 8, 2020

    @mshabunin
    Contributor

    opencv-python==4.0.0.21 is an old version, latest version in pip is 4.2.0.34 The fix for this issue have not been included there yet. You should either build OpenCV for python by yourself (tag 4.3.0) either wait until new version will be available on pip.

  10. DMardanbegi commented on Apr 8, 2020

    @DMardanbegi

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hackathonbugcategory: videoio(camera)platform: win32

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions