We got some help from a previous programmer on the team. He commented all of his code from last year to guide us through programming a dual-camera system that can switch between cameras by pressing a button. Here’s what we’ve typed out:
package frc.robot;
import edu.wpi.first.wpilibj.TimedRobot;
import org.opencv.core.Mat;
import edu.wpi.cscore.CvSink;
import edu.wpi.cscore.CvSource;
import edu.wpi.cscore.UsbCamera;
import edu.wpi.first.cameraserver.CameraServer;
import frc.robot.OI.Controller;
public class Camera extends TimedRobot {
private CvSink[] cameras = {null, null};
private CvSource imgOut;
private int currCamera = 0;
private Mat img;
private final int[] res = {240, 160};
public Camera() {
img = new Mat(res[0], res[1], 0);
UsbCamera cam0 = CameraServer.getInstance().startAutomaticCapture(0);
UsbCamera cam1 = CameraServer.getInstance().startAutomaticCapture(1);
cameras[0] = CameraServer.getInstance().getVideo(cam0);
cameras[1] = CameraServer.getInstance().getVideo(cam1);
imgOut = CameraServer.getInstance().putVideo("Camera", res[0], res[1]);
}
public void run() {
viewCam();
SwitchCam();
}
private void SwitchCam() {
if(Robot.oi.getButtonDown(Controller.Pilot, 8)) {
if(currCamera == 0) {
currCamera = 1;
} else {
currCamera = 0;
}
}
}
private void viewCam() {
cameras[currCamera].grabFrame(img);
imgOut.putFrame(img);
}
public void robotInit() {
//CameraServer.getInstance().startAutomaticCapture(0);
//CameraServer.getInstance().startAutomaticCapture(1);
}
}
The “robotInit” function isn’t being used, as it just runs both cameras at the same time and sucks up bandwidth. The system uses an int id for each camera and switches between them using the Start button on an Xbox 360 controller.
The code throws an exception when we try to deploy it:
Unhandled exception: java.lang.UnsatisfiedLinkError: ‘long org.opencv.core.Mat.n_Mat(int, int, int)’
Can anybody help?