Last active
March 8, 2016 18:03
For the following Intel Community Question: https://software.intel.com/en-us/forums/realsense/topic/611503
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
package work.serverart; | |
import intel.rssdk.*; | |
import processing.core.PApplet; | |
import processing.core.PImage; | |
public class LandmarksOnly extends PApplet { | |
private final int tracked_faces = 4; | |
pxcmStatus sts = pxcmStatus.PXCM_STATUS_NO_ERROR; | |
PXCMSenseManager senseMgr = null; | |
PXCMFaceData faceData = null; | |
PXCMFaceModule faceModule = null; | |
PXCMFaceData.Face face = null; | |
DisposeHandler dh; | |
public void settings() { | |
size(1920,1080); | |
} | |
public void setup() { | |
dh = new DisposeHandler(this); | |
senseMgr = PXCMSenseManager.CreateInstance(); | |
if (senseMgr == null) { | |
print("Failed to create a SenseManager instance\n"); | |
return; | |
} | |
sts = senseMgr.EnableFace(null); | |
faceModule = senseMgr.QueryFace(); | |
if (sts.isError() || faceModule == null) { | |
System.out.println("Failed to initialize face module."); | |
return; | |
} | |
sts = pxcmStatus.PXCM_STATUS_DATA_UNAVAILABLE; | |
PXCMFaceConfiguration faceConfig = faceModule.CreateActiveConfiguration(); | |
faceConfig.SetTrackingMode(PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR_PLUS_DEPTH); | |
faceConfig.strategy = PXCMFaceConfiguration.TrackingStrategyType.STRATEGY_RIGHT_TO_LEFT; | |
/* Landmark Settings */ | |
faceConfig.landmarks.maxTrackedFaces = tracked_faces; | |
faceConfig.landmarks.isEnabled = true; | |
faceConfig.ApplyChanges(); | |
faceConfig.Update(); | |
sts = senseMgr.Init(); | |
if (sts.isError()) { | |
System.out.println("Init failed: " + sts); | |
return; | |
} | |
senseMgr.QueryCaptureManager().QueryDevice().SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL); | |
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(); | |
/* Processing */ | |
frameRate(30); | |
} | |
public void draw() { | |
sts = senseMgr.AcquireFrame(true); | |
if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) < 0) return; | |
faceData.Update(); | |
int num_faces = faceData.QueryNumberOfDetectedFaces(); | |
if (num_faces != 0) { | |
face = faceData.QueryFaceByIndex(0); // Only testing with one individual (also F200); | |
if (face != null) { | |
landmark_data(); | |
drawing(); | |
} | |
} | |
senseMgr.ReleaseFrame(); | |
} | |
private void landmark_data() { | |
PXCMFaceData.LandmarksData ldata = face.QueryLandmarks(); | |
if (ldata != null) { // This check passes. | |
int npoints = ldata.QueryNumPoints(); // As per your example. | |
PXCMFaceData.LandmarkPoint[] points = new PXCMFaceData.LandmarkPoint[npoints]; | |
boolean are_points = ldata.QueryPoints(points); | |
if (are_points) { // This check passes. | |
for (PXCMFaceData.LandmarkPoint landmark : points) { | |
if (landmark != null) { // This check returns null for each point. Fails. | |
System.out.println(landmark.confidenceImage); // Never Prints | |
} | |
} | |
} | |
} | |
} | |
private void drawing() { | |
background(0, 0); | |
} | |
public PImage ToPImageCopy(int var1, PImage var2, PXCMImage.ImageData cData) { | |
var2.loadPixels(); | |
cData.ToIntArray(var1, var2.pixels); | |
var2.updatePixels(); | |
return var2; | |
} | |
public class DisposeHandler { | |
DisposeHandler(PApplet pa) { | |
pa.registerMethod("dispose", this); | |
} | |
public void dispose() { | |
println("Closing sketch"); | |
if (senseMgr == null) return; | |
faceData.close(); | |
senseMgr.close(); | |
senseMgr = null; | |
println("Disposed of sense manager."); | |
} | |
} | |
} |
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
package work.serverart; | |
import processing.core.PApplet; | |
public class Main { | |
public static void main(String s[]) throws java.io.IOException | |
{ | |
PApplet.main(new String[] {"work.serverart.LandmarksOnly"}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment