I have two webcams attached to my laptop (one built in), both of which work. (If I use Cheese, a webcam thingy that comes with Ubuntu, it uses the external one). If I use
Great answer by @Patrick, but I'd like to improve on it and can't comment yet.
I think Patricks setup assumes that the cameras do not have empty indexes in between them. But in my case, my built-in camera was at index 0, and USB webcam was at index 2. So "if not cap.read()[0]" broke out of the while loop at index 1, never catching the others. We have to specify how many indexes we're willing to go over and check, and just not add the ones that are null.
def returnCameraIndexes():
# checks the first 10 indexes.
index = 0
arr = []
i = 10
while i > 0:
cap = cv2.VideoCapture(index)
if cap.read()[0]:
arr.append(index)
cap.release()
index += 1
i -= 1
return arr
This successfully gave me the indexes I need. Again, thanks to Patrick for the layout!