Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package frc.robot.subsystems;
- import frc.robot.RobotContainer;
- import frc.robot.Vision.BoardCheck;
- import frc.robot.Vision.CubeCheck;
- import org.opencv.core.Mat;
- import edu.wpi.cscore.CvSink;
- import edu.wpi.cscore.UsbCamera;
- import edu.wpi.first.cameraserver.CameraServer;
- import edu.wpi.first.wpilibj.Timer;
- import java.util.*;
- public class JavaCamera
- {
- public int nowTask = 0;
- public int nowResult = -1;
- public int nowIteration = 0;
- public Map<String, Map<String, List<String>>> boardResult;
- private UsbCamera camera;
- private CvSink cvSink;
- public JavaCamera()
- {
- camera = CameraServer.getInstance().startAutomaticCapture();
- camera.setResolution(640, 480);
- camera.setFPS(30);
- cvSink = CameraServer.getInstance().getVideo();
- }
- public void Start()
- {
- new Thread(() -> {
- RobotContainer.train.serverIsRunningSB.setDouble(1);
- while (!Thread.interrupted())
- {
- float loopBegin = (float)Timer.getFPGATimestamp() * 1000;
- RobotContainer.train.nowTaskServerSB.setDouble(nowTask);
- Mat source = new Mat();
- if (cvSink.grabFrame(source) == 0)
- {
- continue;
- }
- if (source.cols() < 640 || source.rows() < 480)
- {
- continue;
- }
- if (nowTask == 1)
- {
- boardResult = BoardCheck.Check(source);
- }
- if (nowTask == 2)
- {
- nowResult = CubeCheck.Check(source, false);
- }
- if (nowTask == 3)
- {
- nowResult = CubeCheck.Check(source, true);
- }
- if (nowTask == 4)
- {
- nowResult = CubeCheck.CheckYellow(source);
- }
- RobotContainer.train.resultFromClientSB.setDouble(nowResult);
- RobotContainer.train.iterationsServerSB.setDouble(nowIteration++);
- source.release();
- }
- }).start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement