opencv 设置相机分辨率 windows vrs linux

use*_*153 3 python opencv image-resizing

会出现这种变体的问题,但不会出现这种错误情况。

此代码可在 Linux 上运行,但在 windows10 OpenCV 3.4.2、64 位 -Python 3.6 上失败 - 通过“pip3 install opencv-python”安装

它在 Windows 上失败并显示以下错误消息。

如果我删除 'cv2.set()' 的 horz 和 virt 大小,它可以工作,没有问题,但分辨率不是我想要的

我的目标是从默认图像大小更改为更大的大小。

v=3.4.2
Camera H=480, W=640
Camera H=480, W=640
[ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875855
[ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875855
[ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875855
[ WARN:1] videoio(MSMF): can't grab frame. Error: -2147483638
Run Code Online (Sandbox Code Playgroud)

这是 Python 代码

import cv2
print("v=%s" % cv2.__version__)
cap = cv2.VideoCapture(0, cv2.)
h = cap.get( cv2.CAP_PROP_FRAME_HEIGHT )
w = cap.get( cv2.CAP_PROP_FRAME_WIDTH )
print("Camera H=%d, W=%d" % (h,w) )
# If I remove these two lines it works but is stuck at 640x480
cap.set( cv2.CAP_PROP_FRAME_HEIGHT, 10000 )
cap.set( cv2.CAP_PROP_FRAME_WIDTH, 10000 )
h = cap.get( cv2.CAP_PROP_FRAME_HEIGHT )
w = cap.get( cv2.CAP_PROP_FRAME_WIDTH )
print("Camera H=%d, W=%d" % (h,w) )

while(True):
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    ret, frame = cap.read()
    if ret:
        cv2.imshow('frame',frame)

cap.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

bri*_*ris 8

我能够通过切换到 DSHOW 后端 API 来解决这个问题:

cap = cv2.VideoCapture(cv2.CAP_DSHOW)
Run Code Online (Sandbox Code Playgroud)