How to declare a camera in visual studio with java frc

I put a code but a warning appeared, this warning was “the method getinstance() from the type CameraServer is deprecated

1 Like
Thread visionThread = new Thread(() -> {
		System.out.println("In thread");
		UsbCamera camera = new UsbCamera("Microsoft Lifecam", "/dev/video0");
		CameraServer.getInstance().addCamera(camera);
		camera.setResolution(160, 120);
		camera.setFPS(30);
		CvSink cvSink = CameraServer.getInstance().getVideo();
		CvSource outputStream = CameraServer.getInstance().putVideo("UsbCamera", 160, 120);

		Mat mat = new Mat();

		while (!Thread.interrupted()) {
			if (cvSink.grabFrame(mat) == 0) {
				outputStream.notifyError(cvSink.getError());
				continue;
			}
			// Core.flip(mat,mat,Core.ROTATE_180);
			Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2GRAY);
			outputStream.putFrame(mat);
		}
	});
	visionThread.setDaemon(true);
	visionThread.start();

This sounds like a duplicate of Warning stting up a camera in a robot (java) to me

Can you post your code? It might be helpful for people to see.

change your camera server import to

import edu.wpi.first.cameraserver.CameraServer

1 Like

sorry if it isn’t clear enough

I meant take a screenshot of your code. So we can see the problem.