From d61d491a02ee87ab2e911b1f3d38080cde67ac1a Mon Sep 17 00:00:00 2001 From: PetaroMitaro Date: Tue, 16 Dec 2014 10:58:15 -0500 Subject: [PATCH] added Java vision example programs Change-Id: Icd99f53cc544c2609a333f0a86f4eac064d565bd --- .../org/usfirst/frc/team190/robot/Robot.java | 53 +++++++++++++++++++ .../org/usfirst/frc/team190/robot/Robot.java | 35 ++++++++++++ .../resources/templates/examples/examples.xml | 36 +++++++++++++ 3 files changed, 124 insertions(+) create mode 100755 eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/AdvancedVision/src/org/usfirst/frc/team190/robot/Robot.java create mode 100755 eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/QuickVision/src/org/usfirst/frc/team190/robot/Robot.java diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/AdvancedVision/src/org/usfirst/frc/team190/robot/Robot.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/AdvancedVision/src/org/usfirst/frc/team190/robot/Robot.java new file mode 100755 index 0000000000..f20f6562d5 --- /dev/null +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/AdvancedVision/src/org/usfirst/frc/team190/robot/Robot.java @@ -0,0 +1,53 @@ +package $package; + +import com.ni.vision.NIVision; +import com.ni.vision.NIVision.DrawMode; +import com.ni.vision.NIVision.Image; +import com.ni.vision.NIVision.ShapeMode; +import edu.wpi.first.wpilibj.SampleRobot; + +/** + * This is a demo program showing the use of the NIVision class to do vision processing. + * The image is acquired from the USB Webcam, then a circle is overlayed on it. + * The NIVision class supplies dozens of methods for different types of processing. + * The resulting image can then be sent to the FRC PC Dashboard with setImage() + */ +public class Robot extends SampleRobot { + int session; + Image frame; + + public void robotInit() { + + frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); + + /** + * the camera name (ex "cam1") can be found through the roborio web interface + */ + session = NIVision.IMAQdxOpenCamera("cam1", + NIVision.IMAQdxCameraControlMode.CameraControlModeController); + NIVision.IMAQdxConfigureGrab(session); + } + + public void operatorControl() { + NIVision.IMAQdxStartAcquisition(session); + + /** + * grab an image, draw the circle, and provide it for the camera server + * which will in turn send it to the dashboard. + */ + NIVision.Rect rect = new NIVision.Rect(10, 10, 100, 100); + + while (isOperatorControl() && isEnabled()) { + + NIVision.IMAQdxGrab(session, frame, 1); + NIVision.imaqDrawShapeOnImage(frame, frame, rect, + DrawMode.DRAW_VALUE, ShapeMode.SHAPE_OVAL, 0.0f); + + CameraServer.getInstance().setImage(frame); + } + NIVision.IMAQdxStopAcquisition(session); + } + + public void test() { + } +} diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/QuickVision/src/org/usfirst/frc/team190/robot/Robot.java b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/QuickVision/src/org/usfirst/frc/team190/robot/Robot.java new file mode 100755 index 0000000000..2faf0180a9 --- /dev/null +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/QuickVision/src/org/usfirst/frc/team190/robot/Robot.java @@ -0,0 +1,35 @@ +package $package; + +import edu.wpi.first.wpilibj.SampleRobot; +import edu.wpi.first.wpilibj.RobotDrive; +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.Timer; + +/** + * This is a demo program showing the use of the CameraServer class. + * With start automatic capture, there is no opertunity to process the image. + * Look at the AdvancedVision sample for how to process the image before sending it to the FRC PC Dashboard. + */ +public class Robot extends SampleRobot { + + CameraServer server; + + public Robot() { + server = CameraServer.getInstance(); + server.setQuality(50); + } + + /** + * start up automatic capture you should see the video stream from the + * webcam in your FRC PC Dashboard. + */ + public void operatorControl() { + + server.startAutomaticCapture("cam1"); + + while (isOperatorControl() && isEnabled()) { + /** robot code here! **/ + } + } + +} \ No newline at end of file diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml index 483fa383b0..7f450933d1 100755 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.java/resources/templates/examples/examples.xml @@ -81,6 +81,11 @@ Example programs that demonstrate the use of the various commonly used sensors on FRC robots + + Vision + Example programs that demonstrate the use of USB Cameras and image processing + + Getting Started An example program which demonstrates the simplest autonomous and @@ -287,4 +292,35 @@ destination="src/$package-dir/triggers/DoubleButton.java"> + + + Quick Vision + Demonstrate the use of the CameraServer class to stream from a USB Webcam without processing the images. + + Vision + + + src/$package-dir + + + + + + + + Advanced Vision + Demonstrate the use of the NIVision class to capture image from a Webcam, process them, and then send them to the dashboard. + + Vision + + + src/$package-dir + + + + + +