Skip to content

Commit

Permalink
Scratch for JavaCV driver, small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jul 27, 2012
1 parent 3a9ff56 commit 4d2dec5
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 16 deletions.
10 changes: 10 additions & 0 deletions webcam-capture-driver-javacv/.classpath
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/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>
23 changes: 23 additions & 0 deletions webcam-capture-driver-javacv/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webcam-capture-driver-javacv</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>
35 changes: 35 additions & 0 deletions webcam-capture-driver-javacv/pom.xml
@@ -0,0 +1,35 @@
<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-parent</artifactId>
<version>0.3.4</version>
</parent>

<artifactId>webcam-capture-driver-javacv</artifactId>
<name>Webcam Capture - JavaCV Driver</name>
<description>Webcam Capture driver using JavaCV - Java binding for OpenCV framework</description>

<repositories>
<repository>
<id>javacv</id>
<url>http://maven2.javacv.googlecode.com/git</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>0.3.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.javacv</groupId>
<artifactId>javacv</artifactId>
<version>0.2</version>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,17 @@
package com.github.sarxos.webcam.ds.javacv;

import java.util.List;

import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamDriver;


public class JavaCvDriver implements WebcamDriver {

@Override
public List<WebcamDevice> getDevices() {
// TODO Auto-generated method stub
return null;
}

}
Expand Up @@ -82,18 +82,18 @@ public void open() {
capture = new VideoCapture(size.width, size.height, device);
open = true;

// what the hell is that something below? that's ugly w/a for blue
// what the hell is that something below? that's ugly w/a for black
// images at the very capture beginning, if you have some other idea of
// how to remove them, please share or fix

int i = 0;
do {
// capture.getNextFrame();
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// }
} while (i++ < 5);
capture.getNextFrame();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
} while (i++ < 3);

LOG.info("OpenIMAJ webcam device has been initialized");
}
Expand Down
Expand Up @@ -17,7 +17,7 @@
/**
* NOT STABLE, EXPERIMENTAL STUFF!!!
*
* @author bfiryn
* @author Bartosz Firyn (SarXos)
*/
public class VlcjDevice implements WebcamDevice {

Expand All @@ -30,7 +30,10 @@ public class VlcjDevice implements WebcamDevice {
new Dimension(320, 240),
};

// list of VLC args by Andrew Davison
// (http://fivedots.coe.psu.ac.th/~ad/jg/nui025/snapsWithoutJMF.pdf)
private final static String[] VLC_ARGS = {

// ... have no idea what is this ...
"--intf",

Expand Down Expand Up @@ -82,11 +85,9 @@ private String getCapDevice() {
if (os.indexOf("win") >= 0) {
return "dshow://";
} else if (os.indexOf("mac") >= 0) {
throw new RuntimeException("Not implemented");
return "qtcapture://";
} else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0) {
return "v4l2://";
} else if (os.indexOf("sunos") >= 0) {
throw new RuntimeException("Not implemented");
} else {
throw new RuntimeException("Not implemented");
}
Expand Down Expand Up @@ -114,11 +115,9 @@ public void setSize(Dimension size) {

@Override
public BufferedImage getImage() {

if (!open) {
throw new WebcamException("Cannot get image, player is not open");
}

return player.getSnapshot();
}

Expand All @@ -129,7 +128,7 @@ public void open() {
return;
}

LOG.info("Opening");
LOG.info("Opening webcam device");

factory = new MediaPlayerFactory(VLC_ARGS);
player = factory.newHeadlessMediaPlayer();
Expand All @@ -152,7 +151,7 @@ public void open() {
BufferedImage im = player.getSnapshot(size.width, size.height);
if (im != null && im.getWidth() > 0) {
open = true;
LOG.info("Device has been open: " + getName());
LOG.info("Webcam device is now open: " + getName());
return;
}

Expand Down
Expand Up @@ -18,7 +18,20 @@
/**
* NOT STABLE, EXPERIMENTAL STUFF!!!
*
* @author bfiryn
* Vlcj service discovery works only on Linux, so there is no way (at least for
* now) to list capture devices on Windows.
*
* For Windows dsj library could be used (http://www.humatic.de/htools/dsj.htm)
* listing DirectShow filters for all capture devices in system.
*
* There is service discovery for Linux, but in any case this one could be used
* (http://code.google.com/p/v4l4j/) to access the Video4Linux devices.
*
* MAC OS X can reuse Rococoa (http://code.google.com/p/rococoa/), a Java
* binding to the Mac Objective-C object system, could read device details via
* the Mac's QTKit library.
*
* @author Bartosz Firyn (SarXos)
*/
public class VlcjDriver implements WebcamDriver {

Expand Down

0 comments on commit 4d2dec5

Please sign in to comment.