I am just wondering how many USB cameras can be accessed by one desktop PC? Is there any limit? I am planning to create my own Windows application (using .NET) to capture ar
[Edited]
Actually, see this article which explains: Get List of connected USB Devices
I'm not sure there is a maximum. I will check and post back if I find out.
[Further Edit]
Can't find a documented maximum. Theoretically the ManagementObjectCollection
should be able to hold millions of objects in it. If you ran into problems (which I doubt with 10 devices), you could just preallocate the collection size upon instantiation.
I've just ran a test and I can pick up over 10 USB devices through a hub. You should be fine.
a bit late sorry :) What i found out is that a single USB card is limited by the USB bandwidth. but.. if you add USB cards on the PCI you can get more cameras but... most vendors do not bother to alter the USB card address the computer see so you need to buy USB to PCI cards from different vendors and try your luck. I had the same problem with firewire. here is my code for python. (thank other programmers on 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()
The problem is not how many you can discover. On a single USB bus, ~127 could be possible.
But, a USB bus can only transfer a limited amount of bytes per second. So if you want to use more then one, you have to calculate the amount of bandwidth you have for the video stream.
Example : A USB bus normally can deliver realistically ~35 MB/s. 640*480*2 bytes per pixel => 614400 bytes per frame. @30 FPS this is ~17 MB/s, so you can use 2 cameras simultaneously with this setup.
Maximum limit for usb devices connected to one host - 127. So, you can connect up to 100+ devices and they would work fine (100+ - because hub is also active device and have own address).
Possibly, you try to access first (already active) camera and program fails, because camera already locked?
If that Actually, see code for connect 5 cams in to one computer( processor core i3, 8gb ram!!!) you need connect all cameras in to usb ports only on you'r computer!!! git hub link