On Windows 7 I am using following python code in order to display webcam or laptop cam feed in open CV window. But the problem is that I can see both laptop camera light and in case of usb camera light lit up but the window shown no image just empty/grey.
Code:
import cv2
vid = cv2.VideoCapture(0)
while(True):
ret, frame = vid.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
vid.release()
cv2.destroyAllWindows()
They both work in skype and other utilities. Even on VLC as well. I have checked in my device manager and they both show up.
Please help me how to debug this issue. Because same is happening on my raspberry pi.
Regards, Yasar
Edit 1: Guys - Thank you for your responses but as I have already mentioned above that on cv2.VideoCapture(0) I can see my laptop's cam light turning on and on cv2.VideoCapture(1), my webcam's light turns on but no frame is returned. I have already checked the forums but unable to solve my issue.
import cv2
vid = cv2.VideoCapture(0)
print (vid)
print (vid.isOpened())
while(vid.isOpened()):
ret, frame = vid.read()
print (ret)
print (frame)
if not ret:
break
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
vid.release()
cv2.destroyAllWindows()
Output of above is as below: <VideoCapture 0000000002DAE970> True False None
Please suggest.