What camera models are you using and how much lighting do you have / what are your camera settings? With some testing with a HD-3000, FPS is 30 with a brightly lit scene, but can drop off to <10 fps given a dark scene as the camera goes into a low light mode. Setting the exposure controls to fixed rather than auto can fix these sorts of issues (open a web browser to
http://roborio-449-frc.local:5800/ to get a simple settings gui to try things out).
The main reason you're seeing the delay in switching between cameras is because cscore automatically turns off the camera you're not using, so when you switch it needs to go through the entire connection process all over again. This is intentional to save CPU resources when there's no one connected to the camera stream, but there's a relatively easy workaround: create a CvSink, connect it to the camera, and enable it (it's not necessary to grab frames). This will cause the library to stay connected to the camera (because an enabled sink is always connected). E.g.:
Code:
public CvSink sink1;
public CvSink sink2;
...
sink1 = new CvSink("cam1cv");
sink1.setSource(cam1);
sink1.setEnabled(true);
sink2 = new CvSink("cam1cv");
sink2.setSource(cam2);
sink2.setEnabled(true);
Note you can use the CameraServer wrapper classes to get the other benefits of CameraServer (e.g. NetworkTables publishing), with code like the following rather than calling "new UsbCamera" explicitly.
Code:
cam1 = CameraServer.getInstance().startAutomaticCapture(0);
cam2 = CameraServer.getInstance().startAutomaticCapture(1);
server = CameraServer.getInstance().getServer();
// dummy CvSinks
sink1 = CameraServer.getInstance().getVideo(cam1);
sink1.setEnabled(true);
sink2 = CameraServer.getInstance().getVideo(cam2);
sink2.setEnabled(true);
__________________
Author of
cscore - WPILib CameraServer for 2017+
Author of
ntcore - WPILib NetworkTables for 2016+
Creator of
RobotPy - Python for FRC
2010 FRC World Champions (
294, 67, 177)
2007 FTC World Champions (30, 74,
23)
2001 FRC National Champions (71,
294, 125, 365, 279)