Can't manage to successfully capture video frame from camera in a Mat object

I’ve been trying to develop some image processing code and I’m having trouble actually capturing the camera feed in a Mat object as the FRC sample code demonstrates.
I’m trying to grab a frame of video feed from a USB camera. I would like to capture that frame inside a Mat object in order to process it before outputting it to the dashboard as a separate video feed. No matter what I do, my code just refuses to work and I can’t figure out what’s wrong.

UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
camera.setResolution (640, 480);
CvSink cvSink = CameraServer.getInstance().getVideo();
CvSource outputStream = CameraServer.getInstance().putVideo("Robot Vision", 640, 480);
Mat source;
Mat output;
Thread vpthread = new Thread (() -> {
	while(!Thread.interrupted()) {
		Imgproc.cvtColor(source, output, Imgproc.COLOR_BGR2GRAY); 
		if(doProcessing) {

Whenever I test this code, I receive an error at Imgproc.cvtColor() regarding the incorrect initialization of source. I’ve done a bit of debugging and have discovered that after cvSing.grabFrame(), source is empty and its size is also 0x0 and I can’t figure out why. I’m beginning to become rather frustrated and simply cannot seem to figure out what I am doing incorrectly. I would really appreciate it if someone could please point me in the right direction.