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 --- extensions/WPIJavaCVVideoExtension/build.xml | 74 ++ .../WPIJavaCVVideoExtension/lib/SmartDashboard.jar | 1 + .../WPIJavaCVVideoExtension/lib/WPIJavaCV.jar | 1 + extensions/WPIJavaCVVideoExtension/lib/javacpp.jar | 1 + .../lib/javacv-windows-x86.jar | 1 + extensions/WPIJavaCVVideoExtension/lib/javacv.jar | 1 + extensions/WPIJavaCVVideoExtension/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 | 96 ++ .../WPIJavaCVVideoExtension/nbproject/project.xml | 16 + .../wpijavacvvideo/AbstractVideoExtension.java | 166 +++ .../wpijavacvvideo/AxisCameraExtension.java | 51 + .../wpijavacvvideo/LaptopCameraExtension.java | 39 + .../extensions/wpijavacvvideo/Video.java | 13 + .../wpijavacvvideo/VideoURLExtension.java | 50 + 19 files changed, 1931 insertions(+) create mode 100644 extensions/WPIJavaCVVideoExtension/build.xml create mode 120000 extensions/WPIJavaCVVideoExtension/lib/SmartDashboard.jar create mode 120000 extensions/WPIJavaCVVideoExtension/lib/WPIJavaCV.jar create mode 120000 extensions/WPIJavaCVVideoExtension/lib/javacpp.jar create mode 120000 extensions/WPIJavaCVVideoExtension/lib/javacv-windows-x86.jar create mode 120000 extensions/WPIJavaCVVideoExtension/lib/javacv.jar create mode 100644 extensions/WPIJavaCVVideoExtension/manifest.mf create mode 100644 extensions/WPIJavaCVVideoExtension/nbproject/build-impl.xml create mode 100644 extensions/WPIJavaCVVideoExtension/nbproject/genfiles.properties create mode 100644 extensions/WPIJavaCVVideoExtension/nbproject/private/config.properties create mode 100644 extensions/WPIJavaCVVideoExtension/nbproject/private/private.properties create mode 100644 extensions/WPIJavaCVVideoExtension/nbproject/private/private.xml create mode 100644 extensions/WPIJavaCVVideoExtension/nbproject/project.properties create mode 100644 extensions/WPIJavaCVVideoExtension/nbproject/project.xml create mode 100644 extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AbstractVideoExtension.java create mode 100644 extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AxisCameraExtension.java create mode 100644 extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/LaptopCameraExtension.java create mode 100644 extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/Video.java create mode 100644 extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/VideoURLExtension.java (limited to 'extensions/WPIJavaCVVideoExtension') diff --git a/extensions/WPIJavaCVVideoExtension/build.xml b/extensions/WPIJavaCVVideoExtension/build.xml new file mode 100644 index 0000000..27d6203 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project WPIJavaCVVideoExtension. + + + diff --git a/extensions/WPIJavaCVVideoExtension/lib/SmartDashboard.jar b/extensions/WPIJavaCVVideoExtension/lib/SmartDashboard.jar new file mode 120000 index 0000000..5e4bb39 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/lib/SmartDashboard.jar @@ -0,0 +1 @@ +../../../../wpilib/tools/SmartDashboard.jar \ No newline at end of file diff --git a/extensions/WPIJavaCVVideoExtension/lib/WPIJavaCV.jar b/extensions/WPIJavaCVVideoExtension/lib/WPIJavaCV.jar new file mode 120000 index 0000000..8e0d6df --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/lib/WPIJavaCV.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/dist/WPIJavaCV.jar \ No newline at end of file diff --git a/extensions/WPIJavaCVVideoExtension/lib/javacpp.jar b/extensions/WPIJavaCVVideoExtension/lib/javacpp.jar new file mode 120000 index 0000000..b13cc4d --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/lib/javacpp.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/lib/javacpp.jar \ No newline at end of file diff --git a/extensions/WPIJavaCVVideoExtension/lib/javacv-windows-x86.jar b/extensions/WPIJavaCVVideoExtension/lib/javacv-windows-x86.jar new file mode 120000 index 0000000..438dd95 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/lib/javacv-windows-x86.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/lib/javacv-windows-x86.jar \ No newline at end of file diff --git a/extensions/WPIJavaCVVideoExtension/lib/javacv.jar b/extensions/WPIJavaCVVideoExtension/lib/javacv.jar new file mode 120000 index 0000000..06ad26d --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/lib/javacv.jar @@ -0,0 +1 @@ +../../../WPIJavaCV/lib/javacv.jar \ No newline at end of file diff --git a/extensions/WPIJavaCVVideoExtension/manifest.mf b/extensions/WPIJavaCVVideoExtension/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/extensions/WPIJavaCVVideoExtension/nbproject/build-impl.xml b/extensions/WPIJavaCVVideoExtension/nbproject/build-impl.xml new file mode 100644 index 0000000..e46d053 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/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/WPIJavaCVVideoExtension/nbproject/genfiles.properties b/extensions/WPIJavaCVVideoExtension/nbproject/genfiles.properties new file mode 100644 index 0000000..35733b3 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0d2b3442 +build.xml.script.CRC32=f9e70049 +build.xml.stylesheet.CRC32=28e38971@1.53.1.46 +# 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=0d2b3442 +nbproject/build-impl.xml.script.CRC32=55f5fbcf +nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 diff --git a/extensions/WPIJavaCVVideoExtension/nbproject/private/config.properties b/extensions/WPIJavaCVVideoExtension/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/extensions/WPIJavaCVVideoExtension/nbproject/private/private.properties b/extensions/WPIJavaCVVideoExtension/nbproject/private/private.properties new file mode 100644 index 0000000..bb21662 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/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\\Mitchell Wills\\AppData\\Roaming\\NetBeans\\7.2\\build.properties diff --git a/extensions/WPIJavaCVVideoExtension/nbproject/private/private.xml b/extensions/WPIJavaCVVideoExtension/nbproject/private/private.xml new file mode 100644 index 0000000..cc2c0e5 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/extensions/WPIJavaCVVideoExtension/nbproject/project.properties b/extensions/WPIJavaCVVideoExtension/nbproject/project.properties new file mode 100644 index 0000000..7459bfb --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/nbproject/project.properties @@ -0,0 +1,96 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=WPIJavaCVVideoExtension +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}/WPIJavaCVVideoExtension.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.SmartDashboard.jar=lib/SmartDashboard.jar +file.reference.WPIJavaCV.jar=lib/WPIJavaCV.jar +includes=** +jar.archive.disabled=${jnlp.enabled} +jar.compress=false +jar.index=${jnlp.enabled} +javac.classpath=\ + ${file.reference.WPIJavaCV.jar}:\ + ${file.reference.SmartDashboard.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= +jnlp.codebase.type=no.codebase +jnlp.descriptor=application +jnlp.enabled=false +jnlp.mixed.code=default +jnlp.offline-allowed=false +jnlp.signed=false +jnlp.signing= +jnlp.signing.alias= +jnlp.signing.keystore= +main.class= +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +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/WPIJavaCVVideoExtension/nbproject/project.xml b/extensions/WPIJavaCVVideoExtension/nbproject/project.xml new file mode 100644 index 0000000..32fd950 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + WPIJavaCVVideoExtension + + + + + + + + + + diff --git a/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AbstractVideoExtension.java b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AbstractVideoExtension.java new file mode 100644 index 0000000..9324232 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AbstractVideoExtension.java @@ -0,0 +1,166 @@ +package edu.wpi.first.smartdashboard.extensions.wpijavacvvideo; + +import edu.wpi.first.smartdashboard.gui.DashboardPrefs; +import edu.wpi.first.smartdashboard.gui.StaticWidget; +import edu.wpi.first.smartdashboard.properties.Property; +import edu.wpi.first.smartdashboard.properties.StringProperty; +import edu.wpi.first.wpijavacv.WPIColorImage; +import edu.wpi.first.wpijavacv.WPIFFmpegVideo; +import edu.wpi.first.wpijavacv.WPIGrayscaleImage; +import edu.wpi.first.wpijavacv.WPIImage; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.image.BufferedImage; + +/** + * An extension that displays a video. + * + * @author Greg Granito + * @author Luke Shumaker + */ +public abstract class AbstractVideoExtension extends StaticWidget { + public static final String NAME = null; + protected static final long errorBackoff = -1; + abstract protected Video getVideo(); + abstract protected boolean isVideoProperty(Property property); + + private boolean connected = false; + + public class GCThread extends Thread { + + boolean destroyed = false; + + @Override + public void run() { + while (!destroyed) { + try { + Thread.sleep(10000); + } catch (InterruptedException ex) { + } + System.gc(); + } + } + + public void destroy() { + destroyed = true; + interrupt(); + } + } + + public class BGThread extends Thread { + + boolean destroyed = false; + + public BGThread() { + super(NAME+" Background"); + } + + @Override + public void run() { + WPIImage image; + while (!destroyed) { + if (vid == null) { + vid = getVideo(); + } + try { + image = vid.getImage(); + + if (image instanceof WPIColorImage) { + drawnImage = processImage((WPIColorImage) image).getBufferedImage(); + } else if (image instanceof WPIGrayscaleImage) { + drawnImage = processImage((WPIGrayscaleImage) image).getBufferedImage(); + } + + repaint(); + } catch (final Exception e) { + e.printStackTrace(); + vid.dispose(); + vid = null; + drawnImage = null; + repaint(); + try { + Thread.sleep(errorBackoff); + } catch (InterruptedException ex) { + } + } + } + + } + + @Override + public void destroy() { + destroyed = true; + } + } + private boolean resized = false; + private Video vid; + private BufferedImage drawnImage; + private BGThread bgThread = new BGThread(); + private GCThread gcThread = new GCThread(); + + @Override + public void init() { + setPreferredSize(new Dimension(100, 100)); + bgThread.start(); + gcThread.start(); + revalidate(); + repaint(); + } + + @Override + public void propertyChanged(Property property) { + if (isVideoProperty(property)) { + if (vid != null) { + vid.dispose(); + } + try { + vid = getVideo(); + } catch (Exception e) { + e.printStackTrace(); + drawnImage = null; + setPreferredSize(new Dimension(100, 100)); + revalidate(); + repaint(); + } + } + + } + + @Override + public void disconnect() { + bgThread.destroy(); + gcThread.destroy(); + if(vid != null) vid.dispose(); + super.disconnect(); + } + + @Override + protected void paintComponent(Graphics g) { + if (drawnImage != null) { + if (!resized) { + setPreferredSize(new Dimension(drawnImage.getWidth(), drawnImage.getHeight())); + revalidate(); + } + int width = getBounds().width; + int height = getBounds().height; + double scale = Math.min((double) width / (double) drawnImage.getWidth(), (double) height / (double) drawnImage.getHeight()); + g.drawImage(drawnImage, (int) (width - (scale * drawnImage.getWidth())) / 2, (int) (height - (scale * drawnImage.getHeight())) / 2, + (int) ((width + scale * drawnImage.getWidth()) / 2), (int) (height + scale * drawnImage.getHeight()) / 2, + 0, 0, drawnImage.getWidth(), drawnImage.getHeight(), null); + } else { + g.setColor(Color.PINK); + g.fillRect(0, 0, getBounds().width, getBounds().height); + g.setColor(Color.BLACK); + g.drawString("NO CONNECTION", 10, 10); + } + } + + public WPIImage processImage(WPIColorImage rawImage) { + return rawImage; + } + + public WPIImage processImage(WPIGrayscaleImage rawImage) { + return rawImage; + } +} diff --git a/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AxisCameraExtension.java b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AxisCameraExtension.java new file mode 100644 index 0000000..6851dfc --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/AxisCameraExtension.java @@ -0,0 +1,51 @@ +package edu.wpi.first.smartdashboard.extensions.wpijavacvvideo; + +import edu.wpi.first.smartdashboard.gui.DashboardPrefs; +import edu.wpi.first.smartdashboard.properties.IPAddressProperty; +import edu.wpi.first.smartdashboard.properties.Property; +import edu.wpi.first.wpijavacv.WPICamera; +import edu.wpi.first.wpijavacv.WPIImage; + +/** + * Exactly like VideoURLExtension, except it forces the Stream URL + * to be of the form "http://${IP_address}/mjpg/video.mjpg" and only + * lets the user configure the IP address. + * + * @author Greg Granito + */ +public class AxisCameraExtension extends AbstractVideoExtension { + public static final String NAME = "Axis Camera"; + protected static final long errorBackoff = 2000; + + @Override + protected Video getVideo() { + return new Camera(new WPICamera(ipProperty.getSaveValue()), 5.0); + } + + @Override + protected boolean isVideoProperty(Property property) { + return property == ipProperty; + } + + public final IPAddressProperty ipProperty = new IPAddressProperty(this, "Axis Camera IP Address", defaultIPaddress()); + + private final int[] defaultIPaddress() { + final int team = DashboardPrefs.getInstance().team.getValue(); + return new int[]{10, team / 100, team % 100, 11}; + } + + public class Camera implements Video { + private final WPICamera vid; + private final double timeout; + public Camera(WPICamera vid, double timeout){ + this.vid = vid; + this.timeout = timeout; + } + public WPIImage getImage() throws Exception { + return vid.getNewImage(timeout); + } + public void dispose() { + vid.dispose(); + } + } +} diff --git a/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/LaptopCameraExtension.java b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/LaptopCameraExtension.java new file mode 100644 index 0000000..03fa943 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/LaptopCameraExtension.java @@ -0,0 +1,39 @@ +package edu.wpi.first.smartdashboard.extensions.wpijavacvvideo; + +import edu.wpi.first.smartdashboard.properties.Property; +import edu.wpi.first.wpijavacv.WPIImage; +import edu.wpi.first.wpijavacv.WPILaptopCamera; + +/** + * An extension that displays the laptop built-in camera. + * + * @author Greg Granito + * @author Luke Shumaker + */ +public class LaptopCameraExtension extends AbstractVideoExtension { + public static final String NAME = "Laptop Camera"; + protected static final long errorBackoff = 500; + + @Override + protected Video getVideo() { + return new Camera(new WPILaptopCamera()); + } + + @Override + protected boolean isVideoProperty(Property property) { + return false; + } + + public class Camera implements Video { + private final WPILaptopCamera vid; + public Camera(WPILaptopCamera vid){ + this.vid = vid; + } + public WPIImage getImage() { + return vid.getCurrentFrame(); + } + public void dispose() { + vid.dispose(); + } + } +} diff --git a/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/Video.java b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/Video.java new file mode 100644 index 0000000..8187701 --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/Video.java @@ -0,0 +1,13 @@ +package edu.wpi.first.smartdashboard.extensions.wpijavacvvideo; + +import edu.wpi.first.wpijavacv.WPIImage; + +/** + * The basics of what you need out of a video source. + * + * @author Luke Shumaker + */ +public interface Video { + public WPIImage getImage() throws Exception; + public void dispose(); +} diff --git a/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/VideoURLExtension.java b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/VideoURLExtension.java new file mode 100644 index 0000000..bbe4d6b --- /dev/null +++ b/extensions/WPIJavaCVVideoExtension/src/edu/wpi/first/smartdashboard/extensions/wpijavacvvideo/VideoURLExtension.java @@ -0,0 +1,50 @@ +package edu.wpi.first.smartdashboard.extensions.wpijavacvvideo; + +import edu.wpi.first.smartdashboard.gui.DashboardPrefs; +import edu.wpi.first.smartdashboard.properties.Property; +import edu.wpi.first.smartdashboard.properties.StringProperty; +import edu.wpi.first.wpijavacv.WPIFFmpegVideo; +import edu.wpi.first.wpijavacv.WPIImage; + +/** + * An extension that takes a video stream URL and displays the video. + * + * @author Greg Granito + * @author Luke Shumaker + */ +public class VideoURLExtension extends AbstractVideoExtension { + public static final String NAME = "Video URL Stream"; + protected static final long errorBackoff = 2000; + + @Override + protected Video getVideo() { + return new Camera(new WPIFFmpegVideo(pathProperty.getSaveValue()), 5.0); + } + + @Override + protected boolean isVideoProperty(Property property) { + return property == pathProperty; + } + + public final StringProperty pathProperty = new StringProperty(this, "Video Path", defaultVideoPath()); + + private static String defaultVideoPath() { + final int team = DashboardPrefs.getInstance().team.getValue(); + return "http://10." + (team / 100) + "." + (team % 100) + ".11/mjpg/video.mjpg"; + } + + public class Camera implements Video { + private final WPIFFmpegVideo vid; + private final double timeout; + public Camera(WPIFFmpegVideo vid, double timeout){ + this.vid = vid; + this.timeout = timeout; + } + public WPIImage getImage() throws Exception { + return vid.getNewImage(timeout); + } + public void dispose() { + vid.dispose(); + } + } +} -- cgit v1.2.3-54-g00ecf