I can able to access the inbuilt laptop camera with the following code
import cv2
#import numpy as np
cap = cv2.VideoCapture(0)
while (True):
ret, frame = cap.read()
key = cv2.waitKey(20)
cv2.imshow("preview", frame)
if key == 27: # exit on ESC
break
cap.release()
cv2.destroyAllWindows()
I connected a USB camera. I gave 1 instead of 0 to access it. but it is showing an error. By changing it to between -1 and -99, I can access the inbuilt cam only. How can I access the USB cam? I checked the working condition of USB cam with cheese. It is working fine.