Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/Overlays
- Timestamp:
- Nov 28, 2019, 11:04:54 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/Overlays
v1 v2 15 15 import edu.wpi.cscore.CvSource; 16 16 import edu.wpi.cscore.UsbCamera; 17 import edu.wpi.first.cameraserver.*; 17 18 import edu.wpi.first.wpilibj.TimedRobot; 18 import edu.wpi.first.cameraserver.*;19 19 20 20 public class Robot extends TimedRobot { 21 21 22 22 public void robotInit() { 23 // do camera processing in its own thread so if anything goes wrong, 24 // we don't take down the entire robot 23 25 new Thread(() -> { 26 // get a handle to the camera server that accesses the USB camera 24 27 UsbCamera camera = CameraServer.getInstance().startAutomaticCapture(); 25 28 camera.setResolution(640, 480); 26 29 30 // CvSink receives video from the camera 27 31 CvSink cvSink = CameraServer.getInstance().getVideo(); 32 // CvSource sends video stream (named "Rectangle") to the smart dashboard 28 33 CvSource outputStream = CameraServer.getInstance().putVideo("Rectangle", 640, 480); 29 34 35 // We store video frames in a Mat for processing 30 36 Mat mat = new Mat(); 31 37 32 38 while(!Thread.interrupted()) { 39 // grab a frame from the video stream 33 40 if (cvSink.grabFrame(mat) == 0) { 34 41 outputStream.notifyError(cvSink.getError()); … … 36 43 continue; 37 44 } 38 // Put a re ctangle on the image45 // Put a red rectangle on the image 39 46 Imgproc.rectangle(mat, new Point(160,120), new Point(480,360), new Scalar(0,0,255), 5); 40 47 // Give the output stream a new image to display