How do I program a Microsoft LifeCam using Java to display onto SmartDashboard? WE NEED HELP PLEASE!

Our entire programming team is relatively new to programming a robot, and we’re trying to program some basic vision code in Java. We’ve been having trouble finding resources on Chief Delphi, and everything we’ve found so far is deprecated. How can we program a USB Camera, like a Microsoft LifeCam, to display onto the SmartDashboard?

See . You just need one line of code.

Edit: I just noticed that the docs refer to edu.wpi.first.wpilibj.CameraServer (which is deprecated) instead of edu.wpi.first.cameraserver.CameraServer and have submitted a PR to fix that.

I would also recommend ditching SmartDashboard, not only because it looks a little outdated but also because it’s functionality is nowhere even close to that of ShuffleBoard. You can adjust compression, resolution and even FPS on the fly, we did that last year. We used SmartDashboard in 2018 but a CSA recommended that we use ShuffleBoard when we were having issues and it worked flawlessly. We didn’t end up using it in 2019 but I’m excited to start using it this season. It has much more functionality, is easier to set up, and (IMHO :grin:) looks better than SmartDashboard.

1 Like

We’ve found that the camera is really laggy unless the server runs on a separate thread. We do this:

    Thread cameraThread = new Thread(() -> {
            var camera = CameraServer.getInstance().startAutomaticCapture();
            camera.setResolution(320, 240);

StartAutomaticCapture starts the camera in a new thread. Your code to call in in a second new thread should be unnecessary.

Is that new for 2020? This was necessary in 2019.

This has not changed since last year, but running those three lines of code in a separate thread makes no difference to the underlying operation of the camera server, which is internally multithreaded. Those three lines of code take almost no time to execute and that thread will exit nearly immediately.

Thanks, we’ll try removing the thread.

We are a 3rd year team. The first year we didn’t have a camera, but we needed one for sandstorm last year. I remember clearly being at our week-zero event and asking another team why our camera framerate was so terrible. They suggested the thread, and the issue went away once implemented. I guess that must be a coincidence!?

I think it’s more likely that your camera defaulted you a resolution or frame rate that exceeded the bandwidth limits of the field. When the FPS was set to 15 and resolution to 320x240, it brought it under the bandwidth limit.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.