Skip to content

Commit

Permalink
fixes for new face api
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-ninja committed Sep 15, 2017
1 parent 510e50b commit 19e1f96
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 21 deletions.
12 changes: 9 additions & 3 deletions Assets/Scripts/GazeGestureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ IEnumerator<object> PostToFaceAPI(byte[] imageData, Matrix4x4 cameraToWorldMatri
GameObject txtObject = (GameObject)Instantiate(textPrefab);
TextMesh txtMesh = txtObject.GetComponent<TextMesh>();
var r = result["kairos"];
float top = -(r["top"].f / cameraResolution.height -.5f);
float left = r["left"].f / cameraResolution.width - .5f;
float top = -(r["topLeftY"].f / cameraResolution.height -.5f);
float left = r["topLeftX"].f / cameraResolution.width - .5f;
float width = r["width"].f / cameraResolution.width;
float height = r["height"].f / cameraResolution.height;

Expand All @@ -104,6 +104,7 @@ IEnumerator<object> PostToFaceAPI(byte[] imageData, Matrix4x4 cameraToWorldMatri
scale.z = .1f;
faceBounds.transform.localScale = scale;
faceBounds.tag = "faceBounds";
Debug.Log(string.Format("{0},{1} translates to {2},{3}", left, top, faceBounds.transform.position.x, faceBounds.transform.position.y));

Vector3 origin = cameraToWorldMatrix.MultiplyPoint3x4(pixelToCameraMatrix.MultiplyPoint3x4(new Vector3(left + width + .1f, top, 0)));
txtObject.transform.position = origin;
Expand All @@ -113,7 +114,7 @@ IEnumerator<object> PostToFaceAPI(byte[] imageData, Matrix4x4 cameraToWorldMatri
txtObject.transform.localScale /= 2;
}

txtMesh.text = result["text"].str;
txtMesh.text = result["text"].str.Replace("\\n", "\n");
}
}

Expand Down Expand Up @@ -141,6 +142,7 @@ void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptur
status.transform.rotation = cameraRotation;

StartCoroutine(PostToFaceAPI(imageBufferList.ToArray(), cameraToWorldMatrix, pixelToCameraMatrix));
//StartCoroutine(PostToFaceAPI(System.IO.File.ReadAllBytes("nyou045.png"), cameraToWorldMatrix, pixelToCameraMatrix));
}
photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
}
Expand Down Expand Up @@ -168,6 +170,10 @@ void Awake()
status.GetComponent<TextMesh>().text = "taking photo...";
status.SetActive(true);
PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);
} else
{
status.GetComponent<TextMesh>().text = "busy...";
status.SetActive(true);
}
};
recognizer.StartCapturingGestures();
Expand Down
212 changes: 194 additions & 18 deletions Assets/Scripts/JSON_test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,204 @@

public class JSON_test : MonoBehaviour
{

public GameObject textPrefab;

// Use this for initialization
void Start()
{
string json = "[{\"faceId\":\"5cfdda25 - 743e-482d - 9d33 - 5806f8bf5056\",\"faceRectangle\":{\"top\":891,\"left\":18,\"width\":64,\"height\":64},\"faceAttributes\":{\"smile\":0.024,\"headPose\":" +
"{\"pitch\":0.0,\"roll\":-3.1,\"yaw\":-7.3},\"gender\":\"male\",\"age\":25.4,\"facialHair\":{\"moustache\":0.6,\"beard\":0.6,\"sideburns\":0.5},\"glasses\":\"ReadingGlasses\"}}]";
JSONObject j = new JSONObject(json);
JSONObject result = j.list[0];
GameObject txtObject = (GameObject)Instantiate(textPrefab);
TextMesh txtMesh = txtObject.GetComponent<TextMesh>();
var a = result.GetField("faceAttributes");
var f = a.GetField("facialHair");
//var p = result.GetField("faceRectangle");
txtMesh.text = string.Format("Gender: {0}\nAge: {1}\nMoustache: {2}\nBeard: {3}\nSideburns: {4}\nGlasses: {5}\nSmile: {6}", a.GetField("gender").str, a.GetField("age"), f.GetField("moustache"), f.GetField("beard"), f.GetField("sideburns"), a.GetField("glasses").str, a.GetField("smile"));
txtMesh.color = Color.red; // Set the text's color to red
}

// Update is called once per frame
void Update()
string json = @"[
{
""kairos"": {
""eyeDistance"": 16,
""topLeftX"": 29,
""topLeftY"": 30,
""chinTipX"": 45,
""width"": 36,
""yaw"": 7,
""chinTipY"": 68,
""confidence"": 0.9993,
""height"": 36,
""rightEyeCenterY"": 39,
""rightEyeCenterX"": 37,
""leftEyeCenterY"": 39,
""leftEyeCenterX"": 54,
""pitch"": -4,
""attributes"": {
""gender"": {
""femaleConfidence"": 0,
""type"": ""M"",
""maleConfidence"": 1
},
""age"": 27,
""hispanic"": 0.02015,
""lips"": ""Together"",
""other"": 0.00129,
""black"": 2e-05,
""asian"": 9e-05,
""white"": 0.97845,
""glasses"": ""None""
},
""face_id"": 1,
""quality"": 0.8038,
""roll"": 0
},
""text"": ""Age: 27\nGender: M\nEthnicity: white: 98%, hispanic: 2%\nGlasses: None\nLips: Together\nEmotion: happiness: 78%\nSmile: 44%\nBeauty: F:56%, M:56%\nRecognition confidence: 93.96%\nUPI: nyou045\nName: Mr Nick Young\nPosition: Research IT Specialist\nDepartment: Computer Science\nReports to: Mr Marcus Gustafsson\n"",
""fpp"": {
""attributes"": {
""emotion"": {
""neutral"": 20.253,
""sadness"": 0.673,
""disgust"": 0.907,
""anger"": 0.053,
""surprise"": 0.3,
""fear"": 0.053,
""happiness"": 77.761
},
""beauty"": {
""female_score"": 56.236,
""male_score"": 55.571
},
""gender"": {
""value"": ""Male""
},
""age"": {
""value"": 30
},
""eyestatus"": {
""left_eye_status"": {
""normal_glass_eye_open"": 0.034,
""no_glass_eye_close"": 0.0,
""occlusion"": 0.0,
""no_glass_eye_open"": 99.966,
""normal_glass_eye_close"": 0.0,
""dark_glasses"": 0.0
},
""right_eye_status"": {
""normal_glass_eye_open"": 0.397,
""no_glass_eye_close"": 0.0,
""occlusion"": 0.0,
""no_glass_eye_open"": 99.601,
""normal_glass_eye_close"": 0.002,
""dark_glasses"": 0.0
}
},
""glass"": {
""value"": ""None""
},
""headpose"": {
""yaw_angle"": 1.8853482,
""pitch_angle"": 6.320396,
""roll_angle"": -2.5211878
},
""blur"": {
""blurness"": {
""threshold"": 50.0,
""value"": 1.488
},
""motionblur"": {
""threshold"": 50.0,
""value"": 1.488
},
""gaussianblur"": {
""threshold"": 50.0,
""value"": 1.488
}
},
""smile"": {
""threshold"": 30.1,
""value"": 44.069
},
""facequality"": {
""threshold"": 70.1,
""value"": 92.136
},
""ethnicity"": {
""value"": ""White""
}
},
""face_token"": ""f163a6c3c07461e71f5da1eab755ce36"",
""face_rectangle"": {
""width"": 37,
""top"": 32,
""height"": 37,
""left"": 27
}
},
""of"": {
""confidence"": 0.9395938787156883,
""data"": {
""phoneNumbers"": [
{
""phone"": ""+64 9 923 9740"",
""type"": ""ddi""
},
{
""phone"": ""89740"",
""type"": ""extension""
}
],
""orgUnits"": [
""COMSCI"",
""SCIFAC""
],
""upi"": ""nyou045"",
""groupProfile"": false,
""positions"": [
{
""department"": {
""name"": ""Computer Science"",
""unit"": ""COMSCI""
},
""position"": ""Research IT Specialist"",
""orgUnits"": [
{
""name"": ""Faculty of Science"",
""unit"": ""SCIFAC""
}
],
""reportsTo"": {
""positionId"": 2,
""url"": ""m-gustafsson"",
""name"": ""Mr Marcus Gustafsson""
}
}
],
""image"": ""/people/imageraw/nick-young/10547437/large"",
""profileUrl"": ""nick-young"",
""fullName"": ""Mr Nick Young"",
""emailAddresses"": [
""nick.young@auckland.ac.nz"",
""nyou045@aucklanduni.ac.nz""
]
},
""uid"": ""nyou045"",
""face_rectangle"": {
""width"": 37,
""top"": 30,
""left"": 25,
""height"": 37
}
}
}
]";
JSONObject j = new JSONObject(json);
Debug.Log(j[0]["text"].str);
}
}
Binary file modified Assets/main.unity
Binary file not shown.

0 comments on commit 19e1f96

Please sign in to comment.