-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add presets for libfreenect2 (pull #340)
- Loading branch information
Showing
10 changed files
with
1,600 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
JavaCPP Presets for libfreenect2 | ||
================================ | ||
|
||
Introduction | ||
------------ | ||
This directory contains the JavaCPP Presets module for: | ||
|
||
* libfreenect2 0.2.0 https://github.com/OpenKinect/libfreenect2 | ||
|
||
Please refer to the parent README.md file for more detailed information about the JavaCPP Presets. | ||
|
||
|
||
Documentation | ||
------------- | ||
Java API documentation is available here: | ||
|
||
* http://bytedeco.org/javacpp-presets/libfreenect2/apidocs/ | ||
|
||
|
||
Example | ||
------- | ||
|
||
Here is the full code of the example found in the [`example/`](example/) folder. | ||
|
||
### The `pom.xml` file | ||
|
||
```xml | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.bytedeco.javacpp-presets.libfreenect</groupId> | ||
<artifactId>freenect2Example</artifactId> | ||
<version>0.2.0</version> | ||
<properties> | ||
<exec.mainClass>freenect2Example</exec.mainClass> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.bytedeco.javacpp-presets</groupId> | ||
<artifactId>libfreenect2</artifactId> | ||
<version>0.2.0-1.3.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jogamp.gluegen</groupId> | ||
<artifactId>gluegen-rt-main</artifactId> | ||
<version>2.3.1</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jogamp.jogl</groupId> | ||
<artifactId>jogl-all-main</artifactId> | ||
<version>2.3.1</version> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
``` | ||
|
||
### The `src/main/java/freenect2Example.java` file | ||
|
||
```java | ||
import org.bytedeco.javacpp.Loader; | ||
import org.bytedeco.javacpp.freenect2; | ||
import org.bytedeco.javacpp.freenect2.CpuPacketPipeline; | ||
import org.bytedeco.javacpp.freenect2.FrameMap; | ||
import org.bytedeco.javacpp.freenect2.Freenect2; | ||
import org.bytedeco.javacpp.freenect2.Freenect2Device; | ||
import org.bytedeco.javacpp.freenect2.PacketPipeline; | ||
import org.bytedeco.javacpp.freenect2.SyncMultiFrameListener; | ||
|
||
public class freenect2Example { | ||
public static void main(String[] args) { | ||
Freenect2 freenect2Context; | ||
try { | ||
Loader.load(org.bytedeco.javacpp.freenect2.class); | ||
freenect2Context = new Freenect2(); | ||
} catch (Exception e) { | ||
System.out.println("Exception in the TryLoad !" + e); | ||
return; | ||
} | ||
Freenect2Device device = null; | ||
PacketPipeline pipeline = null; | ||
String serial = ""; | ||
|
||
// Only CPU pipeline tested. | ||
pipeline = new CpuPacketPipeline(); | ||
// pipeline = new libfreenect2::OpenGLPacketPipeline(); | ||
// pipeline = new libfreenect2::OpenCLPacketPipeline(deviceId); | ||
// pipeline = new libfreenect2::CudaPacketPipeline(deviceId); | ||
|
||
if (serial == "") { | ||
serial = freenect2Context.getDefaultDeviceSerialNumber().getString(); | ||
System.out.println("Serial:" + serial); | ||
} | ||
|
||
device = freenect2Context.openDevice(serial, pipeline); | ||
// [listeners] | ||
int types = 0; | ||
types |= freenect2.Frame.Color; | ||
types |= freenect2.Frame.Ir | freenect2.Frame.Depth; | ||
|
||
SyncMultiFrameListener listener = new freenect2.SyncMultiFrameListener(types); | ||
|
||
device.setColorFrameListener(listener); | ||
device.setIrAndDepthFrameListener(listener); | ||
|
||
device.start(); | ||
|
||
System.out.println("Serial: " + device.getSerialNumber().getString()); | ||
System.out.println("Firmware: " + device.getFirmwareVersion().getString()); | ||
|
||
FrameMap frames = new FrameMap(); | ||
|
||
int frameCount = 0; | ||
for (int i = 0; i < 100; i++) { | ||
System.out.println("getting frame " + frameCount); | ||
if (!listener.waitForNewFrame(frames, 10 * 1000)) // 10 sconds | ||
{ | ||
System.out.println("timeout!"); | ||
return; | ||
} | ||
|
||
freenect2.Frame rgb = frames.get(freenect2.Frame.Color); | ||
freenect2.Frame ir = frames.get(freenect2.Frame.Ir); | ||
freenect2.Frame depth = frames.get(freenect2.Frame.Depth); | ||
|
||
System.out.println("RGB image, w:" + rgb.width() + " " + rgb.height()); | ||
byte[] imgData = new byte[1000]; | ||
rgb.data().get(imgData); | ||
for (int pix = 0; pix < 10; pix++) { | ||
System.out.print(imgData[pix] + " "); | ||
} | ||
System.out.println(); | ||
frameCount++; | ||
listener.release(frames); | ||
continue; | ||
} | ||
device.stop(); | ||
device.close(); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
# This file is meant to be included by the parent cppbuild.sh script | ||
if [[ -z "$PLATFORM" ]]; then | ||
pushd .. | ||
bash cppbuild.sh "$@" libfreenect2 | ||
popd | ||
exit | ||
fi | ||
|
||
LIBJPEG=libjpeg-turbo-1.5.1 | ||
LIBFREENECT2_VERSION=0.2.0 | ||
download http://downloads.sourceforge.net/project/libjpeg-turbo/1.5.1/$LIBJPEG.tar.gz $LIBJPEG.tar.gz | ||
download https://github.com/OpenKinect/libfreenect2/archive/v$LIBFREENECT2_VERSION.zip libfreenect2-$LIBFREENECT2_VERSION.zip | ||
|
||
mkdir -p $PLATFORM | ||
cd $PLATFORM | ||
INSTALL_PATH=`pwd` | ||
tar -xzvf ../$LIBJPEG.tar.gz | ||
mkdir -p include lib bin | ||
unzip -o ../libfreenect2-$LIBFREENECT2_VERSION.zip | ||
|
||
case $PLATFORM in | ||
linux-x86) | ||
export CC="$OLDCC -m32 -fPIC" | ||
cd $LIBJPEG | ||
./configure --prefix=$INSTALL_PATH --disable-shared --with-pic --host=i686-linux | ||
make -j $MAKEJ | ||
make install | ||
cd ../libfreenect2-$LIBFREENECT2_VERSION | ||
# patch -Np1 < ../../../libfreenect2-$LIBFREENECT2_VERSION.patch | ||
CC="$OLDCC -m32" CXX="$OLDCXX -m32" $CMAKE -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=OFF -DBUILD_OPENNI_DRIVER=OFF -DENABLE_CUDA=OFF -DENABLE_CXX11=OFF -DENABLE_OPENCL=OFF -DENABLE_VAAPI=OFF -DENABLE_TEGRAJPEG=OFF -DCMAKE_INSTALL_PREFIX=.. -DTurboJPEG_INCLUDE_DIRS=../include -DTurboJPEG_LIBRARIES=../lib/libturbojpeg.a | ||
make -j4 | ||
make install | ||
patch -Np1 < ../../../libfreenect2-$LIBFREENECT2_VERSION.patch | ||
;; | ||
linux-x86_64) | ||
export CC="$OLDCC -m64 -fPIC" | ||
cd $LIBJPEG | ||
./configure --prefix=$INSTALL_PATH --disable-shared --with-pic --host=x86_64-linux | ||
make -j $MAKEJ | ||
make install | ||
cd ../libfreenect2-$LIBFREENECT2_VERSION | ||
# patch -Np1 < ../../../libfreenect2-$LIBFREENECT2_VERSION.patch | ||
CC="$OLDCC -m64" CXX="$OLDCXX -m64" $CMAKE -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=OFF -DBUILD_OPENNI_DRIVER=OFF -DENABLE_CUDA=OFF -DENABLE_CXX11=OFF -DENABLE_OPENCL=OFF -DENABLE_VAAPI=OFF -DENABLE_TEGRAJPEG=OFF -DCMAKE_INSTALL_PREFIX=.. -DTurboJPEG_INCLUDE_DIRS=../include -DTurboJPEG_LIBRARIES=../lib/libturbojpeg.a | ||
make -j4 | ||
make install | ||
patch -Np1 < ../../../libfreenect2-$LIBFREENECT2_VERSION.patch | ||
;; | ||
*) | ||
echo "Error: Platform \"$PLATFORM\" is not supported" | ||
;; | ||
esac | ||
|
||
cd ../.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.bytedeco.javacpp-presets.libfreenect</groupId> | ||
<artifactId>freenect2Example</artifactId> | ||
<version>0.2.0</version> | ||
<properties> | ||
<exec.mainClass>freenect2Example</exec.mainClass> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.bytedeco.javacpp-presets</groupId> | ||
<artifactId>libfreenect2</artifactId> | ||
<version>0.2.0-1.3.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jogamp.gluegen</groupId> | ||
<artifactId>gluegen-rt-main</artifactId> | ||
<version>2.3.1</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jogamp.jogl</groupId> | ||
<artifactId>jogl-all-main</artifactId> | ||
<version>2.3.1</version> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import org.bytedeco.javacpp.Loader; | ||
import org.bytedeco.javacpp.freenect2; | ||
import org.bytedeco.javacpp.freenect2.CpuPacketPipeline; | ||
import org.bytedeco.javacpp.freenect2.FrameMap; | ||
import org.bytedeco.javacpp.freenect2.Freenect2; | ||
import org.bytedeco.javacpp.freenect2.Freenect2Device; | ||
import org.bytedeco.javacpp.freenect2.PacketPipeline; | ||
import org.bytedeco.javacpp.freenect2.SyncMultiFrameListener; | ||
|
||
/** | ||
* | ||
* @author Jeremy Laviole | ||
*/ | ||
public class freenect2Example { | ||
|
||
public static void main(String[] args) { | ||
Freenect2 freenect2Context; | ||
try { | ||
Loader.load(org.bytedeco.javacpp.freenect2.class); | ||
// Context is shared accross cameras. | ||
freenect2Context = new Freenect2(); | ||
|
||
} catch (Exception e) { | ||
System.out.println("Exception in the TryLoad !" + e); | ||
e.printStackTrace(); | ||
return; | ||
} | ||
Freenect2Device device = null; | ||
PacketPipeline pipeline = null; | ||
String serial = ""; | ||
|
||
pipeline = new CpuPacketPipeline(); | ||
// pipeline = new libfreenect2::OpenGLPacketPipeline(); | ||
// pipeline = new libfreenect2::OpenCLPacketPipeline(deviceId); | ||
// pipeline = new libfreenect2::CudaPacketPipeline(deviceId); | ||
|
||
if (serial == "") { | ||
serial = freenect2Context.getDefaultDeviceSerialNumber().getString(); | ||
System.out.println("Serial:" + serial); | ||
} | ||
|
||
device = freenect2Context.openDevice(serial, pipeline); | ||
// [listeners] | ||
int types = 0; | ||
types |= freenect2.Frame.Color; | ||
types |= freenect2.Frame.Ir | freenect2.Frame.Depth; | ||
|
||
SyncMultiFrameListener listener = new freenect2.SyncMultiFrameListener(types); | ||
|
||
device.setColorFrameListener(listener); | ||
device.setIrAndDepthFrameListener(listener); | ||
|
||
device.start(); | ||
|
||
System.out.println("Serial: " + device.getSerialNumber().getString()); | ||
System.out.println("Firmware: " + device.getFirmwareVersion().getString()); | ||
/// [start] | ||
|
||
FrameMap frames = new FrameMap(); | ||
// Fetch 100 frames. | ||
int frameCount = 0; | ||
for (int i = 0; i < 100; i++) { | ||
System.out.println("getting frame " + frameCount); | ||
if (!listener.waitForNewFrame(frames, 10 * 1000)) // 10 sconds | ||
{ | ||
System.out.println("timeout!"); | ||
return; | ||
} | ||
|
||
freenect2.Frame rgb = frames.get(freenect2.Frame.Color); | ||
freenect2.Frame ir = frames.get(freenect2.Frame.Ir); | ||
freenect2.Frame depth = frames.get(freenect2.Frame.Depth); | ||
/// [loop start] | ||
System.out.println("RGB image, w:" + rgb.width() + " " + rgb.height()); | ||
byte[] imgData = new byte[1000]; | ||
rgb.data().get(imgData); | ||
for (int pix = 0; pix < 10; pix++) { | ||
System.out.print(imgData[pix] + " "); | ||
} | ||
System.out.println(); | ||
frameCount++; | ||
listener.release(frames); | ||
continue; | ||
} | ||
|
||
device.stop(); | ||
device.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
diff -ruN libfreenect2-0.2.0/include/libfreenect2/frame_listener_impl.h libfreenect2-0.2.0_patch/include/libfreenect2/frame_listener_impl.h | ||
--- libfreenect2-0.2.0/include/libfreenect2/frame_listener_impl.h 2016-04-27 22:34:51.000000000 +0200 | ||
+++ libfreenect2-0.2.0_patch/include/libfreenect2/frame_listener_impl.h 2016-10-29 17:30:57.949091000 +0200 | ||
@@ -40,7 +40,7 @@ | ||
///@{ | ||
|
||
/** Storage of multiple different types of frames. */ | ||
-typedef std::map<Frame::Type, Frame*> FrameMap; | ||
+// typedef std::map<Frame::Type, Frame*> FrameMap; | ||
|
||
class SyncMultiFrameListenerImpl; | ||
|
||
@@ -62,15 +62,15 @@ | ||
* @param milliseconds Timeout. This parameter is ignored if not built with C++11 threading support. | ||
* @return true if a frame is received; false if not. | ||
*/ | ||
- bool waitForNewFrame(FrameMap &frame, int milliseconds); | ||
+ bool waitForNewFrame(std::map<Frame::Type, Frame*> &frame, int milliseconds); | ||
|
||
/** Wait indefinitely for new frames. | ||
* @param[out] frame Caller is responsible to release the frames. | ||
*/ | ||
- void waitForNewFrame(FrameMap &frame); | ||
+ void waitForNewFrame(std::map<Frame::Type, Frame*> &frame); | ||
|
||
/** Shortcut to delete all frames */ | ||
- void release(FrameMap &frame); | ||
+ void release(std::map<Frame::Type, Frame*> &frame); | ||
|
||
virtual bool onNewFrame(Frame::Type type, Frame *frame); | ||
private: |
Oops, something went wrong.