Intermediate Vision example not showing Rectangle in the SmartDashboard

We running the Intermediate vision example. When the driver station is disabled, we see the live stream from our USB camera. When we enable we expected to see an image (a frame of our image) on the SmartDashboard with a rectangle over it. What are we missing? I know, probably something simple.


It’s hard to know what’s going wrong without being able to see your code. Can you post a link or add the code to this thread?

The only thing I can think of right now is to make sure that you have the correct stream selected in SmartDashboard. I think the example code on the ScreenSteps will create two streams, one with your custom image and one with the raw image from your camera.

Here is the code we are using;
public void robotInit() {
m_visionThread = new Thread(() -> {
// Get the UsbCamera from CameraServer
UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
// Set the resolution
camera.setResolution(640, 480);

  // Get a CvSink. This will capture Mats from the camera
  CvSink cvSink = CameraServer.getInstance().getVideo();
  // Setup a CvSource. This will send images back to the Dashboard
  CvSource outputStream
      = CameraServer.getInstance().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.
      // skip the rest of the current iteration
    // 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


I think you have an extra curly brace just after Imgproc.rectangle that places the outputStream.putFrame line outside of the while loop. However, unless I’m missing something, I wouldn’t expect this code to compile because of that extra curly brace.

You are correct. I was trying something with the code and posted the code with an extra curly brace.

the end of the code should look like this:

        // Give the output stream a new image to display


What your code does is provide a second camera stream with the rectangle superimposed. This stream should show up as a second “camera” on the dashboard list of cameras. This has no relation to the enabled/disabled state of the DS. If you select this second “camera” does the rectangle appear?

You should still make sure that outputStream.putFrame(mat); is inside the while loop. That’s the line of code that actually sends the image to the dashboard, so it needs to be inside the loop to keep updating the image.

1 Like

When we added the camera stream to the SmartDashboard I thought we only saw camera 0. I will look again tonight .

Thanks, We will try moving the line of code tonight.

Got the chance to try this again after the suggestions made, and all is well. Thanks for the help