Listing available devices in python-opencv

前端 未结 6 657
暖寄归人
暖寄归人 2020-12-03 14:32

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

6条回答
  •  無奈伤痛
    2020-12-03 15:10

    I believe that under Linux the valid indices for video inputs are the numbers of the videoN devices in the /dev directory. Hence the following will give a list of valid indices:

    import os
    devs = os.listdir('/dev')
    vid_indices = [int(dev[-1]) for dev in devs 
                   if dev.startswith('video')]
    vid_indices = sorted(vid_indices)
    vid_indices
    

提交回复
热议问题