Skip to content

Commit

Permalink
Added initial code for using javacv (opencv) to capture input from Di…
Browse files Browse the repository at this point in the history
…rectShow devices!
  • Loading branch information
beele committed Nov 16, 2014
1 parent 3bed3d2 commit 754d692
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,4 @@ run.bat
/JambiLight_JAVA/ScreenCapper.dll
settings.xml
JambiLight_JNI/ScreenCapper/ScreenCapper/ReadMe.txt
JambiLight_JAVA/lib/javacv-bin/
25 changes: 12 additions & 13 deletions JambiLight_JAVA/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
<version>8.0.6</version>
</dependency>

<!-- Experimental -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>0.9</version>
</dependency>

<!-- Custom dependencies -->
<dependency>
<groupId>com.google.code</groupId>
Expand All @@ -68,7 +75,8 @@
<version>1.0</version>
<type>dll</type>
</dependency>


<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -140,7 +148,7 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -156,20 +164,11 @@
<!-- list all your dependencies here-->
dependency/jfxrt.jar
</JavaFX-Class-Path>
<!-- The artifactId (name) of the jfxrt.jar ... see dependency system scope-->
<Class-Path>
dependency/javafx-${javafx.version}.jar
dependency/jfxrt.jar
dependency/guava-16.0.1.jar
dependency/jssc-2.8.0.jar
dependency/RXTX-2.2.jar
dependency/hamcrest-core-1.3.jar
dependency/junit-4.11.jar
dependency/controlsfx-8.0.6.jar
</Class-Path>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<!-- All dependencies are outside the jar file and are located in the dependency folder -->
<classpathPrefix>dependency/</classpathPrefix>
</manifest>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ public void onColorsUpdated(ColorModelUpdatedEvent event) {
logger.DEBUG("All mem: " + rt.totalMemory() / megabyteInBytes);
logger.DEBUG("Max mem: " + rt.maxMemory() / megabyteInBytes);

if(model.getActionDuration() > 500) {
/*if(model.getActionDuration() > 500) {
if(performanceCounter == 0) {
performanceCounter++;
} else {
shutdown();
}
}
}*/
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package be.beeles_place.jambiLight.utils.screenCapture;

import be.beeles_place.jambiLight.utils.logger.LOGGER;
import be.beeles_place.jambiLight.utils.screenCapture.impl.ScreenCapper;
import be.beeles_place.jambiLight.utils.screenCapture.impl.ScreenCapperJNI;
import be.beeles_place.jambiLight.utils.screenCapture.impl.ScreenCapperMock;
import be.beeles_place.jambiLight.utils.screenCapture.impl.XbmcScreenCapper;
import be.beeles_place.jambiLight.utils.screenCapture.impl.*;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
Expand All @@ -25,7 +22,10 @@ public enum ScreenCapperStrategy {
MOCK_RAINBOW(ScreenCapperMock.class),

@XmlEnumValue("MOCK_JNI")
MOCK_JNI(ScreenCapperJNI.class);
MOCK_JNI(ScreenCapperJNI.class),

@XmlEnumValue("DIRECT_SHOW")
DIRECT_SHOW(DirectShowCapper.class);

private Class captureStrategy;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package be.beeles_place.jambiLight.utils.screenCapture.impl;

import be.beeles_place.jambiLight.utils.logger.LOGGER;
import be.beeles_place.jambiLight.utils.screenCapture.IScreenCapper;
import org.bytedeco.javacpp.opencv_core;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;

import static org.bytedeco.javacpp.opencv_highgui.*;

public class DirectShowCapper implements IScreenCapper {

private final LOGGER logger;
private Dimension dimensions;

private VideoCapture vc;

private byte[] data;
private int[] pixels;

private final int width;
private final int height;

private boolean initDone;

/**
* Constructor for DirectShowCapper.
* Sets and calculates initial values.
*/
public DirectShowCapper() {
logger = LOGGER.getInstance();
logger.INFO("SCREENCAPPER => Starting screen capture with through DirectShow device.");

width = 720;
height = 576;

pixels = new int[width * height];
dimensions = new Dimension(width,height);
}

@Override
public Dimension getScreenDimensions() {
return dimensions;
}

private void init() {
//TODO: Set up the correct device!
vc = new VideoCapture(0);
//vc.set(CV_CAP_PROP_FRAME_WIDTH,720);
//vc.set(CV_CAP_PROP_FRAME_HEIGHT,480);

initDone = true;
}

@Override
public int[] capture() {
if(initDone == false){
init();
}

opencv_core.Mat m = new opencv_core.Mat();
if(vc.read(m)) {
BufferedImage img = m.getBufferedImage();
byte[] temp = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
for (int i = 0 ; i < pixels.length; i++) {
//Convert from RGB bytes to pixel integer!
pixels[i] = (( temp[i*3+2] &0x0ff)<<16)|(( temp[i*3+1] &0x0ff)<<8)|( temp[i*3] &0x0ff);
}

img.flush();
img = null;
temp = null;
return pixels;
} else {
//TODO: Error!
return new int[width * height];
}
}

@Override
public void dispose() {
if(vc != null && vc.isOpened()) {
vc.release();
}

dimensions = null;
}
}
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set DIR=%cd%
set DIR=^"%DIR%^"
call mvn install:install-file -Dfile=%DIR%/JambiLight_JAVA/lib/RXTXcomm.jar -DgroupId=com.google.code -DartifactId=RXTX -Dversion=2.2 -Dpackaging=jar
call mvn install:install-file -Dfile=%DIR%/JambiLight_JAVA/lib/ScreenCapper.dll -DgroupId=be.beeles_place.code -DartifactId=JNIscreenCapMock -Dversion=1.0 -Dpackaging=dll
call mvn clean install
call mvn clean install -Dplatform.dependencies=true
ren %DIR%\JambiLight_JAVA\target\dependency\JNIscreenCapMock-1.0.dll ScreenCapper.dll
move %DIR%\JambiLight_JAVA\target\dependency\ScreenCapper.dll %DIR%\JambiLight_JAVA\target\
echo java -Xmx256m -jar JambiLight.jar > %DIR%\JambiLight_JAVA\target\run.bat
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ echo "======================================"
echo "======================================"
mvn install:install-file -Dfile=./JambiLight_JAVA/lib/RXTXcomm.jar -DgroupId=com.google.code -DartifactId=RXTX -Dversion=2.2 -Dpackaging=jar
mvn install:install-file -Dfile=./JambiLight_JAVA/lib/ScreenCapper.dll -DgroupId=be.beeles_place.code -DartifactId=JNIscreenCapMock -Dversion=1.0 -Dpackaging=dll
mvn clean install
mvn clean install -Dplatform.dependencies=true
mv ./JambiLight_JAVA/target/dependency/JNIscreenCapMock-1.0.dll ./JambiLight_JAVA/target/ScreenCapper.dll
echo "java -Xmx256m -jar JambiLight.jar" > ./JambiLight_JAVA/target/run.sh
echo "java -Xmx128m -jar SocketDummy.jar" > ./JambiLight_XBMC/SocketDummy/target/run.sh
Expand Down

0 comments on commit 754d692

Please sign in to comment.