public
Created

  • Download Gist
IntelPerC.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
using UnityEngine;
using System.Collections;
 
public class IntelPerC : MonoBehaviour {
// v0.11
// voice - dictation/resetdictation
// gesture - returns conf, openness, worldposition, normal
// face - rect
public Texture2D m_Texture;
private PXCUPipeline pp;
private int[] size=new int[2]{0,0};
private PXCUPipeline.Mode mode=PXCUPipeline.Mode.GESTURE | PXCUPipeline.Mode.FACE_LOCATION ;
int openness=-1; int confidence=0;
Vector3 worldPosition=Vector3.zero;
Vector3 normal=Vector3.zero;
uint faceConfidence=0;
PXCMFaceAnalysis.Detection.ViewAngle faceViewAngle=PXCMFaceAnalysis.Detection.ViewAngle.VIEW_ANGLE_OMNI;
Vector2 faceRectCenter=Vector2.zero;
bool cameraFound=false;
int[] labels=new int[3]{0,256,256};
byte[] labelmap;
string dictation="DUNNO";
public bool GetCameraStatus(){
return cameraFound;
}
public uint GetFaceConfidence(){
return faceConfidence;
}
public Vector2 GetFaceRectCenter(){
return faceRectCenter;
}
public bool GetClosedCertain(){
if(openness<5&&openness>=0&&confidence>80)return true;
else return false;
}
public bool GetOpenCertain(){
if(confidence>80&&openness>80)return true;
else return false;
}
public int GetOpenness(){
return openness;
}
public int GetConfidence(){
return confidence;
}
public Vector3 GetWorldPosition(){
return worldPosition;
}
public Vector3 GetNormal(){
return normal;
}
public string GetDictation(){
return dictation;
}
public void ResetDictation(){
dictation="DUNNO";
}
void Start () {
pp=new PXCUPipeline();
//shm=GetComponent<ShadowHandMod>();
//transform.localScale = new Vector3(Screen.width/420f,Screen.height/420f,0.01f);
if (!pp.Init(mode)) {
print("Unable to initialize the PXCUPipeline");
cameraFound=false;
return;
}else
cameraFound=true;
if (pp.QueryLabelMapSize(size))
print("LabelMap: width=" + size[0] + ", height=" + size[1]);
if (size[0]>0) {
m_Texture = new Texture2D (size[0], size[1], TextureFormat.ARGB32,false);
renderer.material.mainTexture = m_Texture;
labelmap=new byte[size[0]*size[1]];
//shm.ZeroImage(m_Texture);
}
}
void Update () {
if (!pp.AcquireFrame(false)) return;
 
if (pp.QueryLabelMapAsImage(m_Texture))
m_Texture.Apply();
/*int[] labels=new int[3]{0,256,256};
pp.QueryLabelMap(labelmap,labels);
shm.ProcessTexture(m_Texture,labels,labelmap); */
// face stuff
int face; ulong timestamp;
if(pp.QueryFaceID(0,out face,out timestamp)){
PXCMFaceAnalysis.Detection.Data datafacedetect;
if(pp.QueryFaceLocationData(face,out datafacedetect)){
faceConfidence = datafacedetect.confidence;
faceViewAngle = datafacedetect.viewAngle;
faceRectCenter = new Vector2(datafacedetect.rectangle.x,datafacedetect.rectangle.y);
//print (faceRectCenter+" "+faceConfidence);
}
}
/*
* GeoNode
* timeStamp
* user
* body - LABEL
* side - Side
* confidence - 0 to 100
* positionWorld - node pos, world coords
* positionImage - node pos, image specific (x,y,d)
*
* finger tip
* radiusWorld - volume of fingertip 3D in meters
* radiusImage - volume of fingertip in 2D in pixels
*
* hand/palm
* normal - vec perp palm center
* openness - 0 to 100
* opennessState - Openness.LABEL_OPEN,_CLOSE,_OPENNESS_ANY (unknown)
**/
 
PXCMGesture.GeoNode gnode;
if (pp.QueryGeoNode(PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY,out gnode)){
openness = (int)gnode.openness;
worldPosition = new Vector3(gnode.positionWorld.x,-gnode.positionWorld.y,gnode.positionWorld.z);
normal = new Vector3(gnode.normal.x,gnode.normal.y,gnode.normal.z);
confidence = (int)gnode.confidence;
}
PXCMVoiceRecognition.Recognition rdata;
if (pp.QueryVoiceRecognized(out rdata)){
print ("voice rec (label="+rdata.label+","+rdata.confidence+",size="+rdata.dictation.Length+", dictation="+rdata.dictation+")");
dictation = rdata.dictation;
}
pp.ReleaseFrame();
}
void OnDisable() {
pp.Close();
pp.Dispose();
}
public void CloseScene(){
pp.ReleaseFrame();
pp.Close();
pp.Dispose ();
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.