Skip to content

Commit

Permalink
Add few examples, change MJPEG streamer
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Aug 11, 2013
1 parent 089fff8 commit ae310af
Show file tree
Hide file tree
Showing 15 changed files with 499 additions and 198 deletions.
8 changes: 7 additions & 1 deletion webcam-capture-addons/webcam-capture-addon-spycam/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" path="src/main/php"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/example/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
Expand Down
41 changes: 30 additions & 11 deletions webcam-capture-drivers/webcam-capture-driver-gstreamer/.classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" path="src/etc/licenses"/>
<classpathentry kind="src" path="src/example/java"/>
<classpathentry kind="src" path="src/example/resources"/>
<classpathentry kind="src" path="src/etc/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/etc/licenses"/>
<classpathentry kind="src" path="src/example/java"/>
<classpathentry kind="src" path="src/example/resources"/>
<classpathentry kind="src" path="src/etc/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.ds.gstreamer.GStreamerDriver;


/**
* Example of how to take single picture.
*
* @author Bartosz Firyn (SarXos)
*/
public class TakePictureExample2 {

static {
Webcam.setDriver(new GStreamerDriver());
}

public static void main(String[] args) {

final Webcam webcam = Webcam.getDefault();
webcam.open();

JFrame window = new JFrame();
JButton button = new JButton(new AbstractAction("Take Snapshot Now") {

private static final long serialVersionUID = 1L;

@Override
public void actionPerformed(ActionEvent e) {
try {
String name = String.format("test-%d.jpg", System.currentTimeMillis());
ImageIO.write(webcam.getImage(), "JPG", new File(name));
System.out.format("File %s has been saved\n", name);
} catch (IOException t) {
t.printStackTrace();
}
}
});

window.add(button);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.sarxos.webcam;

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

import com.github.sarxos.webcam.ds.openimaj.OpenImajDriver;


/**
* Example of how to take single picture.
*
* @author Bartosz Firyn (SarXos)
*/
public class TakePictureExample2 {

static {
Webcam.setDriver(new OpenImajDriver());
}

public static void main(String[] args) {

final Webcam webcam = Webcam.getDefault();
webcam.open();

JFrame window = new JFrame();
JButton button = new JButton(new AbstractAction("Take Snapshot Now") {

private static final long serialVersionUID = 1L;

@Override
public void actionPerformed(ActionEvent e) {
try {
String name = String.format("test-%d.jpg", System.currentTimeMillis());
ImageIO.write(webcam.getImage(), "JPG", new File(name));
System.out.format("File %s has been saved\n", name);
} catch (IOException t) {
t.printStackTrace();
}
}
});

window.add(button);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.sarxos.webcam;

import javax.swing.JFrame;

import com.github.sarxos.webcam.ds.openimaj.OpenImajDriver;


public class WebcamPanelExample {

static {
Webcam.setDriver(new OpenImajDriver());
}

public static void main(String[] args) throws InterruptedException {

Webcam webcam = Webcam.getDefault();

WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);

JFrame window = new JFrame("Test webcam panel");
window.add(panel);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
}
}
6 changes: 6 additions & 0 deletions webcam-capture-drivers/webcam-capture-driver-v4l4j/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
</classpathentry>
<classpathentry kind="src" path="src/example/java"/>
<classpathentry kind="src" path="src/example/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.ds.v4l4j.V4l4jDriver;


/**
* Example of how to take single picture.
*
* @author Bartosz Firyn (SarXos)
*/
public class TakePictureExample2 {

static {
Webcam.setDriver(new V4l4jDriver());
}

public static void main(String[] args) {

final Webcam webcam = Webcam.getDefault();
webcam.open();

JFrame window = new JFrame();
JButton button = new JButton(new AbstractAction("Take Snapshot Now") {

private static final long serialVersionUID = 1L;

@Override
public void actionPerformed(ActionEvent e) {
try {
String name = String.format("test-%d.jpg", System.currentTimeMillis());
ImageIO.write(webcam.getImage(), "JPG", new File(name));
System.out.format("File %s has been saved\n", name);
} catch (IOException t) {
t.printStackTrace();
}
}
});

window.add(button);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);

}
}
13 changes: 12 additions & 1 deletion webcam-capture-examples/webcam-capture-live-streaming/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public CustomPainterExample() {
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(new Color(0, 0, 0, 0));
setPreferredSize(new Dimension(370, 497));
// setPreferredSize(new Dimension(370, 497));

menu = new JMenuBar();
menu.add(filterMenu);
Expand Down
15 changes: 15 additions & 0 deletions webcam-capture/src/example/java/MjpegStreamingExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamStreamer;


public class MjpegStreamingExample {

public static void main(String[] args) throws InterruptedException {
Webcam w = Webcam.getDefault();
new WebcamStreamer(8080, w, 0.5, true);
do {
Thread.sleep(5000);
} while (true);
}

}
8 changes: 4 additions & 4 deletions webcam-capture/src/example/java/TakePictureExample.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
Expand All @@ -18,11 +17,12 @@ public class TakePictureExample {

public static void main(String[] args) throws IOException {

// automatically open if webcam is closed
Webcam.setAutoOpenMode(true);
// get default webcam and open it
Webcam webcam = Webcam.getDefault();
webcam.open();

// get image
BufferedImage image = Webcam.getDefault().getImage();
BufferedImage image = webcam.getImage();

// save image to PNG file
ImageIO.write(image, "PNG", new File("test.png"));
Expand Down
49 changes: 49 additions & 0 deletions webcam-capture/src/example/java/TakePictureExample2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;


/**
* Example of how to take single picture on button press.
*
* @author Bartosz Firyn (SarXos)
*/
public class TakePictureExample2 {

public static void main(String[] args) {

final Webcam webcam = Webcam.getDefault();
webcam.open();

JFrame window = new JFrame();
JButton button = new JButton(new AbstractAction("Take Snapshot Now") {

private static final long serialVersionUID = 1L;

@Override
public void actionPerformed(ActionEvent e) {
try {
String name = String.format("test-%d.jpg", System.currentTimeMillis());
ImageIO.write(webcam.getImage(), "JPG", new File(name));
System.out.format("File %s has been saved\n", name);
} catch (IOException t) {
t.printStackTrace();
}
}
});

window.add(button);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);

}
}
Loading

0 comments on commit ae310af

Please sign in to comment.