So I’m trying to code some simple vision tracking within the rio to see the ball and align with it but i dont really know where to start i have some stuff that i literally just copy and pasted to try and to get some start to see how it works. if the RIO seems laggy and stuff we could get a co processor its just we dont have a ethernet switch to mess with it yet so i figured this would at least help me get started and have an understanding of vision tracking.
m_visionThread =
new Thread(
() -> {
// Get the UsbCamera from CameraServer
UsbCamera camera = CameraServer.startAutomaticCapture();
// Set the resolution
camera.setResolution(640, 480);
// Get a CvSink. This will capture Mats from the camera
CvSink cvSink = CameraServer.getVideo();
// Setup a CvSource. This will send images back to the Dashboard
CvSource outputStream = CameraServer.putVideo("Rectangle", 640, 480);
// Mats are very memory expensive. Lets reuse this Mat.
Mat mat = new Mat();
// This cannot be 'true'. The program will never exit if it is. This
// lets the robot stop this thread when restarting robot code or
// deploying.
while (!Thread.interrupted()) {
// Tell the CvSink to grab a frame from the camera and put it
// in the source mat. If there is an error notify the output.
if (cvSink.grabFrame(mat) == 0) {
// Send the output the error.
outputStream.notifyError(cvSink.getError());
// skip the rest of the current iteration
continue;
}
// Put a rectangle on the image
Imgproc.rectangle(
mat, new Point(100, 100), new Point(400, 400), new Scalar(255, 255, 255), 5);
// Give the output stream a new image to display
outputStream.putFrame(mat);
}
});
m_visionThread.setDaemon(true);
m_visionThread.start();
}