Arth_Kumar11
Arth_Kumar11

Reputation: 59

cv::VideoCapture::open VIDEOIO(DSHOW)

I have been working on this error for a while but can't resolve it. This is my code

import cv2
import numpy as np
import time

cam = cv2.VideoCapture(0)
time.sleep(2)

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

cam.release()
cv2.destroyAllWindows()

And this is the error it is giving me.

[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (193) cv::VideoCapture::open VIDEOIO(DSHOW): raised unknown C++ exception!

Traceback (most recent call last): File "C:\Users\VVA\Desktop\test.py", line 10, in cv2.imshow('webcam', frame) cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

Upvotes: 2

Views: 7762

Answers (2)

Siegfried Loeffler
Siegfried Loeffler

Reputation: 61

On my macbook the reason this happens seem to be that the internal webcam is index number 1, whereas the index number 0 seems to be the "camtwist" webcam driver.

The answer "just use a different index number" is correct. However it's not very satisfying - if you want to write portable code, what is the way to determine the correct index number of the internal webcam of the device? Better do a loop through all devices?

Upvotes: 0

Arth_Kumar11
Arth_Kumar11

Reputation: 59

just use different index number

Upvotes: 4

Related Questions