Skip to content

Instantly share code, notes, and snippets.

@AustinShalit
Created November 29, 2016 03:50
Show Gist options
  • Save AustinShalit/e652a2508cca0bbd6a808f6c30b67830 to your computer and use it in GitHub Desktop.
Save AustinShalit/e652a2508cca0bbd6a808f6c30b67830 to your computer and use it in GitHub Desktop.
CameraServer Example (OpenCV)
package org.usfirst.frc.team190.robot;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import edu.wpi.cscore.CvSink;
import edu.wpi.cscore.CvSource;
import edu.wpi.cscore.USBCamera;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.IterativeRobot;
public class Robot extends IterativeRobot {
public void robotInit() {
new Thread(() -> {
USBCamera camera = CameraServer.getInstance().startAutomaticCapture();
camera.setResolution(640, 480);
CvSink cvSink = CameraServer.getInstance().getVideo();
CvSource outputStream = CameraServer.getInstance().putVideo("Blur", 640, 480);
Mat source = new Mat();
Mat output = new Mat();
while(true) {
cvSink.grabFrame(source);
Imgproc.cvtColor(source, output, Imgproc.COLOR_BGR2GRAY);
outputStream.putFrame(output);
}
}).start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment