public void resetData() { NextUid = 0; var dataMap = new Dictionary <int, PupilData>(); foreach (var data in PupilDeploy.Datas) { var pupilData = new PupilData(); pupilData.DId = data.Key; pupilData.Level = 1; pupilData.MaxExp = 200; pupilData.CurExp = 0; pupilData.SetAttr(EAttrType.WuXing, data.Value.BaseAttr.WuXing); pupilData.SetAttr(EAttrType.ZiZhi, data.Value.BaseAttr.ZiZhi); pupilData.SetAttr(EAttrType.WaiGong, data.Value.BaseAttr.WaiGong); pupilData.SetAttr(EAttrType.NeiGong, data.Value.BaseAttr.NeiGong); pupilData.SetAttr(EAttrType.ShenFa, data.Value.BaseAttr.ShenFa); pupilData.SetAttr(EAttrType.ShengMing, data.Value.BaseAttr.ShengMing); pupilData.SetAttr(EAttrType.ZhenQi, data.Value.BaseAttr.ZhenQi); pupilData.SetAttr(EAttrType.GongJi, data.Value.BaseAttr.GongJi); pupilData.SetAttr(EAttrType.FangYu, data.Value.BaseAttr.FangYu); pupilData.SetAttr(EAttrType.MingZhong, data.Value.BaseAttr.MingZhong); pupilData.SetAttr(EAttrType.ShanBi, data.Value.BaseAttr.ShanBi); pupilData.SetAttr(EAttrType.BaoJi, data.Value.BaseAttr.BaoJi); pupilData.SetAttr(EAttrType.KangBao, data.Value.BaseAttr.KangBao); dataMap.Add(++NextUid, pupilData); } Data = dataMap; }
private static void UpdateGaze() { foreach (var key in gazeKeys) { if (gazeDictionary.ContainsKey(key)) { switch (key) { case "norm_pos": // 2D case eyeDataKey = key + "_" + stringForEyeID(); // we add the identifier to the key PupilData.AddGazeToEyeData(eyeDataKey, Position(gazeDictionary[key], false)); break; case "eye_centers_3d": case "gaze_normals_3d": // in case of eye_centers_3d and gaze_normals_3d, we get an dictionary with one positional object for each eye id (the key) if (gazeDictionary [key] is Dictionary <object, object> ) { foreach (var item in (gazeDictionary[key] as Dictionary <object, object>)) { eyeDataKey = key + "_" + item.Key.ToString(); PupilData.AddGazeToEyeData(eyeDataKey, Position(item.Value, true)); } } break; default: PupilData.AddGazeToEyeData(key, Position(gazeDictionary[key], true)); break; } } } }
//private void TrackPupil(PupilData p0data, PupilData p1data, float ex, float ey) private void TrackPupil(PupilData p0data, PupilData p1data) { float nx = -p1data.norm_pos[0] + 0.5f; float nz = -p1data.norm_pos[1] + 0.5f; nx *= boardWidth; nz *= boardHeight; float tx = p0data.norm_pos[0] - 0.5f; float tz = p0data.norm_pos[1] - 0.5f; tx *= boardWidth; tz *= boardHeight; nx = GlobalVars.k01 * nx + GlobalVars.k02 * nz + GlobalVars.k03; nz = GlobalVars.k04 * nx + GlobalVars.k05 * nz + GlobalVars.k06; tx = GlobalVars.k11 * tx + GlobalVars.k12 * tz + GlobalVars.k13; tz = GlobalVars.k14 * tx + GlobalVars.k15 * tz + GlobalVars.k16; float gx = (tx + nx) / 2f; float gz = (tz + nz) / 2f; float y = -0.05f; //nx -= ex; nz -= ey; //tx -= ex; tz -= ey; //gx -= ex; tz -= ey; pupil0.transform.localPosition = new Vector3(nx, y, nz); pupil1.transform.localPosition = new Vector3(tx, y, tz); gaze.transform.localPosition = new Vector3(gx, y, gz); }
private void PushToBuffer(PupilData p0data, PupilData p1data) { if (buffer_counter < buffer_size) { buffer[0, buffer_counter] = p0data; buffer[1, buffer_counter] = p1data; errorBuffer[buffer_counter, 0] = cursor.transform.position.x; errorBuffer[buffer_counter, 1] = cursor.transform.position.y; buffer_counter++; } else { PupilData p0 = new PupilData(); PupilData p1 = new PupilData(); float ex = 0, ey = 0; for (int i = 0; i < buffer_size; i++) { p0.norm_pos[0] += buffer[0, i].norm_pos[0]; p0.norm_pos[1] += buffer[0, i].norm_pos[1]; p1.norm_pos[0] += buffer[1, i].norm_pos[0]; p1.norm_pos[1] += buffer[1, i].norm_pos[1]; ex += errorBuffer[i, 0]; ey += errorBuffer[i, 1]; } p0.norm_pos[0] /= (float)buffer_size; p0.norm_pos[1] /= (float)buffer_size; p1.norm_pos[0] /= (float)buffer_size; p1.norm_pos[1] /= (float)buffer_size; ex /= (float)buffer_size; ey /= (float)buffer_size; //TrackPupil(p0, p1, ex, ey); buffer_counter = 0; } }
private void ReportDataToTrackingManager(string rawdata) { if (rawdata == null) { Debug.Log("Received a frame but data was null"); return; } String[] dataset = rawdata.Split('\n'); foreach (var data in dataset) { if (String.IsNullOrEmpty(data)) { continue; } PupilData pupildata = JsonConvert.DeserializeObject <PupilData>(data); if (preData == null && pupildata.topic.EndsWith(".1.")) { continue; } if (pupildata.topic.EndsWith(".0.")) { preData = pupildata; } else if (pupildata.confidence >= 0.60 && preData.confidence >= 0.60) { //PushToBuffer(preData, pupildata); TrackPupil(preData, pupildata); } } }
public TrackData() { eyesROI = new Rectangle(); leftROI = new Rectangle(); rightROI = new Rectangle(); pupilDataLeft = new PupilData(); pupilDataRight = new PupilData(); glintDataLeft = new GlintData(); glintDataRight = new GlintData(); calibrationDataLeft = new CalibrationData(); calibrationDataRight = new CalibrationData(); gazeDataRaw = new GTGazeData(); gazeDataSmoothed = new GTGazeData(); //eyeMovement = new GazeTrackingLibrary.EyeMovement.Classifier(); eyesDetected = false; eyeDetected = false; pupilLeftDetected = false; pupilRightDetected = false; glintsLeftDetected = false; glintsRightDetected = false; }
void ReceivePupilData(PupilData pupilData) { double unityTime = timeSync.ConvertToUnityTime(pupilData.PupilTimestamp); Debug.Log($"Receive Pupil Data with method {pupilData.Method} and confidence {pupilData.Confidence} at {unityTime}"); if (pupilData.EyeIdx == 0) { Debug.Log($"theta {Mathf.Rad2Deg * pupilData.Circle.Theta} phi {Mathf.Rad2Deg * pupilData.Circle.Phi}"); } }
private static void UpdateEyeID() { string id = ""; if (gazeDictionary != null) { if (gazeDictionary.TryGetValue("id", out IDo)) { id = IDo.ToString(); } } PupilData.UpdateCurrentEyeID(id); }
public ActionResult PostUsername([FromBody] PupilData pupilData) { var pupil = new Pupil { Username = pupilData.Username, Password = pupilData.Password, SolvedProblems = 0 }; DbContext.Add(pupil); DbContext.SaveChanges(); return(Ok("User registered")); }
private static void UpdateGaze() { CheckModeConsistency(); foreach (var key in gazeKeys) { if (gazeDictionary.ContainsKey(key)) { switch (key) { case "norm_pos": // 2D case eyeDataKey = key + "_" + StringFromDictionary(gazeDictionary, "id"); // we add the identifier to the key var position2D = Position(gazeDictionary [key], false); PupilData.AddGazeToEyeData(eyeDataKey, position2D); if (isRecording) { AddToRecording(eyeDataKey, position2D, true); } break; case "eye_centers_3d": case "gaze_normals_3d": // in case of eye_centers_3d and gaze_normals_3d, we get an dictionary with one positional object for each eye id (the key) if (gazeDictionary [key] is Dictionary <object, object> ) { foreach (var item in (gazeDictionary[key] as Dictionary <object, object>)) { eyeDataKey = key + "_" + item.Key.ToString(); var position = Position(item.Value, true); position.y *= -1f; // Pupil y axis is inverted PupilData.AddGazeToEyeData(eyeDataKey, position); } } break; default: var position3D = Position(gazeDictionary [key], true); position3D.y *= -1f; // Pupil y axis is inverted PupilData.AddGazeToEyeData(key, position3D); if (isRecording) { AddToRecording(key, position3D); } break; } } } }
private static PupilData ConvertPupilToAbsolute(EyeEnum eye, PupilData pupilData, TrackData trackData) { var eyeROI = new Rectangle(); if (eye == EyeEnum.Left) { eyeROI = trackData.LeftROI; } else { eyeROI = trackData.RightROI; } pupilData.Center.X += eyeROI.X; pupilData.Center.Y += eyeROI.Y; pupilData.Blob.CenterOfGravity = new GTPoint(pupilData.Blob.CenterOfGravity.X + eyeROI.X, pupilData.Blob.CenterOfGravity.Y + eyeROI.Y); return(pupilData); }
void OnGUI() { #if !UNITY_WSA string str; // print ("confidence 0 in op mon : " + Pupil.values.Confidences [0]); Operator.properties.Properties [0].confidence = PupilTools.Confidence(PupilData.leftEyeID); Operator.properties.Properties [1].confidence = PupilTools.Confidence(PupilData.rightEyeID); // print (Pupil.values.Confidences [0]); GUI.color = new Color(1, 1, 1, .5f); float imageHeight = (Screen.width / 2) / 1.333f; //for 4:3 ratio float imageVerticalPosition = (Screen.height - imageHeight) / 2; GUI.DrawTexture(new Rect(0, imageVerticalPosition, Screen.width / 2, imageHeight), pupilSettings.framePublishing.eye0Image); GUI.DrawTexture(new Rect(Screen.width / 2, imageVerticalPosition, Screen.width / 2, imageHeight), pupilSettings.framePublishing.eye1Image); Operator.properties.Properties [0].OperatorCamera.Render(); //Construct the Text box string for data display on the Operator Monitor view str = "Gaze Point : " + " ( X: " + PupilData._3D.GazePosition.x + " Y: " + PupilData._3D.GazePosition.y + " Z: " + PupilData._3D.GazePosition.z + " ) "; str += "\nEyeball 0 Center : " + " ( X: " + PupilData._3D.RightEyeCenter.x + " Y: " + PupilData._3D.RightEyeCenter.y + " Z: " + PupilData._3D.RightEyeCenter.z + " ) "; str += "\nEyeball 1 Center : " + " ( X: " + PupilData._3D.LeftEyeCenter.x + " Y: " + PupilData._3D.LeftEyeCenter.y + " Z: " + PupilData._3D.LeftEyeCenter.z + " ) "; str += "\nPupil Diameter : " + PupilData.Diameter(); //Use the predefined style for the TextArea GUIStyle _s = pupilTracker.Styles.Find(x => x.name == "OpMon_textArea"); GUI.TextArea(new Rect(0, 0, Screen.width, 200), str, _s); //This is the call to draw both Confidence Graphs for each eyes DrawGraph(Operator.properties.Properties[0]); DrawGraph(Operator.properties.Properties[1]); #endif }
void CollectCalibrationDataAtScene(int scene) { GameObject point; switch (scene) { case 1: point = point1; break; case 2: point = point2; break; case 3: point = point3; break; case 4: point = point4; break; default: point = point1; break; } string rawdata = lastPacket; if (rawdata == null) { Debug.Log("Received a frame but data was null"); return; } String[] dataset = rawdata.Split('\n'); foreach (var data in dataset) { if (String.IsNullOrEmpty(data)) { continue; } // Debug.Log("Read data: " + data); PupilData pupildata = JsonConvert.DeserializeObject <PupilData>(data); if (pupildata.confidence >= 0.60) { if (pupildata.topic.EndsWith(".0.")) { if (dataSize0 < sizeGoal) { errorx0[dataSize0] = cursor.transform.position.x - basex; errory0[dataSize0] = cursor.transform.position.y - basey; pupil0Data[dataSize0++] = pupildata; } } else { if (dataSize1 < sizeGoal) { errorx1[dataSize1] = cursor.transform.position.x - basex; errory1[dataSize1] = cursor.transform.position.y - basey; pupil1Data[dataSize1++] = pupildata; } } } } int dataSize = dataSize0 + dataSize1; float ratio = (float)dataSize / ((float)sizeGoal * 2f); Color newColor = new Color(1f - ratio, ratio / 3f, 0F); Material m = point.GetComponent <Renderer>().material; m.SetColor("_EmissionColor", newColor); Debug.Log("Scene: " + clickCounter + " | Frame: " + dataSize); }
public void WriteFrameGray(string name, string extraAttrib = null) { if (write) { m_writer.WriteStartElement(name); m_writer.WriteAttributeString("timestamp", (Time.time - startTime).ToString()); //Gaze data. try { GazePoint point = gaze.LeftEye.GazePoint; if (point.Validity == Validity.Valid) { m_writer.WriteAttributeString("lefteyex", point.PositionOnDisplayArea.X.ToString()); m_writer.WriteAttributeString("lefteyey", point.PositionOnDisplayArea.Y.ToString()); } else { m_writer.WriteAttributeString("lefteyex", "invalid"); m_writer.WriteAttributeString("lefteyey", "invalid"); } PupilData pupil = gaze.LeftEye.Pupil; if (pupil.Validity == Validity.Valid) { m_writer.WriteAttributeString("leftpupil", pupil.PupilDiameter.ToString()); } else { m_writer.WriteAttributeString("leftpupil", "invalid"); } if (extraAttrib != null) { m_writer.WriteAttributeString("result", extraAttrib); } point = gaze.RightEye.GazePoint; if (point.Validity == Validity.Valid) { m_writer.WriteAttributeString("righteyex", point.PositionOnDisplayArea.X.ToString()); m_writer.WriteAttributeString("righteyey", point.PositionOnDisplayArea.Y.ToString()); } else { m_writer.WriteAttributeString("righteyex", "invalid"); m_writer.WriteAttributeString("righteyey", "invalid"); } pupil = gaze.RightEye.Pupil; if (pupil.Validity == Validity.Valid) { m_writer.WriteAttributeString("rightpupil", pupil.PupilDiameter.ToString()); } else { m_writer.WriteAttributeString("rightpupil", "invalid"); } } catch {} if (extraAttrib != null) { m_writer.WriteAttributeString("result", extraAttrib); } //Done! m_writer.WriteEndElement(); } }
public void InitializeSubscriptionSocket() { if (subscribeSocket != null) { subscribeSocket.Close(); } if (topicList.Count == 0) { return; } subscribeSocket = new SubscriberSocket(IPHeader + subport); //André: Is this necessary?? subscribeSocket.Options.SendHighWatermark = PupilSettings.numberOfMessages; // 6; foreach (var topic in topicList) { subscribeSocket.Subscribe(topic); } subscribeSocket.ReceiveReady += (s, a) => { int i = 0; NetMQMessage m = new NetMQMessage(); while (a.Socket.TryReceiveMultipartMessage(ref m)) { // We read all the messages from the socket, but disregard the ones after a certain point if (i > PupilSettings.numberOfMessages) // 6) { continue; } mStream = new MemoryStream(m[1].ToByteArray()); string msgType = m[0].ConvertToString(); if (PupilSettings.Instance.debug.printMessageType) { Debug.Log(msgType); } if (PupilSettings.Instance.debug.printMessage) { Debug.Log(MessagePackSerializer.ToJson(m[1].ToByteArray())); } if (PupilSettings.Instance.dataProcess.state != PupilSettings.EStatus.ProcessingGaze) { continue; } switch (msgType) { case "gaze": case "pupil.0": case "pupil.1": var dictionary = MessagePackSerializer.Deserialize <Dictionary <string, object> > (mStream); if (PupilData.ConfidenceForDictionary(dictionary) > 0.6f) { if (msgType == "gaze") { PupilData.gazeDictionary = dictionary; } else if (msgType == "pupil.0") { PupilData.pupil0Dictionary = dictionary; } else if (msgType == "pupil.1") { PupilData.pupil1Dictionary = dictionary; } } break; default: Debug.Log(msgType); foreach (var item in MessagePackSerializer.Deserialize <Dictionary <string, object> > (mStream)) { Debug.Log(item.Key); Debug.Log(item.Value.ToString()); } break; } i++; } }; }
// //Helper methods // //Log the state of the current frame private void WriteFrame(string name, string extraAttrib = null) { if (write) { //Writing this frame... m_writer.WriteStartElement(name); //This is our relevant data: // Transform t = gameObjectToLog.transform; m_writer.WriteAttributeString("distance", Vector3.Distance (t.position, goalDestination).ToString()); m_writer.WriteAttributeString("pose", t.rotation.eulerAngles.y.ToString()); m_writer.WriteAttributeString("timestamp", (Time.time - startTime).ToString()); m_writer.WriteAttributeString("x", (t.position.x - relativeOrigin.x).ToString()); m_writer.WriteAttributeString("y", (t.position.z - relativeOrigin.z).ToString()); //Gaze data. try { GazePoint point = gaze.LeftEye.GazePoint; if (point.Validity == Validity.Valid) { m_writer.WriteAttributeString("lefteyex", point.PositionOnDisplayArea.X.ToString()); m_writer.WriteAttributeString("lefteyey", point.PositionOnDisplayArea.Y.ToString()); } else { m_writer.WriteAttributeString("lefteyex", "invalid"); m_writer.WriteAttributeString("lefteyey", "invalid"); } PupilData pupil = gaze.LeftEye.Pupil; if (pupil.Validity == Validity.Valid) { m_writer.WriteAttributeString("leftpupil", pupil.PupilDiameter.ToString()); } else { m_writer.WriteAttributeString("leftpupil", "invalid"); } if (extraAttrib != null) { m_writer.WriteAttributeString("result", extraAttrib); } point = gaze.RightEye.GazePoint; if (point.Validity == Validity.Valid) { m_writer.WriteAttributeString("righteyex", point.PositionOnDisplayArea.X.ToString()); m_writer.WriteAttributeString("righteyey", point.PositionOnDisplayArea.Y.ToString()); } else { m_writer.WriteAttributeString("righteyex", "invalid"); m_writer.WriteAttributeString("righteyey", "invalid"); } pupil = gaze.RightEye.Pupil; if (pupil.Validity == Validity.Valid) { m_writer.WriteAttributeString("rightpupil", pupil.PupilDiameter.ToString()); } else { m_writer.WriteAttributeString("rightpupil", "invalid"); } } catch {} if (extraAttrib != null) { m_writer.WriteAttributeString("result", extraAttrib); } //Done! m_writer.WriteEndElement(); } }
void ReceiveData(PupilData data) { pupilDiameter = data.Diameter3d; }