Skip to content

Commit

Permalink
Capture driver able to read image by fswebcam cli tool, closes #175
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Mar 14, 2014
1 parent 7bfe979 commit 47322c6
Show file tree
Hide file tree
Showing 9 changed files with 631 additions and 0 deletions.
28 changes: 28 additions & 0 deletions webcam-capture-drivers/driver-fswebcam/.classpath
@@ -0,0 +1,28 @@
<?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" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<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>
<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>
23 changes: 23 additions & 0 deletions webcam-capture-drivers/driver-fswebcam/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webcam-capture-driver-v4l4j</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
64 changes: 64 additions & 0 deletions webcam-capture-drivers/driver-fswebcam/README.md
@@ -0,0 +1,64 @@
# FsWebcam Capture Driver

This capture driver is designed to allow developers to use console program called
_fswebcam_ written by Philip Heron as the source of images for Webcam Capture API.
This capture driver works on *nix **only** and requires [fswebcam](https://github.com/fsphil/fswebcam) to be
installed.

To install fswebcam tool:

```plain
sudo apt-get install fswebcam
```

## How To Use

Set capture driver before you start using Webcam class:

```java
public class TakePictureExample {

// set capture driver for fswebcam tool
static {
Webcam.setDriver(new FsWebcamDriver());
}

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

// get default webcam and open it
Webcam webcam = Webcam.getDefault();
webcam.open();

// get image from webcam device
BufferedImage image = webcam.getImage();

// save image to PNG file
ImageIO.write(image, "PNG", new File("test.png"));

// close webcam
webcam.close();
}
}
```

## Issues

There are several known issues. If you have an idea of how those can
be fixed, please send the pull request with the code change and I will
be happy to merge it into the master branch.

1. Single call to getImage() causes webcam to be re-open again,
2. Because of 1, webcam diode is blinking,
3. Because of 1, FPS is pretty slow (0.2 FPS on my Ubuntu Laptop),
4. In some cases when the main Java process is killed, the fswebcam subprocess keeps running because noone is reading from the pipe.


## License

Copyright (C) 2014 Bartosz Firyn

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 changes: 38 additions & 0 deletions webcam-capture-drivers/driver-fswebcam/pom.xml
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-drivers</artifactId>
<version>0.3.10-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-driver-fswebcam</artifactId>
<packaging>jar</packaging>

<name>Webcam Capture - FsWebcam Driver</name>
<description>
This is one of the capture drivers which can be used by Webcam Capture API
to fetch image from webcam device. This specific capture driver is using
fswebcam command line tool by by Philip Heron to access the image.
</description>

<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
@@ -0,0 +1,38 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.ds.fswebcam.FsWebcamDriver;


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

// set capture driver for fswebcam tool
static {
Webcam.setDriver(new FsWebcamDriver());
}

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

// get default webcam and open it
Webcam webcam = Webcam.getDefault();
webcam.open();

// get image from webcam device
BufferedImage image = webcam.getImage();

// save image to PNG file
ImageIO.write(image, "PNG", new File("test.png"));

// close webcam
webcam.close();
}
}

0 comments on commit 47322c6

Please sign in to comment.