From 42ff123fea0f9fb8ed0c40ce2c3e21b64ff4bbf0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 9 Mar 2016 05:39:28 -0500 Subject: Clean up extensions. Renaming, code de-duplication --- .../ExampleSquareTrackerExtension/Square.pdf | Bin 0 -> 79845 bytes extensions/ExampleSquareTrackerExtension/build.xml | 74 ++ .../lib/SmartDashboard.jar | 1 + .../lib/WPIJavaCV.jar | 1 + .../lib/WPIJavaCVVideoExtension.jar | 1 + .../ExampleSquareTrackerExtension/lib/javacpp.jar | 1 + .../lib/javacv-windows-x86.jar | 1 + .../ExampleSquareTrackerExtension/lib/javacv.jar | 1 + .../ExampleSquareTrackerExtension/manifest.mf | 3 + .../nbproject/build-impl.xml | 1400 ++++++++++++++++++++ .../nbproject/genfiles.properties | 8 + .../nbproject/private/config.properties | 0 .../nbproject/private/private.properties | 6 + .../nbproject/private/private.xml | 4 + .../nbproject/project.properties | 87 ++ .../nbproject/project.xml | 49 + .../extensions/squaretracker/Square.pdf | Bin 0 -> 79845 bytes .../squaretracker/SquareTrackerExtension.java | 119 ++ 18 files changed, 1756 insertions(+) create mode 100644 extensions/ExampleSquareTrackerExtension/Square.pdf create mode 100644 extensions/ExampleSquareTrackerExtension/build.xml create mode 120000 extensions/ExampleSquareTrackerExtension/lib/SmartDashboard.jar create mode 120000 extensions/ExampleSquareTrackerExtension/lib/WPIJavaCV.jar create mode 120000 extensions/ExampleSquareTrackerExtension/lib/WPIJavaCVVideoExtension.jar create mode 120000 extensions/ExampleSquareTrackerExtension/lib/javacpp.jar create mode 120000 extensions/ExampleSquareTrackerExtension/lib/javacv-windows-x86.jar create mode 120000 extensions/ExampleSquareTrackerExtension/lib/javacv.jar create mode 100644 extensions/ExampleSquareTrackerExtension/manifest.mf create mode 100644 extensions/ExampleSquareTrackerExtension/nbproject/build-impl.xml create mode 100644 extensions/ExampleSquareTrackerExtension/nbproject/genfiles.properties create mode 100644 extensions/ExampleSquareTrackerExtension/nbproject/private/config.properties create mode 100644 extensions/ExampleSquareTrackerExtension/nbproject/private/private.properties create mode 100644 extensions/ExampleSquareTrackerExtension/nbproject/private/private.xml create mode 100644 extensions/ExampleSquareTrackerExtension/nbproject/project.properties create mode 100644 extensions/ExampleSquareTrackerExtension/nbproject/project.xml create mode 100644 extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/Square.pdf create mode 100644 extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/SquareTrackerExtension.java (limited to 'extensions/ExampleSquareTrackerExtension') diff --git a/extensions/ExampleSquareTrackerExtension/Square.pdf b/extensions/ExampleSquareTrackerExtension/Square.pdf new file mode 100644 index 0000000..23cb55e Binary files /dev/null and b/extensions/ExampleSquareTrackerExtension/Square.pdf differ diff --git a/extensions/ExampleSquareTrackerExtension/build.xml b/extensions/ExampleSquareTrackerExtension/build.xml new file mode 100644 index 0000000..ec4a616 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ExampleSquareTrackerExtension. + + + diff --git a/extensions/ExampleSquareTrackerExtension/lib/SmartDashboard.jar b/extensions/ExampleSquareTrackerExtension/lib/SmartDashboard.jar new file mode 120000 index 0000000..5e4bb39 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/lib/SmartDashboard.jar @@ -0,0 +1 @@ +../../../../wpilib/tools/SmartDashboard.jar \ No newline at end of file diff --git a/extensions/ExampleSquareTrackerExtension/lib/WPIJavaCV.jar b/extensions/ExampleSquareTrackerExtension/lib/WPIJavaCV.jar new file mode 120000 index 0000000..8e0d6df --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/lib/WPIJavaCV.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/dist/WPIJavaCV.jar \ No newline at end of file diff --git a/extensions/ExampleSquareTrackerExtension/lib/WPIJavaCVVideoExtension.jar b/extensions/ExampleSquareTrackerExtension/lib/WPIJavaCVVideoExtension.jar new file mode 120000 index 0000000..a8bc1b6 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/lib/WPIJavaCVVideoExtension.jar @@ -0,0 +1 @@ +../../WPIJavaCVVideoExtension/dist/WPIJavaCVVideoExtension.jar \ No newline at end of file diff --git a/extensions/ExampleSquareTrackerExtension/lib/javacpp.jar b/extensions/ExampleSquareTrackerExtension/lib/javacpp.jar new file mode 120000 index 0000000..b13cc4d --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/lib/javacpp.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/lib/javacpp.jar \ No newline at end of file diff --git a/extensions/ExampleSquareTrackerExtension/lib/javacv-windows-x86.jar b/extensions/ExampleSquareTrackerExtension/lib/javacv-windows-x86.jar new file mode 120000 index 0000000..438dd95 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/lib/javacv-windows-x86.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/lib/javacv-windows-x86.jar \ No newline at end of file diff --git a/extensions/ExampleSquareTrackerExtension/lib/javacv.jar b/extensions/ExampleSquareTrackerExtension/lib/javacv.jar new file mode 120000 index 0000000..06ad26d --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/lib/javacv.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/lib/javacv.jar \ No newline at end of file diff --git a/extensions/ExampleSquareTrackerExtension/manifest.mf b/extensions/ExampleSquareTrackerExtension/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/extensions/ExampleSquareTrackerExtension/nbproject/build-impl.xml b/extensions/ExampleSquareTrackerExtension/nbproject/build-impl.xml new file mode 100644 index 0000000..5a9f0e1 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/nbproject/build-impl.xml @@ -0,0 +1,1400 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/ExampleSquareTrackerExtension/nbproject/genfiles.properties b/extensions/ExampleSquareTrackerExtension/nbproject/genfiles.properties new file mode 100644 index 0000000..b58eb40 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0e31bf96 +build.xml.script.CRC32=fe93e624 +build.xml.stylesheet.CRC32=28e38971@1.38.3.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0e31bf96 +nbproject/build-impl.xml.script.CRC32=1f2b204c +nbproject/build-impl.xml.stylesheet.CRC32=229523de@1.38.3.45 diff --git a/extensions/ExampleSquareTrackerExtension/nbproject/private/config.properties b/extensions/ExampleSquareTrackerExtension/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/extensions/ExampleSquareTrackerExtension/nbproject/private/private.properties b/extensions/ExampleSquareTrackerExtension/nbproject/private/private.properties new file mode 100644 index 0000000..7b67f1f --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=false +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Paul\\.netbeans\\6.9\\build.properties diff --git a/extensions/ExampleSquareTrackerExtension/nbproject/private/private.xml b/extensions/ExampleSquareTrackerExtension/nbproject/private/private.xml new file mode 100644 index 0000000..cc2c0e5 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/extensions/ExampleSquareTrackerExtension/nbproject/project.properties b/extensions/ExampleSquareTrackerExtension/nbproject/project.properties new file mode 100644 index 0000000..59422cf --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/nbproject/project.properties @@ -0,0 +1,87 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ExampleSquareTrackerExtension +application.vendor=Greg +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ExampleSquareTrackerExtension.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.javacpp.jar=lib/javacpp.jar +file.reference.javacv-windows-x86.jar=lib/javacv-windows-x86.jar +file.reference.javacv.jar=lib/javacv.jar +file.reference.NetworkTable_Client.jar=lib/NetworkTable_Client.jar +file.reference.SmartDashboard.jar=lib/SmartDashboard.jar +file.reference.WPIJavaCVVideoExtension.jar=lib/WPIJavaCVVideoExtension.jar +file.reference.WPIJavaCV.jar=lib/WPIJavaCV.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.WPIJavaCV.jar}:\ + ${file.reference.WPIJavaCVVideoExtension.jar}:\ + ${file.reference.SmartDashboard.jar}:\ + ${file.reference.NetworkTable_Client.jar}:\ + ${file.reference.javacpp.jar}:\ + ${file.reference.javacv-windows-x86.jar}:\ + ${file.reference.javacv.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=squaretrackerextension.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/extensions/ExampleSquareTrackerExtension/nbproject/project.xml b/extensions/ExampleSquareTrackerExtension/nbproject/project.xml new file mode 100644 index 0000000..ead182e --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/nbproject/project.xml @@ -0,0 +1,49 @@ + + + org.netbeans.modules.java.j2seproject + + + ExampleSquareTrackerExtension + + + + + + + + + + NetworkTable_Client + jar + + jar + clean + jar + + + SmartDashboard + jar + + jar + clean + jar + + + WPICameraExtension + jar + + jar + clean + jar + + + WPIJavaCV + jar + + jar + clean + jar + + + + diff --git a/extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/Square.pdf b/extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/Square.pdf new file mode 100644 index 0000000..23cb55e Binary files /dev/null and b/extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/Square.pdf differ diff --git a/extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/SquareTrackerExtension.java b/extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/SquareTrackerExtension.java new file mode 100644 index 0000000..a9361d3 --- /dev/null +++ b/extensions/ExampleSquareTrackerExtension/src/edu/wpi/first/smartdashboard/extensions/squaretracker/SquareTrackerExtension.java @@ -0,0 +1,119 @@ +package edu.wpi.first.smartdashboard.extensions.squaretracker; + +import edu.wpi.first.smartdashboard.extensions.wpijavacvvideo.LaptopCameraExtension; +import edu.wpi.first.smartdashboard.robot.Robot; +import edu.wpi.first.wpijavacv.WPIBinaryImage; +import edu.wpi.first.wpijavacv.WPIColor; +import edu.wpi.first.wpijavacv.WPIColorImage; +import edu.wpi.first.wpijavacv.WPIContour; +import edu.wpi.first.wpijavacv.WPIImage; +import edu.wpi.first.wpijavacv.WPIPoint; +import edu.wpi.first.wpijavacv.WPIPolygon; +import edu.wpi.first.wpilibj.networking.NetworkTable; +import java.util.ArrayList; + +/** + * + * @author Greg Granito + */ +public class SquareTrackerExtension extends LaptopCameraExtension { + public static final String NAME = "Laptop Camera Square Tracker"; + + /* Uses the table to send information from the DS to the robot */ + NetworkTable table = NetworkTable.getTable("camera"); + WPIColor targetColor = new WPIColor(255, 0, 0); + + @Override + public WPIImage processImage(WPIColorImage rawImage) { + + WPIBinaryImage blueBin = rawImage.getBlueChannel().getThresholdInverted(60); + WPIBinaryImage greenBin = rawImage.getGreenChannel().getThresholdInverted(60); + WPIBinaryImage redBin = rawImage.getRedChannel().getThresholdInverted(60); + + WPIBinaryImage finalBin = blueBin.getAnd(redBin).getAnd(greenBin); + + finalBin.erode(2); + finalBin.dilate(6); + + WPIContour[] contours = finalBin.findContours(); + + ArrayList polygons = new ArrayList(); + + for(WPIContour c : contours){ + double ratio = ((double)c.getHeight()) / ((double)c.getWidth()); + if(ratio < 1.5 && ratio> 0.75){ + polygons.add(c.approxPolygon(45)); + } + } + + ArrayList possiblePolygons = new ArrayList(); + + for(WPIPolygon p : polygons){ + if(p.isConvex() && p.getNumVertices() == 4){ + possiblePolygons.add(p); + }else{ + rawImage.drawPolygon(p, WPIColor.CYAN, 5); + } + } + + WPIPolygon square = null; + int squareArea = 0; + + for(WPIPolygon p : possiblePolygons){ + rawImage.drawPolygon(p, WPIColor.GREEN, 5); + for(WPIPolygon q : possiblePolygons){ + if(p == q) continue; + + int pCenterX = (p.getX() + (p.getWidth()/2)); + + int qCenterX = q.getX() + (q.getWidth()/2); + + int pCenterY = (p.getY() + (p.getHeight()/2)); + + int qCenterY = q.getY() + (q.getHeight()/2); + + rawImage.drawPoint(new WPIPoint(pCenterX, pCenterY), targetColor, 5); + rawImage.drawPoint(new WPIPoint(qCenterX, qCenterY), targetColor, 5); + + if(Math.abs(pCenterX - qCenterX) < 20 && + Math.abs(pCenterY - qCenterY) < 20){ + int pArea = Math.abs(p.getArea()); + int qArea = Math.abs(q.getArea()); + if(pArea > qArea){ + square = p; + squareArea = pArea; + }else{ + square = q; + squareArea = qArea; + } + break; + } + } + } + + if(square != null){ + double x = square.getX() + (square.getWidth()/2); + x = (2 * (x/rawImage.getWidth())) - 1; + + double area = ((double)squareArea) / ((double)(rawImage.getWidth() * rawImage.getHeight())); + + synchronized(table) { + table.beginTransaction(); + table.putBoolean("found", true); + table.putDouble("x", x); + table.putDouble("area", area); + table.endTransaction(); + } + + Robot.getTable().putBoolean("found", true); + Robot.getTable().putDouble("X", x); + Robot.getTable().putDouble("Area", area); + rawImage.drawPolygon(square, targetColor, 7); + }else{ + table.putBoolean("found", false); + Robot.getTable().putBoolean("found", false); + } + + return rawImage; + } +} -- cgit v1.2.3-54-g00ecf