Hey, our team is trying to create a separate thread for vision. The only piece of code I could find in screensteps was in Java, but we code in C++. Can someone help me?
visionThread = new VisionThread(camera, new MyVisionPipeline(), pipeline -> {
if (!pipeline.filterContoursOutput().isEmpty()) {
Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
synchronized (imgLock) {
centerX = r.x + (r.width / 2);
}
}
});
visionThread.start();
Here are a couple references on threading in C++:
In short, the body of your vision thread will be effectively the same, so you just need to define the thread object and tell it to run.
Thank you! Do you know if it is even necessary to run a separate thread? Would the answer to that question change if we use a raspberry pi?
Using a thread isn’t strictly required.
If you use a raspberry pi, you wouldn’t need any camera code in your robot code at all. All you might need is something to read values returned by the pi (via network tables or similar) if you need to act on what your camera processing code is returning.
If all you want to do is send the camera feed back to the driverstation, I recommend looking into the CameraServer class and related articles on screensteps.