void OnPacket(Pupil.PupilData3D data) { //add new frame _gazeFps.AddFrame(); if (m_status == EStatus.ProcessingGaze) //gaze processing stage { int id = data.base_data [0].id; float x, y; x = (float)data.norm_pos [0]; y = (float)data.norm_pos [1]; _eyePos.x = (leftEye.gaze.x + rightEye.gaze.x) * 0.5f; _eyePos.y = (leftEye.gaze.y + rightEye.gaze.y) * 0.5f; if (id == 0) { _eyeFps[0].AddFrame(); leftEye.AddGaze(x, y); if (OnEyeGaze != null) { OnEyeGaze(this, id); } } else if (id == 1) { _eyeFps[1].AddFrame(); rightEye.AddGaze(x, y); if (OnEyeGaze != null) { OnEyeGaze(this, id); } } } else if (m_status == EStatus.Calibration) //gaze calibration stage { float t = GetPupilTimestamp(); floatArray[] _cPoints = GetCalibPoints; float[] _cPointFloatValues = _cPoints [_currCalibPoint].axisValues; var ref0 = new Dictionary <string, object>() { { "norm_pos", _cPointFloatValues }, { "timestamp", t }, { "id", 0 } }; var ref1 = new Dictionary <string, object>() { { "norm_pos", _cPointFloatValues }, { "timestamp", t }, { "id", 1 } }; //keeping this until the new calibration method is not yet tested // var ref0=new Dictionary<string,object>(){{"norm_pos",new float[]{_calibPoints[_currCalibPoint].x,_calibPoints[_currCalibPoint].y}},{"timestamp",t},{"id",0}}; // var ref1=new Dictionary<string,object>(){{"norm_pos",new float[]{_calibPoints[_currCalibPoint].x,_calibPoints[_currCalibPoint].y}},{"timestamp",t},{"id",1}}; //If OnCalibData delegate has assigned function from the Calibration Marker, assign the current calibration position to it. _CalibData(_cPointFloatValues); _calibrationData.Add(ref0); _calibrationData.Add(ref1); //Increment the current calibration sample. (Default sample amount per calibration point is 120) _currCalibSamples++; print("Sampling at : " + _currCalibSamples); //give a small timeout per sample. Thread.Sleep(1000 / 60); //If the current calibration sample is bigger or equal to the desired sampling (so we accomplished sampling for this calibration point), //null the current sample and step to next calbration point. //Also prepare calibration data for sending, and send it. if (_currCalibSamples >= _calibSamples) { _currCalibSamples = 0; _currCalibPoint++; //reformat the calibration data for sending. string pointsData = "["; int index = 0; foreach (var v in _calibrationData) { pointsData += JsonUtility.ToJson(v); //String.Format("{'norm_pos':({0},{1}),'timestamp':{2},'id':{3}}",v.norm_pos[0],v.norm_pos[1],v.timestamp,v.id); ++index; if (index != _calibrationData.Count) { pointsData += ","; } } pointsData += "]"; // pointsData = JsonUtility.ToJson (_CalibrationPoints); //Debug.Log (pointsData); //Send the current relevant calibration data for the current calibration point. _sendRequestMessage(new Dictionary <string, object> { { "subject", "calibration.add_ref_data" }, { "ref_data", _CalibrationPoints } }); //Clear the current calibration data, so we can proceed to the next point if there is any. _calibrationData.Clear(); //Stop calibration if we accomplished all required calibration target. if (_currCalibPoint >= _cPoints.Length) { StopCalibration(); } } } }
void OnPacket(Pupil.PupilData3D data) { //add new frame _gazeFPS++; var ct = DateTime.Now; if ((ct - _lastT).TotalSeconds > 1) { _lastT = ct; _currentFps = _gazeFPS; _gazeFPS = 0; } if (m_status == EStatus.ProcessingGaze) //gaze processing stage { float x, y; x = (float)data.norm_pos [0]; y = (float)data.norm_pos [1]; _eyePos.x = (leftEye.gaze.x + rightEye.gaze.x) * 0.5f; _eyePos.y = (leftEye.gaze.y + rightEye.gaze.y) * 0.5f; if (data.id == 0) { leftEye.AddGaze(x, y); if (OnEyeGaze != null) { OnEyeGaze(this); } } else if (data.id == 1) { rightEye.AddGaze(x, y); if (OnEyeGaze != null) { OnEyeGaze(this); } } } else if (m_status == EStatus.Calibration) //gaze calibration stage { float t = GetPupilTimestamp(); var ref0 = new Dictionary <string, object>() { { "norm_pos", new float[] { _calibPoints[_currCalibPoint].x, _calibPoints[_currCalibPoint].y } }, { "timestamp", t }, { "id", 0 } }; var ref1 = new Dictionary <string, object>() { { "norm_pos", new float[] { _calibPoints[_currCalibPoint].x, _calibPoints[_currCalibPoint].y } }, { "timestamp", t }, { "id", 1 } }; _CalibData(_calibPoints [_currCalibPoint].x, _calibPoints [_currCalibPoint].y); _calibrationData.Add(ref0); _calibrationData.Add(ref1); _currCalibSamples++; Thread.Sleep(1000 / 60); if (_currCalibSamples >= _calibSamples) { _currCalibSamples = 0; _currCalibPoint++; string pointsData = "["; int index = 0; foreach (var v in _calibrationData) { pointsData += JsonUtility.ToJson(v); //String.Format("{'norm_pos':({0},{1}),'timestamp':{2},'id':{3}}",v.norm_pos[0],v.norm_pos[1],v.timestamp,v.id); ++index; if (index != _calibrationData.Count) { pointsData += ","; } } pointsData += "]"; // pointsData = JsonUtility.ToJson (_CalibrationPoints); //Debug.Log (pointsData); _sendRequestMessage(new Dictionary <string, object> { { "subject", "calibration.add_ref_data" }, { "ref_data", _CalibrationPoints } }); _calibrationData.Clear(); if (_currCalibPoint >= _calibPoints.Length) { StopCalibration(); } } } }
void OnPacket(Pupil.PupilData3D data) { float x, y; _gazeFPS++; ct = DateTime.Now; if ((ct - _lastT).TotalSeconds > 1) { _lastT = ct; _currentFps = _gazeFPS; _gazeFPS = 0; } if (m_status == EStatus.ProcessingGaze) //gaze processing stage { x = (float)data.norm_pos [0]; y = (float)data.norm_pos [1]; if (data.id == 0) { leftEye.AddGaze(x, y); } else if (data.id == 1) { rightEye.AddGaze(x, y); } centerEye.x = (leftEye.gaze.x + rightEye.gaze.x) * 0.5f; centerEye.y = (leftEye.gaze.y + rightEye.gaze.y) * 0.5f; } else if (m_status == EStatus.Calibration) //gaze calibration stage { // Get Pupil Timestamp _requestSocket.SendFrame("t"); NetMQMessage recievedMsg = _requestSocket.ReceiveMultipartMessage(); float t = float.Parse(recievedMsg[0].ConvertToString()); var ref0 = new Dictionary <string, object>() { { "norm_pos", new float[] { _calibPoints[_currCalibPoint].x, _calibPoints[_currCalibPoint].y } }, { "timestamp", t }, { "id", 0 } }; var ref1 = new Dictionary <string, object>() { { "norm_pos", new float[] { _calibPoints[_currCalibPoint].x, _calibPoints[_currCalibPoint].y } }, { "timestamp", t }, { "id", 1 } }; if (OnCalibrationData != null) { OnCalibrationData(this, _calibPoints [_currCalibPoint].x, _calibPoints [_currCalibPoint].y); } _calibrationData.Add(ref0); _calibrationData.Add(ref1); _currCalibSamples++; Thread.Sleep(1000 / 60); if (_currCalibSamples >= DefaultCalibrationCount) { _currCalibSamples = 0; _currCalibPoint++; _sendRequestMessage(new Dictionary <string, object> { { "subject", "calibration.add_ref_data" }, { "ref_data", _calibrationData.ToArray() } }); _calibrationData.Clear(); if (_currCalibPoint >= _calibPoints.Length) { StopCalibration(); } } } }