Skip to content

Commit

Permalink
Merge pull request #4 from ThomasLengeling/dev
Browse files Browse the repository at this point in the history
Point Cloud Depth
  • Loading branch information
ThomasLengeling committed Oct 12, 2014
2 parents 5b14cbb + 3dd97b2 commit acc6f17
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 6 deletions.
86 changes: 86 additions & 0 deletions KinectPV2/examples/PointCloudDepth/PointCloudDepth.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright (C) 2014 Thomas Sanchez Lengeling.
KinectPV2, Kinect for Windows v2 library for processing
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.
*/

import KinectPV2.KJoint;
import KinectPV2.*;

KinectPV2 kinect;

//Distance Threashold
float maxD = 4.0f; //meters
float minD = 1.0f;

void setup() {
size(512*2, 424, P3D);

kinect = new KinectPV2(this);

//Enable point cloud
kinect.enablePointCloud(true);
kinect.init();
}

void draw() {
background(0);

image(kinect.getDepthImage(), 0, 0);

/* Get the point cloud as a PImage
* Each pixel of the PointCloudDepthImage correspondes to the value
* of the Z in the Point Cloud or distances, the values of
* the Point cloud are mapped from (0.0 - 8.0) to gray color (0 - 255)
* if change the low and high Threshold, then the mapping min and max distantance
* are change to the new min and max threashold.
* (low, high) -> (0, 255)
*/
image(kinect.getPointCloudDepthImage(), 512, 0);

//get each pixel as int [] 512 x 424
//int [] rawData = kinect.getRawPointCloudDepth();

//Threahold of the point Cloud.
kinect.setLowThresholdPC(minD);
kinect.setHighThresholdPC(maxD);
}

void keyPressed() {
if (key == '1') {
minD += 0.01;
println("Change min: "+minD);
}

if (key == '2') {
minD -= 0.01;
println("Change min: "+minD);
}

if (key == '3') {
maxD += 0.01;
println("Change max: "+maxD);
}

if (key == '4') {
maxD -= 0.01;
println("Change max: "+maxD);
}
}
2 changes: 2 additions & 0 deletions KinectPV2/examples/PointCloudDepth/code/sketch.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode.id=processing.mode.java.JavaMode
mode=Java
2 changes: 2 additions & 0 deletions KinectPV2/examples/PointCloudDepth/sketch.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode.id=processing.mode.java.JavaMode
mode=Java
Binary file modified KinectPV2/library/KinectPV2.dll
Binary file not shown.
Binary file modified KinectPV2/library/KinectPV2.exp
Binary file not shown.
Binary file modified KinectPV2/library/KinectPV2.jar
Binary file not shown.
Binary file modified KinectPV2/library/KinectPV2.lib
Binary file not shown.
Binary file modified KinectPV2/library/KinectPV2.pdb
Binary file not shown.
3 changes: 3 additions & 0 deletions KinectPV2/src/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ public interface Constants {

public final static int WIDTHDepth = 512;
public final static int HEIGHTDepth = 424;

public final static int Int32 = 0;
public final static int Float = 1;
}
59 changes: 53 additions & 6 deletions KinectPV2/src/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class Device implements Constants, FaceProperties, SkeletonProperties, Ru
private Image longExposureImg;
private Image bodyTrackImg;
private Image depthMaskImg;
private Image pointCloudDepthImg;

private Skeleton [] skeletonDepth;
private Skeleton [] skeleton3d;
Expand Down Expand Up @@ -90,6 +91,8 @@ public Device(PApplet _p){

longExposureImg = new Image(parent, WIDTHDepth, HEIGHTDepth, PImage.ALPHA);

pointCloudDepthImg = new Image(parent, WIDTHDepth, HEIGHTDepth, PImage.ALPHA);

skeletonDepth = new Skeleton[BODY_COUNT];
for(int i = 0; i < BODY_COUNT; i++){
skeletonDepth[i] = new Skeleton();
Expand Down Expand Up @@ -185,6 +188,15 @@ private void copyLongExposureImg(int [] rawData){
PApplet.arrayCopy(rawData, 0, longExposureImg.rawIntData, 0, longExposureImg.getImgSize());
}

//POINT CLOUD DEPTH
private void copyPointCloudImage(int [] rawData) {
if(rawData.length == WIDTHDepth * HEIGHTDepth) {
PApplet.arrayCopy(rawData, 0, pointCloudDepthImg.rawIntData, 0, pointCloudDepthImg.getImgSize());
PApplet.arrayCopy(rawData, 0, pointCloudDepthImg.pixels(), 0, pointCloudDepthImg.getImgSize());
pointCloudDepthImg.updatePixels();
}
}

//SKELETON DEPTH
private void copySkeletonDepthData(float [] rawData){
if(rawData.length == JOINTSIZE){
Expand Down Expand Up @@ -342,6 +354,11 @@ public PImage getLongExposureInfraredImage(){
}


public PImage getPointCloudDepthImage() {
return pointCloudDepthImg.img;
}


/**
* Get Raw Depth Data
* 512 x 424
Expand Down Expand Up @@ -396,6 +413,10 @@ public PImage getLongExposureInfraredImage(){
return longExposureImg.rawIntData;
}

public int [] getRawPointCloudDepth() {
return pointCloudDepthImg.rawIntData;
}

//ACTIVATE RAW DATA
/**
* Activate Raw Color Image Capture.
Expand Down Expand Up @@ -554,19 +575,38 @@ public void enablePointCloud(boolean toggle){
* Set Threshold Depth Value Z for Point Cloud
* @param float val
*/
public void setThresholdPointCloud(float val){
jniThresholdDepthPointCloud(val);
public void setLowThresholdPC(float val){
jniSetLowThresholdDepthPC(val);
}

/**
* Get Threshold Depth Value Z from Point Cloud
* Default 1.9
* @return default Threshold
*/
public float getThresholdDepthPointCloud(){
return jniGetDefaultThresholdDepthPointCloud();
public float getLowThresholdDepthPC(){
return jniGetLowThresholdDepthPC();
}


/**
* Set Threshold Depth Value Z for Point Cloud
* @param float val
*/
public void setHighThresholdPC(float val){
jniSetHighThresholdDepthPC(val);
}

/**
* Get Threshold Depth Value Z from Point Cloud
* Default 1.9
* @return default Threshold
*/
public float getHighThresholdDepthPC(){
return jniGetHighThresholdDepthPC();
}


/*
public void enablePointCloudColor(boolean toggle){
jniEnablePointCloudColor(toggle);
Expand Down Expand Up @@ -636,9 +676,16 @@ protected void stopDevice(){

private native void jniEnablePointCloudColor(boolean toggle);

private native void jniThresholdDepthPointCloud(float val);

private native float jniGetDefaultThresholdDepthPointCloud();

private native void jniSetLowThresholdDepthPC(float val);

private native float jniGetLowThresholdDepthPC();


private native void jniSetHighThresholdDepthPC(float val);

private native float jniGetHighThresholdDepthPC();


public void run() {
Expand Down
4 changes: 4 additions & 0 deletions KinectPV2/src/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ public class Image{
private boolean processRawData;

protected byte [] rawByteData;

protected float [] rawFloatData;
protected int [] rawIntData;

public Image(PApplet p, int width, int height, int MODE){
parent = p;
img = parent.createImage(width, height, MODE);
imgPixelSize = width * height;
rawByteData = new byte[imgPixelSize];

rawIntData = new int[imgPixelSize];
rawFloatData = new float[imgPixelSize];
processRawData= false;
}

Expand Down

0 comments on commit acc6f17

Please sign in to comment.