No announcement yet.

Multiple USBCameras (not for multiple network streams)

  • Time
  • Show
Clear All
new posts

  • Multiple USBCameras (not for multiple network streams)

    Is WPIlib (or the underlying NIVision libraries) expected to deal with multiple, simultaneous USB cameras?

    I'm trying to get two USBCamera()s setup -- one for streaming to the DS and one for on-robot vision analysis. I can plug in two cameras, they show up as "cam0" and "cam1", and I can capture (or stream) images from either of them. Everything works as I expect.

    But only one at a time.

    When I try to start both of those at once the second one started always returns "No image acquisition in progress", even though startCapture() has already been called (for example, when using the WPIlib-provided M-JPEG server, which calls startCapture() internally).

    Interestingly this problem goes away if I call USBCamera.getImage() directly instead of in a separate thread. For example, if I rig CameraServer to expose capture(), rig capture() to not loop, and call CameraServer.capture() directly from a command everything seems to work fine for as many captures I care to take. That's just not practical while the robot is otherwise in use -- it needs to run in its own thread to avoid making other commands lag. I don't know if this thread-related difference is important or just a side-effect of tying up the main thread for long periods, but I thought it was worth documenting.

    FYI: I'm using the Microsoft LifeCam HD‑3000 camera, though I don't have any reason to believe this is hardware-specific.

  • #2
    Re: Multiple USBCameras (not for multiple network streams)

    No, the CameraServer and USBCamera classes were not written with the intent of handling multiple simultaneous USB cameras. I know CameraServer will not work with two simultaneous, I'm not sure about USBCamera. Some teams have had success with using multiple cameras, but I don't know if any have been simultaneous or if they've all been switching. The underying NIVision libraries should have no issues with multiple cameras.
    FRC Robotics Engineer


    • #3
      Re: Multiple USBCameras (not for multiple network streams)

      I'm aware that the streaming server is restricted to a single stream; it doesn't even have provisions for second listening port. But I have a problem getting images from a second camera even if I call USBCamera.getImage() or the underlying NIVision.IMAQdxGrab() -- I get the "No acquisition in progress" error for whichever camera was started second.

      In any case it sounds like "in theory this is possible, but it's not popular enough to be well-tested". If someone has done this I'd be happy to hear about it.

      I'll work up a minimal test case to clearly demonstrate both my intent and the failure and link that code here, in case anyone else wants to take a look.