Ask Your Question
0

Change camera size fails on windows, works on linux?

asked 2018-08-15 21:49:03 -0600

duaneellis gravatar image

This codeworks on Linux, it Fails on windows10 OpenCV 3.4.2, 64bit -Python 3.6 - installed via "pip3 install opencv-python"

It fails on Windows with the error message below.

If I remove the 'cv2.set()' for the horz and virt size it works, without problem but the resolution is not what I want

My goal is to change from the default camera image size to the LARGER size.

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

This is the Python code

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()
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2018-08-25 17:49:08 -0600

brianpeiris gravatar image

I was able to work around this by switching to the DSHOW backend API:

cap = cv2.VideoCapture(cv2.CAP_DSHOW)
edit flag offensive delete link more

Comments

This worked for me. In addition, if you are using a second video source you can do something like this:

videoSourceIndex = 1
cap = cv2.VideoCapture(cv2.CAP_DSHOW + videoSourceIndex)
oonyalo gravatar imageoonyalo ( 2018-11-13 14:47:14 -0600 )edit
0

answered 2018-11-07 01:29:52 -0600

[ WARN:1] videoio(MSMF): OnReadSample() ,[ WARN:1] videoio(MSMF): async ReadSample() this error happens when there is configuration issue in your camera. Kindly reconfigure it. I have also faced the same problem when i used the external camera. Alternatively you can allow program to wait for sometime before camera gets started like below.

while ret == False: time.sleep(2) cap = cv2.VideoCapture(0 + cv2.CAP_DSHOW) ret, frame= cap.read()

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-08-15 21:49:03 -0600

Seen: 4,829 times

Last updated: Aug 15 '18