Exemple #1
0
    public void InitModules()
    {
        try
        {
            nuitrack.Nuitrack.Init();

            depthSensor     = nuitrack.DepthSensor.Create();
            userTracker     = nuitrack.UserTracker.Create();
            skeletonTracker = nuitrack.SkeletonTracker.Create();

            depthSensor.OnUpdateEvent             += DepthUpdate;
            userTracker.OnUpdateEvent             += UserUpdate;
            skeletonTracker.OnSkeletonUpdateEvent += SkeletonsUpdate;

            nuitrack.Nuitrack.Run();

            issuesProcessor        = (GameObject)Instantiate(issuesProcessorPrefab);
            depthUserVisualization = (GameObject)Instantiate(depthUserVisualizationPrefab);
            skeletonsVisualization = (GameObject)Instantiate(skeletonsVisualizationPrefab);
        }
        catch (Exception ex)
        {
            exceptionsLogger.AddEntry(ex.ToString());
        }
    }
Exemple #2
0
    void NuitrackInit()
    {
        try
        {
            if (nuitrackInitialized)
            {
                return;
            }
            //Debug.Log("Application.runInBackground " + Application.runInBackground);
            //CloseUserGen(); //just in case
            if (wifiConnect == WifiConnect.VicoVR)
            {
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
                nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.1.1");
            }
            else if (wifiConnect == WifiConnect.TVico)
            {
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
                nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.43.1");
            }
            else
            {
                nuitrack.Nuitrack.Init();
            }

            Debug.Log("Init OK");

            depthSensor = nuitrack.DepthSensor.Create();

            colorSensor = nuitrack.ColorSensor.Create();

            userTracker = nuitrack.UserTracker.Create();

            skeletonTracker = nuitrack.SkeletonTracker.Create();

            gestureRecognizer = nuitrack.GestureRecognizer.Create();

            handTracker = nuitrack.HandTracker.Create();

            nuitrack.Nuitrack.Run();
            Debug.Log("Run OK");

            ChangeModulsState(
                skeletonTrackerModuleOn,
                handsTrackerModuleOn,
                depthModuleOn,
                colorModuleOn,
                gesturesRecognizerModuleOn,
                userTrackerModuleOn
                );

            nuitrackInitialized = true;
            _threadRunning      = false;
        }
        catch (System.Exception ex)
        {
            initException = ex;
            Debug.LogError(ex.ToString());
        }
    }
Exemple #3
0
    void InitSensors()
    {
        depthSensor = nuitrack.DepthSensor.Create();

        colorSensor = nuitrack.ColorSensor.Create();

        userTracker = nuitrack.UserTracker.Create();

        skeletonTracker = nuitrack.SkeletonTracker.Create();

        gestureRecognizer = nuitrack.GestureRecognizer.Create();

        handTracker = nuitrack.HandTracker.Create();

        nuitrack.Nuitrack.Run();
        Debug.Log("Run OK");

        ChangeModulsState(
            skeletonTrackerModuleOn,
            handsTrackerModuleOn,
            depthModuleOn,
            colorModuleOn,
            gesturesRecognizerModuleOn,
            userTrackerModuleOn
            );

        initSuccessful = true;
    }
    public void ReleaseNuitrack()
    {
        if (depthSensorInit != null)
        {
            depthSensorInit.OnUpdateEvent -= DepthUpdate;
        }
        if (colorSensorInit != null)
        {
            colorSensorInit.OnUpdateEvent -= ColorUpdate;
        }
        if (userTrackerInit != null)
        {
            userTrackerInit.OnUpdateEvent -= UserUpdate;
        }
        if (skeletonTrackerInit != null)
        {
            skeletonTrackerInit.OnSkeletonUpdateEvent -= SkeletonsUpdate;
        }
        if (handTrackerInit != null)
        {
            handTrackerInit.OnUpdateEvent -= HandTrackerUpdate;
        }
        if (gestureRecognizerInit != null)
        {
            gestureRecognizerInit.OnNewGesturesEvent -= GesturesUpdate;
        }

        if (issuesProcessor != null)
        {
            Destroy(issuesProcessor);
        }
        if (depthUserVisualization != null)
        {
            Destroy(depthUserVisualization);
        }
        if (skeletonsVisualization != null)
        {
            Destroy(skeletonsVisualization);
        }
        if (handTrackerVisualization != null)
        {
            Destroy(handTrackerVisualization);
        }
        if (gesturesVisualization != null)
        {
            Destroy(gesturesVisualization);
        }

        depthSensorInit       = null;
        colorSensorInit       = null;
        userTrackerInit       = null;
        skeletonTrackerInit   = null;
        handTrackerInit       = null;
        gestureRecognizerInit = null;

        nuitrack.Nuitrack.Release();
    }
Exemple #5
0
 void OnDestroy()
 {
     try
     {
         skeletonTracker = null;
         nuitrack.Nuitrack.Release();
     }
     catch (Exception ex)
     {
         exceptionsLogger.AddEntry(ex.ToString());
     }
 }
Exemple #6
0
    public void CloseUserGen()
    {
        try
        {
            if (depthSensor != null)
            {
                depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            }
            if (colorSensor != null)
            {
                colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            }
            if (userTracker != null)
            {
                userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            }
            if (skeletonTracker != null)
            {
                skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            }
            if (gestureRecognizer != null)
            {
                gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            }
            if (handTracker != null)
            {
                handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            }

            depthFrame      = null;
            colorFrame      = null;
            userFrame       = null;
            skeletonData    = null;
            handTrackerData = null;

            depthSensor       = null;
            colorSensor       = null;
            userTracker       = null;
            skeletonTracker   = null;
            gestureRecognizer = null;
            handTracker       = null;

            nuitrack.Nuitrack.Release();
            Debug.Log("CloseUserGen");
            nuitrackInitialized = false;
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
    }
Exemple #7
0
    void Start()
    {
        skeletonParts = new Dictionary <int, GameObject[]>();

        //nuitrack initialization and creation of depth and segmentation generators:
        try
        {
            nuitrack.Nuitrack.Init(debugPath);
            skeletonTracker = nuitrack.SkeletonTracker.Create();
            //event handler registerering:
            skeletonTracker.OnSkeletonUpdateEvent += SkeletonUpdate;

            nuitrack.Nuitrack.Run();
        }
        catch (Exception ex)
        {
            exceptionsLogger.AddEntry(ex.ToString());
        }
    }
    public void CloseUserGen()
    {
        if (depthSensor != null)
        {
            depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
        }
        if (colorSensor != null)
        {
            colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
        }
        if (userTracker != null)
        {
            userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
        }
        if (skeletonTracker != null)
        {
            skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
        }
        if (gestureRecognizer != null)
        {
            gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
        }
        if (handTracker != null)
        {
            handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
        }
        //		Debug.Log ("preRelease");
        nuitrack.Nuitrack.Release();
        //		Debug.Log ("postRelease");

        depthSensor       = null;
        colorSensor       = null;
        userTracker       = null;
        skeletonTracker   = null;
        gestureRecognizer = null;
        handTracker       = null;

        depthFrame      = null;
        colorFrame      = null;
        userFrame       = null;
        skeletonData    = null;
        handTrackerData = null;
    }
Exemple #9
0
    void NuitrackInit()
    {
        //    CloseUserGen(); //just in case
        #if UNITY_IOS
        nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
        #else
        if (Application.isEditor && wifiConnectFromEditor)
        {
            //nuitrack.Nuitrack.Init();
            nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
        }
        else
        {
            nuitrack.Nuitrack.Init();
        }
        #endif
        Debug.Log("Init OK");

        depthSensor = nuitrack.DepthSensor.Create();

        colorSensor = nuitrack.ColorSensor.Create();

        userTracker = nuitrack.UserTracker.Create();

        skeletonTracker = nuitrack.SkeletonTracker.Create();

        gestureRecognizer = nuitrack.GestureRecognizer.Create();

        handTracker = nuitrack.HandTracker.Create();

        nuitrack.Nuitrack.Run();
        Debug.Log("Run OK");

        ChangeModulsState(
            skeletonTrackerModuleOn,
            handsTrackerModuleOn,
            depthModuleOn,
            colorModuleOn,
            gesturesRecognizerModuleOn,
            userTrackerModuleOn
            );
    }
Exemple #10
0
    public void ReleaseNuitrack()
    {
        if (issuesProcessor != null)
        {
            Destroy(issuesProcessor);
        }
        if (depthUserVisualization != null)
        {
            Destroy(depthUserVisualization);
        }
        if (skeletonsVisualization != null)
        {
            Destroy(skeletonsVisualization);
        }

        depthSensor     = null;
        userTracker     = null;
        skeletonTracker = null;

        nuitrack.Nuitrack.Release();
    }
    public void ChangeModules(bool depthOn, bool colorOn, bool userOn, bool skeletonOn, bool handsOn, bool gesturesOn)
    {
        try
        {
            //      if (depthSensor != null) depthSensor.OnUpdateEvent -= DepthUpdate;
            //      if (userTracker != null) userTracker.OnUpdateEvent -= UserUpdate;
            //      if (skeletonTracker != null) skeletonTracker.OnSkeletonUpdateEvent -= SkeletonsUpdate;
            //      if (handTracker != null) handTracker.OnUpdateEvent -= HandTrackerUpdate;
            //      if (gestureRecognizer != null) gestureRecognizer.OnNewGesturesEvent -= GesturesUpdate;

            //*
            if (!nuitrackInitialized)
            {
            #if UNITY_IOS
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
            #else
                nuitrack.Nuitrack.Init();
            #endif
                Debug.Log("init ok");
                depthSensorInit       = nuitrack.DepthSensor.Create();
                colorSensorInit       = nuitrack.ColorSensor.Create();
                userTrackerInit       = nuitrack.UserTracker.Create();
                skeletonTrackerInit   = nuitrack.SkeletonTracker.Create();
                handTrackerInit       = nuitrack.HandTracker.Create();
                gestureRecognizerInit = nuitrack.GestureRecognizer.Create();

                nuitrack.Nuitrack.Run();
                Debug.Log("run ok");
                nuitrackInitialized = true;
            }
//			*/

            depthFrame      = null;
            colorFrame      = null;
            userFrame       = null;
            skeletonData    = null;
            handTrackerData = null;
            gesturesData    = null;
            //
            //      depthSensor = null;
            //      userTracker = null;
            //      skeletonTracker = null;
            //      handTracker = null;
            //      gestureRecognizer = null;

            //if (issuesProcessor != null) Destroy(issuesProcessor);

            if (prevDepth != depthOn)
            {
                prevDepth = depthOn;
                if (depthOn)
                {
                    depthSensor = depthSensorInit;
                    depthSensorInit.OnUpdateEvent += DepthUpdate;
                }
                else
                {
                    depthSensorInit.OnUpdateEvent -= DepthUpdate;
                    depthSensor = null;
                }
            }

            if (prevColor != colorOn)
            {
                prevColor = colorOn;
                if (colorOn)
                {
                    colorSensor = colorSensorInit;
                    colorSensorInit.OnUpdateEvent += ColorUpdate;
                }
                else
                {
                    colorSensorInit.OnUpdateEvent -= ColorUpdate;
                    colorSensor = null;
                }
            }

            if (prevUser != userOn)
            {
                prevUser = userOn;
                if (userOn)
                {
                    userTracker = userTrackerInit;
                    userTrackerInit.OnUpdateEvent += UserUpdate;
                }

                else
                {
                    userTrackerInit.OnUpdateEvent -= UserUpdate;
                    userTracker = null;
                }
            }

            if (skeletonOn != prevSkel)
            {
                prevSkel = skeletonOn;
                if (skeletonOn)
                {
                    skeletonTracker = skeletonTrackerInit;
                    skeletonTrackerInit.OnSkeletonUpdateEvent += SkeletonsUpdate;
                }
                else
                {
                    skeletonTrackerInit.OnSkeletonUpdateEvent -= SkeletonsUpdate;
                    skeletonTracker = null;
                }
            }

            if (prevHand != handsOn)
            {
                prevHand = handsOn;
                if (handsOn)
                {
                    handTracker = handTrackerInit;
                    handTrackerInit.OnUpdateEvent += HandTrackerUpdate;
                }
                else
                {
                    handTrackerInit.OnUpdateEvent -= HandTrackerUpdate;
                    handTracker = null;
                }
            }

            if (prevGesture != gesturesOn)
            {
                prevGesture = gesturesOn;
                if (gesturesOn)
                {
                    gestureRecognizer = gestureRecognizerInit;
                    gestureRecognizerInit.OnNewGesturesEvent += GesturesUpdate;
                }
                else
                {
                    gestureRecognizerInit.OnNewGesturesEvent -= GesturesUpdate;
                    gestureRecognizer = null;
                }
            }
            //issuesProcessor = (GameObject)Instantiate(issuesProcessorPrefab);
        }
        catch (Exception ex)
        {
            exceptionsLogger.AddEntry(ex.ToString());
        }
    }
Exemple #12
0
    void NuitrackInit()
    {
        //    CloseUserGen(); //just in case
#if UNITY_IOS
        if (wifiConnect == WifiConnect.VicoVR)
        {
            nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
            nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.1.1");
        }
        else if (wifiConnect == WifiConnect.TVico)
        {
            nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
            nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.43.1");
        }
        else
        {
            nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
        }
#else
        if ((Application.isEditor || Application.platform == RuntimePlatform.WindowsPlayer) && wifiConnect != WifiConnect.none)
        {
            if (wifiConnect == WifiConnect.VicoVR)
            {
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
                nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.1.1");
            }

            if (wifiConnect == WifiConnect.TVico)
            {
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
                nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.43.1");
            }
        }
        else
        {
            nuitrack.Nuitrack.Init();
        }
#endif
        Debug.Log("Init OK");

        depthSensor = nuitrack.DepthSensor.Create();

        colorSensor = nuitrack.ColorSensor.Create();

        userTracker = nuitrack.UserTracker.Create();

        skeletonTracker = nuitrack.SkeletonTracker.Create();

        gestureRecognizer = nuitrack.GestureRecognizer.Create();

        handTracker = nuitrack.HandTracker.Create();

        nuitrack.Nuitrack.Run();
        Debug.Log("Run OK");

        ChangeModulsState(
            skeletonTrackerModuleOn,
            handsTrackerModuleOn,
            depthModuleOn,
            colorModuleOn,
            gesturesRecognizerModuleOn,
            userTrackerModuleOn
            );
    }
    private void InitTrackers(bool depthOn, bool colorOn, bool userOn, bool skeletonOn, bool handsOn, bool gesturesOn)
    {
        if (!nuitrackInitialized)
        {
            nuitrack.Nuitrack.Init();
            Debug.Log("init ok");
            depthSensorInit       = nuitrack.DepthSensor.Create();
            colorSensorInit       = nuitrack.ColorSensor.Create();
            userTrackerInit       = nuitrack.UserTracker.Create();
            skeletonTrackerInit   = nuitrack.SkeletonTracker.Create();
            handTrackerInit       = nuitrack.HandTracker.Create();
            gestureRecognizerInit = nuitrack.GestureRecognizer.Create();

            nuitrack.Nuitrack.Run();
            Debug.Log("run ok");
            nuitrackInitialized = true;
        }

        depthFrame      = null;
        colorFrame      = null;
        userFrame       = null;
        skeletonData    = null;
        handTrackerData = null;
        gesturesData    = null;
        //
        //      depthSensor = null;
        //      userTracker = null;
        //      skeletonTracker = null;
        //      handTracker = null;
        //      gestureRecognizer = null;

        //if (issuesProcessor != null) Destroy(issuesProcessor);

        if (prevDepth != depthOn)
        {
            prevDepth = depthOn;
            if (depthOn)
            {
                depthSensor = depthSensorInit;
                depthSensorInit.OnUpdateEvent += DepthUpdate;
            }
            else
            {
                depthSensorInit.OnUpdateEvent -= DepthUpdate;
                depthSensor = null;
            }
        }

        if (prevColor != colorOn)
        {
            prevColor = colorOn;
            if (colorOn)
            {
                colorSensor = colorSensorInit;
                colorSensorInit.OnUpdateEvent += ColorUpdate;
            }
            else
            {
                colorSensorInit.OnUpdateEvent -= ColorUpdate;
                colorSensor = null;
            }
        }

        if (prevUser != userOn)
        {
            prevUser = userOn;
            if (userOn)
            {
                userTracker = userTrackerInit;
                userTrackerInit.OnUpdateEvent += UserUpdate;
            }

            else
            {
                userTrackerInit.OnUpdateEvent -= UserUpdate;
                userTracker = null;
            }
        }

        if (skeletonOn != prevSkel)
        {
            prevSkel = skeletonOn;
            if (skeletonOn)
            {
                skeletonTracker = skeletonTrackerInit;
                skeletonTrackerInit.OnSkeletonUpdateEvent += SkeletonsUpdate;
            }
            else
            {
                skeletonTrackerInit.OnSkeletonUpdateEvent -= SkeletonsUpdate;
                skeletonTracker = null;
            }
        }

        if (prevHand != handsOn)
        {
            prevHand = handsOn;
            if (handsOn)
            {
                handTracker = handTrackerInit;
                handTrackerInit.OnUpdateEvent += HandTrackerUpdate;
            }
            else
            {
                handTrackerInit.OnUpdateEvent -= HandTrackerUpdate;
                handTracker = null;
            }
        }

        if (prevGesture != gesturesOn)
        {
            prevGesture = gesturesOn;
            if (gesturesOn)
            {
                gestureRecognizer = gestureRecognizerInit;
                gestureRecognizerInit.OnNewGesturesEvent += GesturesUpdate;
            }
            else
            {
                gestureRecognizerInit.OnNewGesturesEvent -= GesturesUpdate;
                gestureRecognizer = null;
            }
        }

        StopThread();
    }
    public void CloseSensor(KinectInterop.SensorData sensorData)
    {
        if (colorWebCam)
        {
            colorWebCam.Stop();
            colorWebCam = null;
        }

        if (coordMapper != null)
        {
            coordMapper.CleanUp();
            coordMapper = null;
        }

        if (colorSensor != null)
        {
            colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            colorSensor = null;
            colorFrame  = null;
        }

        if (depthSensor != null)
        {
            depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            depthSensor = null;
            depthFrame  = null;
        }

        if (userTracker != null)
        {
            userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            userTracker = null;
            userFrame   = null;
        }

        if (skeletonTracker != null)
        {
            skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            skeletonTracker = null;
            skeletonData    = null;
        }

        if (handTracker != null)
        {
            handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            handTracker     = null;
            handTrackerData = null;
        }

        if (gestureRecognizer != null)
        {
            gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            gestureRecognizer = null;
        }

        if (bNuitrackInited)
        {
            bNuitrackInited = false;

            nuitrack.Nuitrack.onIssueUpdateEvent -= OnIssuesUpdate;
            NuitrackTerm();
        }

        Debug.Log("Nuitrack sensor closed");
    }
    public KinectInterop.SensorData OpenDefaultSensor(KinectInterop.FrameSource dwFlags, float sensorAngle, bool bUseMultiSource)
    {
        // init interface
        if (!bNuitrackInited)
        {
            bNuitrackInited = NuitrackInit();
            if (!bNuitrackInited)
            {
                return(null);
            }
        }

        sensorFlags  = dwFlags;
        bMultiSource = bUseMultiSource;

        KinectInterop.SensorData sensorData = new KinectInterop.SensorData();

        if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0)
        {
            for (int i = 0; i < WebCamTexture.devices.Length; i++)
            {
                if (WebCamTexture.devices[i].name.IndexOf("astra", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    Debug.Log("    " + WebCamTexture.devices[i].name + "- AstraPro detected.");
                    colorWebCam = new WebCamTexture(WebCamTexture.devices[i].name, 640, 480, 30);
                    break;
                }
            }

            if (!colorWebCam)
            {
                colorSensor = nuitrack.ColorSensor.Create();
                colorSensor.OnUpdateEvent += HandleOnColorSensorUpdateEvent;
            }
            else
            {
                bWebColorStream = true;
                colorWebCam.Play();

                sensorData.colorImageTexture = colorWebCam;
            }
        }

        if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
        {
            depthSensor = nuitrack.DepthSensor.Create();
//			depthSensor.SetMirror (true);
            depthSensor.OnUpdateEvent += HandleOnDepthSensorUpdateEvent;
        }

        if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
        {
            userTracker = nuitrack.UserTracker.Create();
            userTracker.OnUpdateEvent += HandleOnUserTrackerUpdateEvent;
        }

        if ((dwFlags & KinectInterop.FrameSource.TypeBody) != 0)
        {
            skeletonTracker = nuitrack.SkeletonTracker.Create();
            skeletonTracker.OnSkeletonUpdateEvent += HandleOnSkeletonUpdateEvent;

            handTracker = nuitrack.HandTracker.Create();
            handTracker.OnUpdateEvent += HandleOnHandsUpdateEvent;

            gestureRecognizer = nuitrack.GestureRecognizer.Create();
            gestureRecognizer.OnNewGesturesEvent += OnNewGestures;
        }

//		if((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
//		{
//		}

        nuitrack.Nuitrack.onIssueUpdateEvent += OnIssuesUpdate;
        nuitrack.Nuitrack.Run();

        sensorData.bodyCount  = Constants.SkeletonCount;
        sensorData.jointCount = Constants.JointCount;

        sensorData.depthCameraOffset = 0f;
        sensorData.faceOverlayOffset = 0f;

        if (!bWebColorStream)
        {
//			// wait for color frame
//			if (colorSensor != null)
//			{
//				colorFrame = colorSensor.GetColorFrame();
//				float waitTillTime = Time.realtimeSinceStartup + 2.5f;
//
//				while (colorFrame == null && Time.realtimeSinceStartup <= waitTillTime)
//				{
//					nuitrack.Nuitrack.Update();
//					System.Threading.Thread.Sleep(50);
//					colorFrame = colorSensor.GetColorFrame();
//				}
//			}

            sensorData.colorImageWidth = colorSensor != null?colorSensor.GetOutputMode().XRes : 640;

            sensorData.colorImageHeight = colorSensor != null?colorSensor.GetOutputMode().YRes : 480;

            // flip color image vertically
            sensorData.colorImageScale = new Vector3(1f, -1f, 1f);
        }
        else
        {
            sensorData.colorImageWidth  = colorWebCam.width;
            sensorData.colorImageHeight = colorWebCam.height;

            // flip color image horizontally
            sensorData.colorImageScale = new Vector3(-1f, 1f, 1f);
        }

        Debug.Log("    Color sensor: " + (colorSensor != null ? colorSensor.ToString() : "-") +
                  ", width: " + sensorData.colorImageWidth + ", height: " + sensorData.colorImageHeight);

//		// wait for depth frame
//		if (depthSensor != null)
//		{
//			depthFrame = depthSensor.GetDepthFrame();
//			float waitTillTime = Time.realtimeSinceStartup + 2.5f;
//
//			while (depthFrame == null && Time.realtimeSinceStartup <= waitTillTime)
//			{
//				nuitrack.Nuitrack.Update();
//				System.Threading.Thread.Sleep(50);
//				depthFrame = depthSensor.GetDepthFrame();
//			}
//		}

        sensorData.depthImageWidth = depthSensor != null?depthSensor.GetOutputMode().XRes : 640;

        sensorData.depthImageHeight = depthSensor != null?depthSensor.GetOutputMode().YRes : 480;

        Debug.Log("    Depth sensor: " + (depthSensor != null ? depthSensor.ToString() : "-") +
                  ", width: " + sensorData.depthImageWidth + ", height: " + sensorData.depthImageHeight);

        // color & depth FOV
        float hfovr = colorSensor != null?colorSensor.GetOutputMode().HFOV : 0f;

        float vfovr = 2f * Mathf.Atan(Mathf.Tan(hfovr / 2f) * sensorData.depthImageHeight / sensorData.depthImageWidth);

        sensorData.colorCameraFOV = vfovr * Mathf.Rad2Deg;

        hfovr = depthSensor != null?depthSensor.GetOutputMode().HFOV : 0f;

        vfovr = 2f * Mathf.Atan(Mathf.Tan(hfovr / 2f) * sensorData.depthImageHeight / sensorData.depthImageWidth);
        sensorData.depthCameraFOV = vfovr * Mathf.Rad2Deg;

        if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0)
        {
            int colorImageSize = !colorWebCam ? (sensorData.colorImageWidth * sensorData.colorImageHeight * 3) : 0;
            sensorData.colorImage = new byte[colorImageSize];

            if (!colorWebCam)
            {
                sensorData.colorImageTexture2D = new Texture2D(sensorData.colorImageWidth, sensorData.colorImageHeight, TextureFormat.RGB24, false);
            }
        }

        if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
        {
            int depthImageSize = sensorData.depthImageWidth * sensorData.depthImageHeight;
            sensorData.depthImage = new ushort[depthImageSize];
        }

        if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
        {
            int bodyIndexImageSize = sensorData.depthImageWidth * sensorData.depthImageHeight;
            sensorData.bodyIndexImage = new byte[bodyIndexImageSize];
        }

        if ((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
        {
            int depthImageSize = sensorData.depthImageWidth * sensorData.depthImageHeight;
            sensorData.infraredImage = new ushort[depthImageSize];
        }

        // setup coordinate mapper
        coordMapper = new OrbbecAstraMapper();
        coordMapper.SetupSpaceMapping(sensorData.depthImageWidth, sensorData.depthImageHeight, hfovr, vfovr);
        // d2c-calibration data is valid for Orbbec-Astra only (sensor id & calib.data not provided by Nuitrack)
        coordMapper.SetupCalibrationData(bWebColorStream);

        // set lost-user time tolerance equal to KM
        if (KinectManager.Instance != null)
        {
            waitTimeBeforeRemove = KinectManager.Instance.waitTimeBeforeRemove;
        }

        Debug.Log("Nuitrack sensor opened");

        return(sensorData);
    }
Exemple #16
0
    void NuitrackInit()
    {
        //Debug.Log("Application.runInBackground " + Application.runInBackground);
        //CloseUserGen(); //just in case
#if UNITY_IOS
        if (wifiConnect == WifiConnect.VicoVR)
        {
            nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
            nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.1.1");
        }
        else if (wifiConnect == WifiConnect.TVico)
        {
            nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
            nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.43.1");
        }
        else
        {
            nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
        }
#else
        if ((Application.isEditor || Application.platform == RuntimePlatform.WindowsPlayer) && wifiConnect != WifiConnect.none)
        {
            if (wifiConnect == WifiConnect.VicoVR)
            {
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
                nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.1.1");
            }

            if (wifiConnect == WifiConnect.TVico)
            {
                nuitrack.Nuitrack.Init("", nuitrack.Nuitrack.NuitrackMode.DEBUG);
                nuitrack.Nuitrack.SetConfigValue("Settings.IPAddress", "192.168.43.1");
            }
        }
        else
        {
            nuitrack.Nuitrack.Init();

            //... Change default nuitrack.config settings for better resolution and color mapping

            nuitrack.Nuitrack.SetConfigValue("DepthProvider.Depth2ColorRegistration", "true");
            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.Depth.Preset", "5");
            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.Depth.RawWidth", "848");
            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.Depth.RawHeight", "480");
            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.Depth.ProcessWidth", "848");
            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.Depth.ProcessHeight", "480");
            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.Depth.FPS", "60");

            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.RGB.ProcessWidth", "848");
            nuitrack.Nuitrack.SetConfigValue("Realsense2Module.RGB.ProcessHeight", "480");


            //string alignCheckBefore = nuitrack.Nuitrack.GetConfigValue("DepthProvider.Depth2ColorRegistration");
            //string resolutionCheckBefore = nuitrack.Nuitrack.GetConfigValue("Realsense2Module.Depth.RawWidth");

            //Debug.Log("In NewtrackManager: " + alignCheckBefore);
            //Debug.Log("In NewtrackManager: " + resolutionCheckBefore);

            //...
        }
#endif
        Debug.Log("Init OK");

        depthSensor = nuitrack.DepthSensor.Create();

        colorSensor = nuitrack.ColorSensor.Create();

        userTracker = nuitrack.UserTracker.Create();

        skeletonTracker = nuitrack.SkeletonTracker.Create();

        gestureRecognizer = nuitrack.GestureRecognizer.Create();

        handTracker = nuitrack.HandTracker.Create();

        nuitrack.Nuitrack.Run();
        Debug.Log("Run OK");

        ChangeModulsState(
            skeletonTrackerModuleOn,
            handsTrackerModuleOn,
            depthModuleOn,
            colorModuleOn,
            gesturesRecognizerModuleOn,
            userTrackerModuleOn
            );
    }