Skip to content

Instantly share code, notes, and snippets.

@BorisKourt
Last active March 3, 2016 22:29
Show Gist options
  • Save BorisKourt/8ac77261731000be2fb6 to your computer and use it in GitHub Desktop.
Save BorisKourt/8ac77261731000be2fb6 to your computer and use it in GitHub Desktop.
import processing.core.*;
import intel.rssdk.*;
public class MainCapture extends PApplet {
int nframes = 0;
PImage imgDepth = null;
pxcmStatus sts = pxcmStatus.PXCM_STATUS_NO_ERROR;
PXCMSenseManager senseMgr = null;
PXCMFaceData faceData = null;
PXCMFaceModule faceModule = null;
DisposeHandler dh;
public void settings() {
size(1280, 720);
}
public void setup() {
dh = new DisposeHandler(this);
// Create SenseManager
senseMgr = PXCMSenseManager.CreateInstance();
if (senseMgr == null) {
print("Failed to create a SenseManager instance\n");
return;
}
senseMgr.Enable3DSeg();
senseMgr.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1280, 720, 30);
pxcmStatus sts = senseMgr.EnableFace(null);
faceModule = senseMgr.QueryFace();
if (sts.isError() || faceModule == null)
{
System.out.println("Failed to initialize face module.");
return;
}
// Retrieve the input requirements
sts = pxcmStatus.PXCM_STATUS_DATA_UNAVAILABLE;
PXCMFaceConfiguration faceConfig = faceModule.CreateActiveConfiguration();
faceConfig.SetTrackingMode(PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR_PLUS_DEPTH);
faceConfig.detection.isEnabled = true;
faceConfig.ApplyChanges();
faceConfig.Update();
sts = senseMgr.Init();
if (sts.isError())
{
System.out.println("Init failed: " + sts);
return;
}
PXCMCapture.Device dev = senseMgr.QueryCaptureManager().QueryDevice();
PXCMCapture.DeviceInfo info = new PXCMCapture.DeviceInfo();
dev.QueryDeviceInfo(info);
System.out.println("Using Camera: " + info.name);
faceData = faceModule.CreateOutput();
imgDepth = createImage(1280, 720, RGB);
}
public void draw() {
background(0);
sts = senseMgr.AcquireFrame(true);
if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR)<0) return;
nframes++;
if (nframes==65535) nframes = 0;
faceData = faceModule.CreateOutput();
faceData.Update();
PXCM3DSeg segmentation = senseMgr.Query3DSeg();
if (segmentation != null) {
PXCMImage segmentedImage = segmentation.AcquireSegmentedImage();
if (segmentedImage != null) {
PXCMImage.ImageData cData = new PXCMImage.ImageData();
segmentedImage.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, cData);
imgDepth = cData.ToPImage(0, imgDepth);
segmentedImage.ReleaseAccess(cData);
image(imgDepth, 0, 0);
} else {
println("null segImage");
}
} else {
println("null seg");
}
for (int fidx=0;; fidx++) {
PXCMFaceData.Face face = faceData.QueryFaceByIndex(fidx);
if (face==null) break;
PXCMFaceData.DetectionData detectData = face.QueryDetection();
if (detectData != null)
{
PXCMRectI32 rect = new PXCMRectI32();
boolean ret = detectData.QueryBoundingRect(rect);
if (ret) {
System.out.println ("");
System.out.println ("Detection Rectangle at frame #" + nframes);
System.out.println ("Top Left corner: (" + rect.x + "," + rect.y + ")" );
System.out.println ("Height: " + rect.h + " Width: " + rect.w);
}
stroke(255,255,0);
strokeWeight(3);
noFill();
rect(rect.x,rect.y,rect.h,rect.w);
} else
break;
PXCMFaceData.PoseData poseData = face.QueryPose();
if (poseData != null)
{
PXCMFaceData.PoseEulerAngles pea = new PXCMFaceData.PoseEulerAngles();
poseData.QueryPoseAngles(pea);
System.out.println ("Pose Data at frame #" + nframes);
System.out.println ("(Roll, Yaw, Pitch) = (" + pea.roll + "," + pea.yaw + "," + pea.pitch + ")");
}
}
faceData.close();
senseMgr.ReleaseFrame();
}
public class DisposeHandler {
DisposeHandler(PApplet pa)
{
pa.registerMethod("dispose", this);
}
public void dispose()
{
println("Closing sketch");
if (senseMgr==null) return;
senseMgr.close();
senseMgr=null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment