Exemple #1
0
        void Update()
        {
            _elapsed += Time.deltaTime;

            if (_elapsed < PupilSettings.Instance.recorder.recordingLength)
            {
                if (_pipe == null)
                {
                    OpenPipe();
                }
            }
            else
            {
                if (_pipe != null && PupilSettings.Instance.recorder.isFixedRecordingLength && _recorderState == RecorderState.RECORDING)
                {
                    Stop();
                }
            }

            if (_recorderState == RecorderState.STOPPING)
            {
                PupilTools.RepaintGUI();
                GameObject.Destroy(this.gameObject);
            }
        }
Exemple #2
0
 void OnDisable()
 {
     if (PupilTools.IsConnected)
     {
         PupilTools.UnSubscribeFrom("gaze");
     }
 }
Exemple #3
0
    public void StartCalibrationDebugView()
    {
        if (DebugViewVariables.DebugEyeMesh != null)
        {
            var a = (from tr in OffsetTransforms
                     where tr.name == "Debug View Origin Matrix"
                     select tr).FirstOrDefault() as DebugView._Transform;
            if (a.GO != null)
            {
                a.GO.SetActive(true);
            }

            if (pupilGazeTracker.OnCalibDebug == null)
            {
                pupilGazeTracker.OnCalibDebug += DrawCalibrationDebugView;
            }
            //			OnCalibDebug -= DrawCalibrationDebugView;
            pupilGazeTracker.OnUpdate -= CalibrationDebugInteraction;
            pupilGazeTracker.OnUpdate += CalibrationDebugInteraction;

            PupilTools.StartFramePublishing();
        }
        else
        {
            UnityEngine.Debug.LogWarning("Please assign a Debug Eye Mesh under the Settings Debug View Variables. Accessable in Developer Mode!");
            PupilSettings.Instance.debugView.active = false;
        }
    }
    public void StartVisualizingGaze()
    {
        Instance.OnUpdate += VisualizeGaze;

        PupilSettings.Instance.currentCamera = Camera.main;

        if (!PupilMarker.TryToReset(_markerLeftEye))
        {
            _markerLeftEye = new PupilMarker("LeftEye_2D", Color.green);
        }
        if (!PupilMarker.TryToReset(_markerRightEye))
        {
            _markerRightEye = new PupilMarker("RightEye_2D", Color.blue);
        }
        if (!PupilMarker.TryToReset(_markerGazeCenter))
        {
            _markerGazeCenter = new PupilMarker("Gaze_2D", Color.red);
        }
        if (!PupilMarker.TryToReset(_gaze3D))
        {
            _gaze3D = new PupilMarker("Gaze_3D", Color.yellow);
        }

        PupilTools.DataProcessState = EStatus.ProcessingGaze;
        PupilTools.SubscribeTo("gaze");
    }
//	public bool visualizeSphereProjection = false;

    void OnEnable()
    {
        // Main
        if (GetComponentInChildren <Camera> () == null)
        {
            Debug.Log("Frame Publisher could not find a Camera gameobject");
            return;
        }
        eyePublishingInitialized = new bool[] { false, false };

        PupilTools.SubscribeTo("frame.");

        PupilTools.Send(new Dictionary <string, object> {
            { "subject", "start_plugin" }, { "name", "Frame_Publisher" }
        });

//		// Sphere Projection
//		if (visualizeSphereProjection)
//		{
//			if (PupilTools.CalibrationMode == Calibration.Mode._3D)
//			{
//				PupilTools.SubscribeTo ("pupil.");
//			}
//			else
//				Debug.Log ("Sphere projections are only available for 3D calibration");
//		}

        PupilTools.OnReceiveData += CustomReceiveData;
    }
 void OnDisable()
 {
     if (PupilSettings.Instance.connection.isConnected)
     {
         PupilTools.UnSubscribeFrom("gaze");
     }
 }
    void UpdateSphereProjection(int eyeIndex, Dictionary <string, object> dictionary)
    {
        var innerDictionary = PupilTools.DictionaryFromDictionary(dictionary, "projected_sphere");

        if (innerDictionary != null)
        {
            foreach (var item in innerDictionary)
            {
                switch (item.Key.ToString())
                {
                case "angle":                 // Currently always 90
                    break;

                case "axes":
                    var axes = PixelPosition(item.Value);
                    axes.x = eyeTexture[eyeIndex].width / axes.x;
                    axes.y = eyeTexture[eyeIndex].height / axes.y;
                    sphereProjectionMaterial [eyeIndex].mainTextureScale = axes;
                    break;

                case "center":
                    var centerPosition = PixelPosition(item.Value);
                    centerPosition.x /= eyeTexture[eyeIndex].width;                    // / sphereProjectionMaterial [eyeIndex].mainTextureScale.x;
                    centerPosition.y /= eyeTexture[eyeIndex].height;                   // / sphereProjectionMaterial [eyeIndex].mainTextureScale.y;
                    sphereProjectionMaterial [eyeIndex].mainTextureOffset = centerPosition;
                    break;

                default:
                    break;
                }
            }
        }
    }
Exemple #8
0
    void OnDisable()
    {
        PupilGazeTracker._Instance = null;
        var pupilSettings = PupilSettings.Instance;

        PupilTools.SavePupilSettings(ref pupilSettings);
    }
Exemple #9
0
    void CloseShop()
    {
                #if UNITY_EDITOR // Operator window will only be available in Editor mode
        if (OperatorWindow.Instance != null)
        {
            OperatorWindow.Instance.Close();
        }
                #endif

        if (Settings.DataProcessState == PupilSettings.EStatus.Calibration)
        {
            PupilTools.StopCalibration();
        }

        PupilTools.StopEyeProcesses();

        Thread.Sleep(1);

        Settings.connection.CloseSockets();

        StopAllCoroutines();

        if (Recorder.isRecording)
        {
            Recorder.Stop();
        }

        PupilTools.RepaintGUI();

        Pupil.processStatus.eyeProcess0 = false;
        Pupil.processStatus.eyeProcess1 = false;
    }
Exemple #10
0
 public void Stop()
 {
     Recorder.isRecording = false;
     PupilTools.StopPupilServiceRecording();
     _recorderState        = RecorderState.PROCESSING;
     Recorder.isProcessing = true;
 }
Exemple #11
0
    public void StartVisualizingGaze()
    {
        Instance.OnUpdate += VisualizeGaze;

        PupilSettings.Instance.currentCamera = Camera.main;

        if (!PupilMarker.TryToReset(_markerLeftEye))
        {
            _markerLeftEye = new PupilMarker("LeftEye_2D", PupilSettings.leftEyeColor);
        }
        if (!PupilMarker.TryToReset(_markerRightEye))
        {
            _markerRightEye = new PupilMarker("RightEye_2D", PupilSettings.rightEyeColor);
        }

        if (!PupilMarker.TryToReset(_markerGazeCenter))
        {
            _markerGazeCenter = new PupilMarker("Gaze_2D", Color.red);
        }
        if (!PupilMarker.TryToReset(_gaze3D))
        {
            _gaze3D = new PupilMarker("Gaze_3D", Color.yellow);
        }

        PupilTools.IsGazing = true;
        PupilTools.SubscribeTo("gaze");
    }
Exemple #12
0
 void OnDisable()
 {
     if (PupilTools.IsConnected && PupilTools.DataProcessState == EStatus.ProcessingGaze)
     {
         PupilTools.UnSubscribeFrom("gaze");
         print("We stopped gazing");
     }
 }
        public static void StartCalibration()
        {
            PupilTools.OnCalibrationStarted += OnCalibrationStarted;
            PupilTools.OnCalibrationEnded   += OnCalibrationEnded;
            PupilTools.OnCalibrationFailed  += OnCalibrationFailed;

            PupilTools.StartCalibration();
        }
 void OnEnable()
 {
     if (PupilSettings.Instance.connection.isConnected)
     {
         PupilSettings.Instance.DataProcessState = PupilSettings.EStatus.ProcessingGaze;
         PupilTools.SubscribeTo("gaze");
     }
 }
Exemple #15
0
 void OnDisable()
 {
     if (PupilSettings.Instance.connection.isConnected && PupilSettings.Instance.DataProcessState == PupilSettings.EStatus.ProcessingGaze)
     {
         PupilTools.UnSubscribeFrom("gaze");
         print("We stopped gazing");
     }
 }
    public static void StopRecording()
    {
        PupilTools.Send(new Dictionary <string, object> {
            { "subject", "recording.should_stop" }
        });

        isRecording = false;
    }
	void OnEnable()
	{
		if (PupilTools.IsConnected)
		{
			PupilTools.DataProcessState = Pupil.EStatus.ProcessingGaze;
			PupilTools.SubscribeTo ("gaze");
		}
	}
 void OnEnable()
 {
     if (PupilTools.IsConnected)
     {
         PupilTools.IsGazing = true;
         PupilTools.SubscribeTo("gaze");
     }
 }
Exemple #19
0
    void CustomReceiveData(string topic, Dictionary <string, object> dictionary, byte[] thirdFrame = null)
    {
        if (topic.StartsWith("pupil"))
        {
            foreach (var item in dictionary)
            {
                switch (item.Key)
                {
                case "topic":
                case "method":
                case "id":
                    var textForKey = PupilTools.StringFromDictionary(dictionary, item.Key);
                    // Do stuff
                    break;

                case "confidence":
                    print("Conf : " + PupilTools.FloatFromDictionary(dictionary, item.Key));
                    // Do stuff
                    break;

                case "norm_pos":
                    print("Norm : " + PupilTools.VectorFromDictionary(dictionary, item.Key));
                    // Do stuff
                    break;

                case "ellipse":
                    var dictionaryForKey = PupilTools.DictionaryFromDictionary(dictionary, item.Key);
                    foreach (var pupilEllipse in dictionaryForKey)
                    {
                        switch (pupilEllipse.Key.ToString())
                        {
                        case "angle":
                            var angle = (float)(double)pupilEllipse.Value;
                            // Do stuff
                            break;

                        case "center":
                            print("Center : " + PupilTools.ObjectToVector(pupilEllipse.Value));
                            break;

                        case "axes":
                            print("Axes : " + PupilTools.ObjectToVector(pupilEllipse.Value));
                            // Do stuff
                            break;

                        default:
                            break;
                        }
                    }
                    // Do stuff
                    break;

                default:
                    break;
                }
            }
        }
    }
Exemple #20
0
 void OnEnable()
 {
     if (PupilTools.IsConnected)
     {
         PupilTools.IsGazing = true;
         PupilTools.SubscribeTo("gaze");
         eyeCamera.gameObject.AddComponent <FramePublishing>();
     }
 }
Exemple #21
0
    public void RunConnect()
    {
        if (Settings.connection.isLocal)
        {
            RunServiceAtPath();
        }

        StartCoroutine(PupilTools.Connect(retry: true, retryDelay: 5f));
    }
Exemple #22
0
 // Use this for initialization
 void Start()
 {
     // PupilTools.OnConnected += StartPupilSubscription;
     // PupilTools.OnDisconnecting += StopPupilSubscription;
     PupilTools.SubscribeTo("pupil.");
     PupilTools.SubscribeTo("gaze");
     PupilTools.OnReceiveData += CustomReceiveData;
     countDown = refreshTime;
 }
Exemple #23
0
        private void AddToLog()
        {
            if (PupilData._2D.GazePosition != Vector2.zero)
            {
                gazeToWorld = dedicatedCapture.ViewportToWorldPoint(new Vector3(PupilData._2D.GazePosition.x, PupilData._2D.GazePosition.y, Camera.main.nearClipPlane));
            }

            //var raycastHit = EyeRay.CurrentlyHit;
            var tmp = new
            {
                // default variables for all scenes
                a = DateTime.Now,
                b = (int)(1.0f / Time.unscaledDeltaTime), // frames per second during the last frame, could calucate an average frame rate instead
                //c = PupilManager.SceneClass.sceneStat,
                //cc = SceneTimer.sceneTimer,
                d = dedicatedCapture.transform.position.x,
                e = dedicatedCapture.transform.position.y,
                f = dedicatedCapture.transform.position.z,
                g = dedicatedCapture.transform.rotation.x,
                h = dedicatedCapture.transform.rotation.y,
                i = dedicatedCapture.transform.rotation.z,
                j = PupilData._2D.GazePosition != Vector2.zero ? PupilData._2D.GazePosition.x : double.NaN,
                k = PupilData._2D.GazePosition != Vector2.zero ? PupilData._2D.GazePosition.y : double.NaN,
                l = PupilData._2D.GazePosition != Vector2.zero ? gazeToWorld.x : double.NaN,
                m = PupilData._2D.GazePosition != Vector2.zero ? gazeToWorld.y : double.NaN,
                n = PupilData._2D.GazePosition != Vector2.zero ? PupilTools.FloatFromDictionary(PupilTools.gazeDictionary, "confidence") : double.NaN, // confidence value calculated after calibration

                /*
                 * // Baking tray variables
                 * o = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.position.x : double.NaN,
                 * p = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.position.y : double.NaN,
                 * q = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.position.z : double.NaN,
                 * r = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.rotation.x : double.NaN,
                 * s = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.rotation.y : double.NaN,
                 * t = SceneManage.loadTestScene == 2 ? SceneManage.getViveCtrlRight.transform.rotation.z : double.NaN,
                 * tt = SceneManage.loadTestScene == 2 ? ControllerGrabObject.bunLastActive.ctrlEventHolder : "null",
                 * ttt = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.name : "null",
                 * u = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.transform.position.x : double.NaN,
                 * v = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.transform.position.y : double.NaN,
                 * x = SceneManage.loadTestScene == 2 && ControllerGrabObject.objectInHand != null ? ControllerGrabObject.bunLastActive.bunActive.transform.position.z : double.NaN,
                 *
                 * // Museum variables
                 * cbis = SceneManage.loadTestScene == 3 && PaintingsSets.CurrentSet != null ? PaintingsSets.CurrentSet.SetName : "null",
                 * ord = SceneManage.loadTestScene == 3 ? PaintingsSets.myIntArrayString : "null",
                 * oo = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.name : "null",
                 * ox = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.position.x : double.NaN,
                 * oy = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.position.y : double.NaN,
                 * oz = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? raycastHit.transform.position.z : double.NaN,
                 * oox = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? CalculEyeGazeOnObject(raycastHit).x : double.NaN,
                 * ooy = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? CalculEyeGazeOnObject(raycastHit).y : double.NaN,
                 * ooz = SceneManage.loadTestScene == 3 && raycastHit.transform != null ? CalculEyeGazeOnObject(raycastHit).z : double.NaN
                 *
                 */
            };

            _toLog.Add(tmp);
        }
Exemple #24
0
 void OnEnable()
 {
     if (PupilTools.IsConnected)
     {
         PupilTools.IsGazing = true;
         PupilTools.SubscribeTo("gaze");
         eyeCamera.gameObject.AddComponent <FramePublishing>();
     }
     collisionCircleLayer = (1 << LayerMask.NameToLayer("Circle"));
 }
    void Start()
    {
        PupilData.calculateMovingAverage = true;

        sceneCamera     = gameObject.GetComponent <Camera> ();
        calibrationDemo = gameObject.GetComponent <CalibrationDemo> ();
        heading         = gameObject.GetComponent <LineRenderer> ();

        PupilTools.SubscribeTo("gaze");
    }
Exemple #26
0
        public FFmpegPipe(string name, int width, int height, int framerate, Codec codec)
        {
            PupilGazeTracker pupilTracker = PupilGazeTracker.Instance;

            name = "Unity_" + PupilSettings.Instance.currentCamera.name;
            string date = DateTime.Now.ToString("yyyy_MM_dd");
            string path = Application.dataPath + "/" + date;


            if (PupilSettings.Instance.recorder.isCustomPath)
            {
                path = PupilSettings.Instance.recorder.filePath + "/" + date;
            }

            path = path.Replace("Assets/", "");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            UnityEngine.Debug.Log(path);
            PupilTools.StartPupilServiceRecording(path);

            Thread.Sleep(200);             //Waiting for Pupil Service to create the incremented folder

            path += "/" + GetLastIncrement(path);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            Filename = "\"" + path + "/" + name + GetSuffix(codec) + "\"";

            var opt = "-y -f rawvideo -vcodec rawvideo -pixel_format rgb24";

            opt += " -video_size " + width + "x" + height;
            opt += " -framerate " + framerate;
            opt += " -loglevel warning -i - " + GetOptions(codec);
            opt += " " + Filename;

            var info = new ProcessStartInfo(FFmpegConfig.BinaryPath, opt);

            info.UseShellExecute        = false;
            info.CreateNoWindow         = true;
            info.RedirectStandardInput  = true;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;

            FilePath = path;

            _subprocess = Process.Start(info);
            _stdin      = new BinaryWriter(_subprocess.StandardInput.BaseStream);
        }
Exemple #27
0
    void Update()
    {
        if (updateInitialTranslation)
        {
            //might be inconsistent during the first frames -> updating until calibration starts
            UpdateEyesTranslation();
        }

        if (PupilTools.IsCalibrating)
        {
            PupilTools.Calibration.UpdateCalibration();
        }

        PupilTools.Connection.UpdateSubscriptionSockets();

        if (PupilTools.IsConnected && Input.GetKeyUp(KeyCode.C))
        {
            if (PupilTools.IsCalibrating)
            {
                PupilTools.StopCalibration();
            }
            else
            {
                PupilTools.StartCalibration();
                updateInitialTranslation = false;
            }
        }
#if !UNITY_WSA
        if (Input.GetKeyUp(KeyCode.R))
        {
            if (PupilTools.IsConnected)
            {
                if (!Recorder.isRecording)
                {
                    Recorder.isRecording = true;
                    Recorder.Start();
                }
                else
                {
                    Recorder.isRecording = false;
                    Recorder.Stop();
                }
            }
            else
            {
                print("Can not start recording without connection to pupil service");
            }
        }
#endif

        if (Instance.OnUpdate != null)
        {
            Instance.OnUpdate();
        }
    }
    void Update()
    {
        if (PupilTools.IsCalibrating)
        {
            PupilTools.Calibration.UpdateCalibration();
        }

        PupilTools.Connection.UpdateSubscriptionSockets();

        if (PupilTools.IsConnected && Input.GetKeyUp(KeyCode.C))
        {
            if (PupilTools.IsCalibrating)
            {
                PupilTools.StopCalibration();
            }
            else
            {
                PupilTools.StartCalibration();
            }
        }
#if !UNITY_WSA
        //Start Recording as soon as the scene is loaded after calibration successfully ended
        if (PupilTools.IsGazing)
        {
            if (!Recorder.isRecording)
            {
                Recorder.isRecording = true;
                Recorder.Start();
            }
        }
        //if (Input.GetKeyUp(KeyCode.R))
        //{
        //    if (PupilTools.IsConnected)
        //    {
        //        if (!Recorder.isRecording)
        //        {
        //            Recorder.isRecording = true;
        //            Recorder.Start();
        //        }
        //        else
        //        {
        //            Recorder.isRecording = false;
        //            Recorder.Stop();
        //        }
        //    }
        //    else
        //        print("Can not start recording without connection to pupil service");
        //}
#endif

        if (Instance.OnUpdate != null)
        {
            Instance.OnUpdate();
        }
    }
Exemple #29
0
    void StopBlinkSubscription()
    {
        UnityEngine.Debug.Log("Disconnected");

        PupilTools.Send(new Dictionary <string, object> {
            { "subject", "stop_plugin" }
            , { "name", "Blink_Detection" }
        });

        PupilTools.UnSubscribeFrom("blinks");
    }
Exemple #30
0
 // Use this for initialization
 void Start()
 {
     ConfidenceBarSlider.minValue = 0;
     ConfidenceBarSlider.maxValue = 1;
     // PupilTools.OnConnected += StartPupilSubscription;
     // PupilTools.OnDisconnecting += StopPupilSubscription;
     PupilTools.SubscribeTo("pupil.");
     PupilTools.SubscribeTo("gaze");
     PupilTools.OnReceiveData += CustomReceiveData;
     countDown = refreshTime;
 }