How to eliminate lag on USB Webcam Java

Hello!

Our team was using the simple camera server code on our robot during our last competition. It worked, but it always had a 1-2 second lag. Is there anyway to just lower the resolution and frame rate of the video (preferable 160x120px) so that the video feed is at least real-time?

(We are using USB webcams)

Right click on the camera on the smart dashboard and you can change the resolution. You can also resize the window.

Inside the CameraServer Class there is a setQuality() Method.

You can use this to change the quality of the image sent to the Driverstation which should decrease the Lag.

Checkout the WPI Documentation on the CameraServer Class for more information.

We heard from another team that you can preset the resolution of the HD-3000 Camera with the life-cam software, but we tried changing the size of the video in the LifeCam software, but all that does is change the resolution for that recording session, and doesn’t transfer when we plug it into the roborio.

Try running the camera in its own thread during operator control.
Write the vision code like you usually would, and then during the operator control loop, call it in its own thread, separate from other functions of the robot.
We had major camera lag problems, and this fixed it for us.

Here’s a bit of example code


    public void operatorControl() 
    {
    	isDone = false;
    	//Begin vision processing on a new thread
    	Thread thread = new Thread() 
    	{
    		public void run() 
    		{
    			while (!isDone) 
    			{
    				if(RobotMap.visionSystemEnable != -1)
    				{
        				vision.vision();
    				}
    			}
    		}
    	};
    	thread.start(); 

Use Resource Monitor to verify that you’re not exceeding the 7mbps rate limit on robot <–> operator console communications. We had to set quality on the stream to 30 to do so.