use of org.bytedeco.javacpp.freenect2.Freenect2 in project javacpp-presets by bytedeco.
the class freenect2Example method main.
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();
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 (// 10 sconds
!listener.waitForNewFrame(frames, 10 * 1000)) {
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();
}
use of org.bytedeco.javacpp.freenect2.Freenect2 in project javacv by bytedeco.
the class OpenKinect2FrameGrabber method grabIR.
protected void grabIR() {
/**
* 512x424 float. Range is [0.0, 65535.0].
*/
freenect2.Frame IRImage = frames.get(freenect2.Frame.Ir);
int channels = 1;
int iplDepth = IPL_DEPTH_32F;
int bpp = (int) IRImage.bytes_per_pixel();
int deviceWidth = (int) IRImage.width();
int deviceHeight = (int) IRImage.height();
Pointer rawIRData = IRImage.data();
if (rawIRImage == null) {
rawIRImage = IplImage.createHeader(deviceWidth, deviceHeight, iplDepth, channels);
}
cvSetData(rawIRImage, rawIRData, deviceWidth * channels * iplDepth / 8);
}
use of org.bytedeco.javacpp.freenect2.Freenect2 in project javacv by bytedeco.
the class OpenKinect2FrameGrabber method tryLoad.
public static void tryLoad() throws FrameGrabber.Exception {
if (loadingException != null) {
loadingException.printStackTrace();
throw loadingException;
} else {
try {
if (freenect2Context != null) {
return;
}
Loader.load(org.bytedeco.javacpp.freenect2.class);
// Context is shared accross cameras.
freenect2Context = new Freenect2();
} catch (Throwable t) {
throw loadingException = new FrameGrabber.Exception("Failed to load " + OpenKinect2FrameGrabber.class, t);
}
}
}
use of org.bytedeco.javacpp.freenect2.Freenect2 in project javacv by bytedeco.
the class OpenKinect2FrameGrabber method grabVideo.
protected void grabVideo() {
int iplDepth = IPL_DEPTH_8U;
freenect2.Frame rgb = frames.get(freenect2.Frame.Color);
int channels = (int) rgb.bytes_per_pixel();
int deviceWidth = (int) rgb.width();
int deviceHeight = (int) rgb.height();
BytePointer rawVideoImageData = rgb.data();
if (rawVideoImage == null) {
rawVideoImage = IplImage.createHeader(deviceWidth, deviceHeight, iplDepth, channels);
}
cvSetData(rawVideoImage, rawVideoImageData, deviceWidth * channels * iplDepth / 8);
if (videoImageRGBA == null) {
videoImageRGBA = rawVideoImage.clone();
}
cvCvtColor(rawVideoImage, videoImageRGBA, COLOR_BGRA2RGBA);
}
use of org.bytedeco.javacpp.freenect2.Freenect2 in project javacv by bytedeco.
the class OpenKinect2FrameGrabber method grabDepth.
protected void grabDepth() {
/**
* 512x424 float also ?.
*/
freenect2.Frame depthImage = frames.get(freenect2.Frame.Depth);
int channels = 1;
int iplDepth = IPL_DEPTH_32F;
int bpp = (int) depthImage.bytes_per_pixel();
int deviceWidth = (int) depthImage.width();
int deviceHeight = (int) depthImage.height();
Pointer rawDepthData = depthImage.data();
if (rawDepthImage == null) {
rawDepthImage = IplImage.createHeader(deviceWidth, deviceHeight, iplDepth, channels);
}
cvSetData(rawDepthImage, rawDepthData, deviceWidth * channels * iplDepth / 8);
}
Aggregations