Hello, recently I was able to get a USB camera plugged into a raspberry pi 3 to stream via MJPEG streamer. Before we had two usb cameras plugged into the RIO and swapped via this code which has now been modified to theoretically work with the pi stream. However, when I try this, I either get a too many simultaneous streams error, or an error saying that the address specified cannot be reached.
I have the MJPEG stream also set to stream port 1180. Any tips on how to get this working? Also, am I better off just putting this switcher logic on the pi and grab the switch button via Network Tables?
public void robotInit() {
Thread t = new Thread(() -> {
boolean allowCam1 = false;
UsbCamera camera1 = CameraServer.getInstance().startAutomaticCapture(0);
camera1.setResolution(320, 240);
camera1.setFPS(30);
HttpCamera piCam = new HttpCamera("piCam", "http://10.23.170.203:1180/?action=stream", HttpCameraKind.kMJPGStreamer);
CvSink cvSink1 = CameraServer.getInstance().getVideo(camera1);
CvSink cvSink2 = CameraServer.getInstance().getVideo(piCam);
CvSource outputStream = CameraServer.getInstance().putVideo("Switcher", 640, 480);
Mat image = new Mat();
while(!Thread.interrupted()) {
if(oi.getGamepad().getRawButton(9)) {
allowCam1 = !allowCam1;
Timer.delay(1);
}
if(allowCam1){
cvSink2.setEnabled(false);
cvSink1.setEnabled(true);
cvSink1.grabFrame(image);
} else{
cvSink1.setEnabled(false);
cvSink2.setEnabled(true);
cvSink2.grabFrame(image);
}
outputStream.putFrame(image);
}
});
t.start();