一台 PC 可以访问多少个 USB 摄像头



我只是想知道一台台式电脑可以访问多少个 USB 摄像头?有限制吗?我计划创建自己的 Windows 应用程序(使用 .NET)来捕获连接到台式电脑的大约 10 个 USB 摄像头。这可能吗?

问题不在于你能发现多少。在单个USB总线上,~127是可能的。

但是,USB 总线每秒只能传输有限数量的字节。因此,如果要使用多个,则必须计算视频流的带宽量。

例:USB 总线通常可以提供实际的 ~35 MB/s.每像素 640*480*2 字节 => 每帧 614400 字节。@ 30 FPS 这是 ~17 MB/s,因此您可以在此设置中同时使用 2 台摄像机。

如果那样 实际上,请参阅将 5 个凸轮连接到一台计算机(处理器核心 i3、8GB RAM!!)的代码,您需要将所有相机连接到计算机上的 USB 端口!!Git 中心链接

有点晚了对不起:)我发现单个USB卡受到USB带宽的限制。但。。如果您在PCI上添加USB卡,则可以获得更多相机,但是...大多数供应商不会费心更改计算机看到的USB卡地址,因此您需要从不同的供应商处购买USB到PCI卡并碰碰运气。我在火线上遇到了同样的问题。这是我的Python代码。(感谢StackOverflow上的其他程序员)

# show multiple usb cameras
import os
import cv2
import threading
import time
import datetime
#font for image writing
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
fontColor = (255,180,180)
lineType = 2
SaveImage = True # if true save images
duration = [100,100,100,10,10] # time between image saves in sec
IMAGESAVEPATH = "C:/tmp/pix" # path for camera to store image to
ShowText = True #Show text on image - text will be  saved with the image
#camera thread. here me make a thread and its functions
class camThread(threading.Thread):
def __init__(self, previewName, camID):
    threading.Thread.__init__(self)
    self.previewName = previewName
    self.camID = camID
def run(self):
    print ("Starting " + self.previewName)
    camPreview(self.previewName, self.camID)
#camera main loop - here we init the specific camera and start it then have a             window to show the image and we store the image to the right directory
def camPreview(previewName, camID):
    cv2.namedWindow(previewName)
cam = cv2.VideoCapture(camID) #start the camera (the cameras are numbered by the         order they are connected to the computer)
if cam.isOpened():  # try to get the first frame
    cam.set(3,4000)    #this will bring the largest frame set    
    cam.set(4,4000)
    cam.set(5,1) #fps
    time.sleep(2)
    cam.set(15, -1.0)
    rval, frame = cam.read() #read the image
else:
    rval = False
TStart = time.time() # time  for next image
mpath = os.path.join(IMAGESAVEPATH, str(camID)) #make sure the directory we save in exists, otherwise make it
print("try to make dir ", mpath, " T " , time.time())
if not os.path.exists(mpath):
    os.makedirs(mpath)
    
    cv2.namedWindow(previewName, cv2.WINDOW_NORMAL)
while rval: #if we get an image
    height, width, channels = frame.shape
    if ShowText: # write text on the image
        caption = str(camID) + " - " + str(height) + " " + str(width) + " "
        cv2.putText(frame,str(caption),(20,20),font, fontScale, fontColor, lineType)
    cv2.imshow(previewName, frame) # show image in its window
    #cv2.resizeWindow(previewName, 1280,960) # resize all windows removed ofer
    rval, frame = cam.read() #raed next image
    key = cv2.waitKey(20) 
    if key == 27:  # exit on ESC
        print("key pressed ", camID)
        break
    
    TDiff = int(time.time() - TStart) # time difference from last image
    if (SaveImage and TDiff > duration[camID]): # Save if time passed
        file_name = os.path.join(mpath, "T{:%Y.%m.%d %H-%M-%S}.jpg".format(datetime.datetime.now())) # make file name string
        cv2.imwrite(file_name, frame) 
        print("rsaved to : ", file_name)
        TStart = time.time() #reset time to next image
        
    cv2.destroyWindow(previewName)
# Create 5 threads as follows
thread1 = camThread("Camera 1", 0)
thread2 = camThread("Camera 2", 1)
thread3 = camThread("Camera 3", 2)
thread4 = camThread("Camera 4", 3)
thread5 = camThread("Camera 5", 4)
thread1.start()
thread2.start()
thread3.start()
thread4.start()
thread5.start()

[已编辑]

实际上,请参阅这篇文章,其中解释了:获取已连接的 USB 设备列表

我不确定是否有最大值。 如果我发现,我会检查并回发。

[进一步编辑]

找不到记录的最大值。 从理论上讲,ManagementObjectCollection应该能够容纳数百万个物体。 如果您遇到问题(我怀疑 10 台设备),您可以在实例化时预先分配集合大小。

刚刚进行了一次测试,我可以通过集线器拾取 10 多个 USB 设备。 你应该没事的。

连接到一台主机的 USB 设备的最大限制 - 127。因此,您最多可以连接100 +设备,它们可以正常工作(100+ - 因为集线器也是活动设备并且有自己的地址)。

可能,您尝试访问第一个(已处于活动状态)的相机并且程序失败,因为相机已经锁定?

最新更新