Displaying 2 USB Cameras

Our team is trying to mount 2 Microsoft Lifecam USB Cameras to our robot (1 in the front and one in the back). How would we be able to view both cameras? It could be either simultaneous display or alternating displays. I understand there is a 4MB limit; can we just lower the resolution/frame rate of the cameras?

We are using Java

1 Like

Screensteps is your friend, my friend.

https://wpilib.screenstepslive.com/s/currentCS/m/vision/l/708159-using-multiple-cameras

Hopefully that gives you what you need. If you have more specific questions, ask, and they can be answered further.

That page is written in c++. Is there anything for Java?

See Switching Cameras with code for a Java equivalent. They really are very very similar, which is why screensteps often only has one or the other.

2 Likes

Thank you! That helps a lot.

Just curious - what sort of camera switching times are you all getting via code?
Our programmers told us (electrical) that it could take up to a couple of seconds and we didnā€™t second guess them.
Built a USB relay that toggles input to the RoboRio USB using a signal out of the DIO.
Itā€™s still some software, but the relay switch is just about instantaneous.

Are you talking about a USB physical switch that disconnects the camera?? That canā€™t possibly be faster than keeping both cameras connected and using software to switch, as physically disconnecting means the camera would need to renegotiate the USB protocol etc. While the ā€œdefaultā€ software behavior is to disconnect the cameras, causing a couple second delay when switching as the camera reconnects, my post linked to above as well as the second example in screensteps keeps both cameras open and connected, which results in a near-instantaneous switch.

A post was merged into an existing topic: VSCode WPILib ā€œtestā€ feature

Good question and points, because of my incomplete description.
We went on Amazon and got some off the shelf small relays that switch two USB cameras connected (via the relays) to one USB on the Roborio.
As far as the software knows, thereā€™s only one camera connected.
We originally thought we would just switch the two USB data lines but we do the power and ground too.

Iā€™m not convinced thereā€™s any advantage to doing this but the programming team claimed software had a switching lagā€¦this setup is an instant switch.

This:

It would be interesting to see what ā€œdmesgā€ outputs when you switch the cameras. I would expect to see it disconnect one camera and connect the new one.

Iā€™ll see about getting info on messages when the cameras are switched via the relay moduleā€¦might be a little while before I ask programmers for that , bag day is looming!

I tried to add the code to my project but I am getting errors like ā€œType mismatch: cannot convert from MjpegServer to CameraServerā€

I followed the toggleable switch code, but Iā€™m not sure how to view the stream from the server on shuffleboard. How do can I view the stream?

The switched stream will appear as a virtual ā€œcameraā€ in the list of cameras in Shuffleboard, just like the real two cameras.

Are you talking about the Java code? Thereā€™s no use of the MjpegServer class explicitly in that code. So Iā€™m going to need more information (your code, what errors youā€™re getting) to help.

@Peter_Johnson I can see my two created cameras with name ā€œfrontcamā€ and ā€œbackcamā€ but donā€™t see anything besides that under the cameraserver tab.

Here is my code:

You have two Robot.javaā€™s in that repositoryā€¦ are you sure youā€™re running the right one?

Yeah, Iā€™m positive. New to github, but ignore everything in the ā€˜mainā€™ folder. The only files that interact with the cameras are Controls and the Robot.java outside the folder.

1 Like

It looks like it wonā€™t appear in the camera list until it has a source assigned. Try setting an initial source for the switched stream. E.g. after the setConnectionStrategy calls, do server.setSource(frontcam);

If this works, Iā€™ll edit my post above to correct this.

Unfortunately didnā€™t work.