mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
SCRIPT Move java files
This commit is contained in:
committed by
Peter Johnson
parent
7ca1be9bae
commit
c350c5f112
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.httpcamera;
|
||||
|
||||
import edu.wpi.first.wpilibj.RobotBase;
|
||||
|
||||
/**
|
||||
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what
|
||||
* you are doing, do not modify this file except to change the parameter class to the startRobot
|
||||
* call.
|
||||
*/
|
||||
public final class Main {
|
||||
private Main() {}
|
||||
|
||||
/**
|
||||
* Main initialization function. Do not perform any initialization here.
|
||||
*
|
||||
* <p>If you change your main robot class, change the parameter type.
|
||||
*/
|
||||
public static void main(String... args) {
|
||||
RobotBase.startRobot(Robot::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.httpcamera;
|
||||
|
||||
import edu.wpi.first.cameraserver.CameraServer;
|
||||
import edu.wpi.first.cscore.CvSink;
|
||||
import edu.wpi.first.cscore.CvSource;
|
||||
import edu.wpi.first.cscore.HttpCamera;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
/**
|
||||
* This is a demo program showing the use of OpenCV to do vision processing. The image is acquired
|
||||
* from an HTTP camera, then a rectangle is put on the image and sent to the dashboard. OpenCV has
|
||||
* many methods for different types of processing.
|
||||
*/
|
||||
public class Robot extends TimedRobot {
|
||||
Thread m_visionThread;
|
||||
|
||||
/** Called once at the beginning of the robot program. */
|
||||
public Robot() {
|
||||
m_visionThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
// Create an HTTP camera. The address will need to be modified to have the correct
|
||||
// team number. The exact path will depend on the source.
|
||||
HttpCamera camera =
|
||||
new HttpCamera("HTTP Camera", "http://10.x.y.11/video/stream.mjpg");
|
||||
// Start capturing images
|
||||
CameraServer.startAutomaticCapture(camera);
|
||||
// Set the resolution
|
||||
camera.setResolution(640, 480);
|
||||
|
||||
// Get a CvSink. This will capture Mats from the camera
|
||||
CvSink cvSink = CameraServer.getVideo();
|
||||
// Setup a CvSource. This will send images back to the Dashboard
|
||||
CvSource outputStream = CameraServer.putVideo("Rectangle", 640, 480);
|
||||
|
||||
// Mats are very memory expensive. Lets reuse this Mat.
|
||||
Mat mat = new Mat();
|
||||
|
||||
// This cannot be 'true'. The program will never exit if it is. This
|
||||
// lets the robot stop this thread when restarting robot code or
|
||||
// deploying.
|
||||
while (!Thread.interrupted()) {
|
||||
// Tell the CvSink to grab a frame from the camera and put it
|
||||
// in the source mat. If there is an error notify the output.
|
||||
if (cvSink.grabFrame(mat) == 0) {
|
||||
// Send the output the error.
|
||||
outputStream.notifyError(cvSink.getError());
|
||||
// skip the rest of the current iteration
|
||||
continue;
|
||||
}
|
||||
// Put a rectangle on the image
|
||||
Imgproc.rectangle(
|
||||
mat, new Point(100, 100), new Point(400, 400), new Scalar(255, 255, 255), 5);
|
||||
// Give the output stream a new image to display
|
||||
outputStream.putFrame(mat);
|
||||
}
|
||||
});
|
||||
m_visionThread.setDaemon(true);
|
||||
m_visionThread.start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user