There’s a problem with my vision code. I’m only using 1 output stream, but I’m getting the error “too many output streams”. Here is my code
// Vision Processing
private VisionThread visionThread;
private final Object imgLock = new Object();
double centerX = 0.0;
double width = 0.0;
public String shotReady = "Shot Ready";
int gripTolerance = 3;
int tooFar = 90;
int tooClose = 110;
int camWidth = 320;
int camHeight = 240;
int imageCenter = (camWidth / 2);
boolean isShotReady = false;
VisionClass pipeline = new VisionClass();
VisionRunner<?> visionRunner;
UsbCamera cam0, cam1, selectedCam;
Mat image;
CvSink selectedVideo, gearVid, highGoalVid;
CvSource outputStream;
boolean isTargetFound = false;
@Override
public void robotInit() {
// Switch Vision Targets
cam0 = new UsbCamera("cam0", 0); // High Goal Camera
cam1 = new UsbCamera("cam1", 1); // Gear Camera
cam0.setResolution(camWidth, camHeight);
cam1.setResolution(camWidth, camHeight);
cam0.setFPS(16);
cam1.setFPS(16);
selectedCam = cam0;
image = new Mat();
// MjpegServer server = new MjpegServer("server", 1181);
highGoalVid = CameraServer.getInstance().getVideo(cam0);
highGoalVid.setEnabled(true);
gearVid = CameraServer.getInstance().getVideo(cam1);
gearVid.setEnabled(false);
highGoalVid.grabFrame(image);
selectedVideo = highGoalVid;
outputStream = CameraServer.getInstance().putVideo("Selected Video", camWidth, camHeight);
// server.setSource(outputStream);
outputStream.putFrame(image);
visionThread = new VisionThread(selectedCam, pipeline, pipeline -> {
if (!pipeline.filterContoursOutput().isEmpty()) {
isTargetFound = true;
Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
Rect r1 = Imgproc.boundingRect(pipeline.filterContoursOutput().get(1));
Mat processedImage = new Mat();
synchronized (imgLock) {
selectedVideo.grabFrame(processedImage);
Imgproc.rectangle(processedImage, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height),
new Scalar(0, 0, 255), 2);
Imgproc.rectangle(processedImage, new Point(r1.x, r1.y), new Point(r1.x + r1.width, r1.y + r1.height),
new Scalar(0, 0, 255), 2);
outputStream.putFrame(processedImage);
}
} else {
isTargetFound = false;
}
});
visionThread.start();