Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/Overlays


Ignore:
Timestamp:
Nov 28, 2019, 11:04:54 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/Overlays

    v1 v2  
    1515import edu.wpi.cscore.CvSource;
    1616import edu.wpi.cscore.UsbCamera;
     17import edu.wpi.first.cameraserver.*;
    1718import edu.wpi.first.wpilibj.TimedRobot;
    18 import edu.wpi.first.cameraserver.*;
    1919
    2020public class Robot extends TimedRobot {
    2121   
    2222    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
    2325            new Thread(() -> {
     26                // get a handle to the camera server that accesses the USB camera
    2427                UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
    2528                camera.setResolution(640, 480);
    26                
     29 
     30                // CvSink receives video from the camera               
    2731                CvSink cvSink = CameraServer.getInstance().getVideo();
     32                // CvSource sends video stream (named "Rectangle") to the smart dashboard
    2833                CvSource outputStream = CameraServer.getInstance().putVideo("Rectangle", 640, 480);
    2934               
     35                // We store video frames in a Mat for processing
    3036                Mat mat = new Mat();
    3137               
    3238                while(!Thread.interrupted()) {
     39                  // grab a frame from the video stream
    3340                  if (cvSink.grabFrame(mat) == 0) {
    3441                    outputStream.notifyError(cvSink.getError());
     
    3643                    continue;
    3744                  }
    38                   // Put a rectangle on the image
     45                  // Put a red rectangle on the image
    3946                  Imgproc.rectangle(mat, new Point(160,120), new Point(480,360), new Scalar(0,0,255), 5);
    4047                  // Give the output stream a new image to display