5

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 around 10 USB cameras that are connected to my desktop PC. Is this possible?

Chris
  • 39,262
  • 15
  • 126
  • 145
John Hadikusumo
  • 1,257
  • 1
  • 11
  • 19
  • I tried very hard and was stuck with 2 cameras LIMIT. The system WILL display them all, but when you actually START them one by one, 3rd will always fail. BTW, I tried with several systems and several different cameras, and failed always. Please tell if you manage to get it running somehow. – Daniel Mošmondor Apr 20 '12 at 08:34
  • Have a look at the article I posted and create a small proof-of-concept. – Ste Apr 20 '12 at 08:49
  • I havent tried this, but what if you did something like this: turn camA on, display image, turn camA off, turn camB on, display image, turn B off, turn C... etc. if the process of turning off and on all of your cameras takes less than 1/30s all of your cameras will be effectively running at 30 FPS. – TehTris May 24 '18 at 05:01

5 Answers5

17

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.

Christopher
  • 8,656
  • 3
  • 30
  • 37
  • Are you sure that on PC only able to run 2 camera running ? I was stumped with this website http://www.gotocamera.com/how_it_works, it software supports 4 cameras on one PC. I am planning to create similar software. – John Hadikusumo Apr 20 '12 at 12:08
  • My example is for a uncompressed stream. If you have a MJPEG compressed video stream, you have other bandwidth requirements for each camera. – Christopher Apr 20 '12 at 16:24
  • may I ask for a bit enlightenment? does "USB bus" here means USB hub? because so far I only know USB port and USB hub.. I just don't want to be mistaken because of terms.. thanks – Yohanes Khosiawan 许先汉 May 16 '14 at 03:00
  • A USB bus is meant here as all devices connected to one USB controller. From this controller a tree can be build by using hubs. Look into the device manager (or something equivalent) and configure it to show 'By connection'. You can see the device tree from the controller over hubs to the devices. – Christopher May 16 '14 at 06:30
  • are uvc cameras generally sending compressed videos? – waspinator Mar 15 '17 at 20:51
1

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

Amir Je
  • 11
  • 1
0

[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.

Community
  • 1
  • 1
Ste
  • 1,106
  • 2
  • 10
  • 29
0

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?

Alexey
  • 489
  • 1
  • 3
  • 12
0

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()
oferb
  • 1
  • 2