コード例 #1
0
    void Update()
    {
        bool haveNewFrame = false;

        if (!nuitrackModules.nuitrackInitialized)
        {
            return;
        }

        if ((nuitrackModules.DepthFrame != null) && active)
        {
            if (depthFrame != null)
            {
                haveNewFrame = (depthFrame != nuitrackModules.DepthFrame);
            }
            depthFrame = nuitrackModules.DepthFrame;
            colorFrame = nuitrackModules.ColorFrame;
            userFrame  = nuitrackModules.UserFrame;
            if (haveNewFrame)
            {
                ProcessFrame(depthFrame, colorFrame, userFrame);
            }
        }
        else
        {
            HideVisualization();
        }
    }
コード例 #2
0
    public static Texture2D ToTexture2D(this nuitrack.ColorFrame frame)
    {
        int datasize = frame.DataSize;

        if (colorDataArray == null || colorDataArray.Length != datasize)
        {
            colorDataArray = new byte[datasize];
        }
        Marshal.Copy(frame.Data, colorDataArray, 0, datasize);

        for (int i = 0; i < datasize; i += 3)
        {
            byte temp = colorDataArray[i];
            colorDataArray[i]     = colorDataArray[i + 2];
            colorDataArray[i + 2] = temp;
        }

        Texture2D rgbTexture = new Texture2D(frame.Cols, frame.Rows, TextureFormat.RGB24, false);

        rgbTexture.LoadRawTextureData(colorDataArray);
        rgbTexture.Apply();

        Resources.UnloadUnusedAssets();

        return(rgbTexture);
    }
コード例 #3
0
        void Update()
        {
            if (!NuitrackManager.Instance.nuitrackInitialized)
            {
                return;
            }

            if ((NuitrackManager.DepthFrame != null) && active)
            {
                nuitrack.DepthFrame depthFrame = NuitrackManager.DepthFrame;
                nuitrack.ColorFrame colorFrame = NuitrackManager.ColorFrame;
                nuitrack.UserFrame  userFrame  = NuitrackManager.UserFrame;

                bool haveNewFrame = (lastFrameTimestamp != depthFrame.Timestamp);
                if (haveNewFrame)
                {
                    ProcessFrame(depthFrame, colorFrame, userFrame);
                    lastFrameTimestamp = depthFrame.Timestamp;
                }
            }
            else
            {
                HideVisualization();
            }
        }
コード例 #4
0
 void HandleOnColorSensorUpdateEvent(nuitrack.ColorFrame frame)
 {
     //Debug.Log("Color Update");
     colorFrame = frame;
     if (onColorUpdate != null)
     {
         onColorUpdate(colorFrame);
     }
 }
コード例 #5
0
 void HandleOnColorSensorUpdateEvent(nuitrack.ColorFrame frame)
 {
     if (colorFrame != null)
     {
         colorFrame.Dispose();
     }
     colorFrame = (nuitrack.ColorFrame)frame.Clone();
     //Debug.Log("Color Update");
     onColorUpdate?.Invoke(colorFrame);
 }
コード例 #6
0
    private void HandleOnColorSensorUpdateEvent(nuitrack.ColorFrame frame)
    {
        colorFrame = frame;

        if (bMultiSource && colorFrame != null)
        {
            bMultiFrameColor = true;
            SyncAllFrames();
        }
    }
コード例 #7
0
        void ProcessFrame(nuitrack.DepthFrame depthFrame, nuitrack.ColorFrame colorFrame, nuitrack.UserFrame userFrame)
        {
            for (int i = 0; i < parts; i++)
            {
                if (!visualizationParts[i].activeSelf)
                {
                    visualizationParts[i].SetActive(true);
                }
            }

            if (userFrame != null)
            {
                if (issuesProcessor.userIssues != null)
                {
                    for (int i = 1; i < userCurrentCols.Length; i++)
                    {
                        if (issuesProcessor.userIssues.ContainsKey(i))
                        {
                            userCurrentCols[i] =
                                (issuesProcessor.userIssues[i].isOccluded ||
                                 issuesProcessor.userIssues[i].onBorderLeft ||
                                 issuesProcessor.userIssues[i].onBorderRight ||
                                 issuesProcessor.userIssues[i].onBorderTop) ?
                                occludedUserCols[i] : userCols[i];
                        }
                    }
                }
            }

            if (colorFrame == null)
            {
                rgbTexture = depthFrame.ToRenderTexture();
            }
            else
            {
                rgbTexture = colorFrame.ToRenderTexture();
            }

            depthTexture        = depthFrame.ToRenderTexture(depthGradient, depthCache);
            segmentationTexture = userFrame.ToRenderTexture(userCurrentCols, textureCache);

            if (!showBackground)
            {
                FrameUtils.TextureUtils.Cut(rgbTexture, segmentationTexture, ref rgbRenderTexture);
                visMat.SetTexture("_RGBTex", rgbRenderTexture);
            }
            else
            {
                visMat.SetTexture("_RGBTex", rgbTexture);
            }

            visMat.SetFloat("_maxSensorDepth", FrameUtils.DepthToTexture.MaxSensorDepth);
            visMat.SetTexture("_DepthTex", depthTexture);
            visMat.SetTexture("_SegmentationTex", segmentationTexture);
        }
コード例 #8
0
    void ProcessFrame(nuitrack.DepthFrame depthFrame, nuitrack.ColorFrame colorFrame, nuitrack.UserFrame userFrame)
    {
        for (int i = 0; i < visualizationParts.Length; i++)
        {
            if (!visualizationParts[i].activeSelf)
            {
                visualizationParts[i].SetActive(true);
            }
        }

        System.DateTime t1 = System.DateTime.Now;
        for (int i = 0, pointIndex = 0, rgbOffset = 0; i < depthFrame.Rows; i++)
        {
            for (int j = 0; j < depthFrame.Cols; j++, ++pointIndex, rgbOffset += 3)
            {
                int userId = 0;
                if (userFrame != null)
                {
                    userId = userFrame[i, j];
                }
                Color rgbCol = defaultColor;
                if (colorFrame != null)
                {
                    rgbCol = new Color32(colorFrame[i, j].Red, colorFrame[i, j].Green, colorFrame[i, j].Blue, 255);
                }
                //new Color32(depthFrame.rgb[rgbOffset + 2], depthFrame.rgb[rgbOffset + 1], depthFrame.rgb[rgbOffset + 0], 255);
                Color segmColor = userCols[userId];

                depthColors[pointIndex].r = depthFrame[i, j] / 16384f;
                rgbColors[pointIndex]     = rgbCol;
                segmColors[pointIndex]    = segmColor;
            }
        }
        System.DateTime t2 = System.DateTime.Now;

        depthTexture.SetPixels(depthColors);
        rgbTexture.SetPixels(rgbColors);
        segmentationTexture.SetPixels(segmColors);

        System.DateTime t3 = System.DateTime.Now;

        depthTexture.Apply();
        rgbTexture.Apply();
        segmentationTexture.Apply();

        System.DateTime t4 = System.DateTime.Now;

        //Debug.Log(
        //  "Loop time : " + (t2 - t1).TotalMilliseconds.ToString() +
        //  "; Set pixels: " + (t3 - t2).TotalMilliseconds.ToString() +
        //  "; Texture.Apply: " + (t4 - t3).TotalMilliseconds.ToString()
        //);
    }
コード例 #9
0
    void ProcessFrame(nuitrack.DepthFrame depthFrame, nuitrack.ColorFrame colorFrame)
    {
        int pointIndex = 0;

        for (int i = 0; i < depthFrame.Rows; i += frameStep)
        {
            for (int j = 0; j < depthFrame.Cols; j += frameStep)
            {
                //take depth from the frame and put it into the depthColors array
                depthColors[pointIndex].r = depthFrame[i, j] / 16384f;

                //take from the rgb frame a color and put it into an array rgbColors
                Color rgbCol = defaultColor;
                if (colorFrame != null)
                {
                    rgbCol = new Color32(colorFrame[i, j].Red, colorFrame[i, j].Green, colorFrame[i, j].Blue, 255);
                }
                rgbColors[pointIndex] = rgbCol;

                points[pointIndex].GetComponent <Renderer>().material.color = rgbCol;

                //change of position of the point (cube) in Z (depth)
                Vector3 newPos = NuitrackManager.DepthSensor.ConvertProjToRealCoords(j, i, depthFrame[i, j]).ToVector3();
                //NuitrackManager.depthSensor.ConvertRealToProjCoords(j - depthFrame.Cols, i, depthFrame[i, j]).ToVector3();

                //Hide the "point" if its depth is 0
                if (depthFrame[i, j] == 0)
                {
                    points[pointIndex].SetActive(false);
                }
                else
                {
                    points[pointIndex].SetActive(true);
                    points[pointIndex].transform.position = newPos;

                    float distancePoints = Vector3.Distance(newPos, NuitrackManager.DepthSensor.ConvertProjToRealCoords(j + 1, i, depthFrame[i, j]).ToVector3()); //Distance between points
                    depthToScale = distancePoints * depthFrame.Cols / hRes;                                                                                       //calculate the size of cubes as a function of depth

                    points[pointIndex].transform.localScale = Vector3.one * meshScaling * depthToScale;
                }

                ++pointIndex;
            }
            Debug.Log(pointIndex);
        }

        Debug.Log("BREAK1");
        depthTexture.SetPixels(depthColors);
        rgbTexture.SetPixels(rgbColors);
        Debug.Log("Break2");
        depthTexture.Apply();
        rgbTexture.Apply();
    }
コード例 #10
0
    void DrawColor(nuitrack.ColorFrame frame)
    {
        for (int i = 0; i < (cols * rows); i++)
        {
            int ptr = i * 3;
            outSegment[ptr]     = frame[i].Red;
            outSegment[ptr + 1] = frame[i].Green;
            outSegment[ptr + 2] = frame[i].Blue;
        }

        colorTexture.LoadRawTextureData(outSegment);
        colorTexture.Apply(false);
    }
コード例 #11
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());
        }
    }
コード例 #12
0
    void DrawColorFrame(nuitrack.ColorFrame frame)
    {
        colorFrame = frame.Data; // RGB24

        for (int i = 0; i < colorFrame.Length; i += 3)
        {
            byte temp = colorFrame[i];
            colorFrame[i]     = colorFrame[i + 2];
            colorFrame[i + 2] = temp;
        }

        frameTexture.LoadRawTextureData(colorFrame);
        frameTexture.Apply();
    }
コード例 #13
0
    void Update()
    {
        if (NuitrackManager.DepthFrame != null)
        {
            nuitrack.DepthFrame depthFrame = NuitrackManager.DepthFrame;
            nuitrack.ColorFrame colorFrame = NuitrackManager.ColorFrame;

            bool haveNewFrame = (lastFrameID != depthFrame.ID);
            if (haveNewFrame)
            {
                ProcessFrame(depthFrame, colorFrame);
                lastFrameID = depthFrame.ID;
            }
        }
    }
コード例 #14
0
    void HandleOnColorSensorUpdateEvent(nuitrack.ColorFrame frame)
    {
        if (ColorFrame != null)
        {
            ColorFrame.Dispose();
        }
        ColorFrame = (nuitrack.ColorFrame)frame.Clone();

        try
        {
            onColorUpdate?.Invoke(ColorFrame);
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }
コード例 #15
0
ファイル: PointCloud.cs プロジェクト: dmilkovic/NKS_v2
    void Update()
    {
        bool haveNewFrame = false;

        if ((NuitrackManager.DepthFrame != null))
        {
            if (depthFrame != null)
            {
                haveNewFrame = (depthFrame != NuitrackManager.DepthFrame);
            }
            depthFrame = NuitrackManager.DepthFrame;
            colorFrame = NuitrackManager.ColorFrame;
            if (haveNewFrame)
            {
                ProcessFrame(depthFrame, colorFrame);
            }
        }
    }
コード例 #16
0
    /// <summary>
    /// Get UnityEngine.Texture2D from nuitrack.ColorFrame
    /// </summary>
    /// <param name="frame">Original nuitrack.ColorFrame</param>
    /// <returns>Unity Texture2D</returns>
    public static Texture2D ToTexture2D(this nuitrack.ColorFrame frame)
    {
        byte[] sourceData = frame.Data;

        for (int i = 0; i < sourceData.Length; i += 3)
        {
            byte temp = sourceData[i];
            sourceData[i]     = sourceData[i + 2];
            sourceData[i + 2] = temp;
        }

        Texture2D rgbTexture = new Texture2D(frame.Cols, frame.Rows, TextureFormat.RGB24, false);

        rgbTexture.LoadRawTextureData(sourceData);
        rgbTexture.Apply();

        return(rgbTexture);
    }
    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;
    }
コード例 #18
0
        void NuitrackManager_onColorUpdate(nuitrack.ColorFrame frame)
        {
            float frameAspectRatio = (float)frame.Cols / frame.Rows;

            nuitrack.OutputMode mode = NuitrackManager.DepthSensor.GetOutputMode();

            //The frame from the sensor fills the screen and the FOV is
            //determined for the axis along which the frame reaches the edges of the screen.
            //If the screen is wider than the frame from the sensor, then the alignment will
            //occur according to the inverse aspect ratio of the frame(otherwise the screen).
            float targetAspectRatio = ViewWidth / ViewHeight > frameAspectRatio ?
                                      (float)frame.Rows / frame.Cols : ViewHeight / ViewWidth;

            //Setting the camera's vFOV equal to the depth sensor's vFOV.
            // Nuitrack does not yet have a representation of vFOV, so we use the hFOV to vFOV conversion.
            float vFOV = 2 * Mathf.Atan(Mathf.Tan(mode.HFOV * 0.5f) * targetAspectRatio);

            Camera.fieldOfView = vFOV * Mathf.Rad2Deg;
        }
コード例 #19
0
    void NuitrackManager_onColorUpdate(nuitrack.ColorFrame frame)
    {
        if (renderTexture == null || renderTexture.width != frame.Cols || renderTexture.height != frame.Rows)
        {
            dstRgbTexture2D = new Texture2D(frame.Cols, frame.Rows, TextureFormat.RGB24, false);
            BGR2RGBShader.SetTexture(kernelIndex, "Texture", dstRgbTexture2D);

            renderTexture = new RenderTexture(dstRgbTexture2D.width, dstRgbTexture2D.height, 0, RenderTextureFormat.ARGB32);
            renderTexture.enableRandomWrite = true;
            renderTexture.Create();

            BGR2RGBShader.SetTexture(kernelIndex, "Result", renderTexture);

            rawImage.texture = renderTexture;
        }

        dstRgbTexture2D.LoadRawTextureData(frame.Data, frame.DataSize);
        dstRgbTexture2D.Apply();

        BGR2RGBShader.Dispatch(kernelIndex, dstRgbTexture2D.width / (int)x, dstRgbTexture2D.height / (int)y, (int)z);
    }
コード例 #20
0
        void ProcessFrame(nuitrack.DepthFrame depthFrame, nuitrack.ColorFrame colorFrame, nuitrack.UserFrame userFrame)
        {
            for (int i = 0; i < visualizationParts.Length; i++)
            {
                if (!visualizationParts[i].activeSelf)
                {
                    visualizationParts[i].SetActive(true);
                }
            }

            if (colorFrame == null)
            {
                rgbTexture = depthFrame.ToRenderTexture();
            }
            else
            {
                rgbTexture = colorFrame.ToRenderTexture();
            }

            if (!showBackground)
            {
                FrameUtils.TextureUtils.Cut(rgbTexture, segmentationTexture, ref rgbRenderTexture);
                meshMat.SetTexture("_RGBTex", rgbRenderTexture);
            }
            else
            {
                meshMat.SetTexture("_RGBTex", rgbTexture);
            }

            depthTexture        = depthFrame.ToRenderTexture(depthGradient, depthCache);
            segmentationTexture = userFrame.ToRenderTexture(userCols, textureCache);

            meshMat.SetTexture("_DepthTex", depthTexture);
            meshMat.SetTexture("_SegmentationTex", segmentationTexture);


            meshMat.SetFloat("_maxSensorDepth", FrameUtils.DepthToTexture.MaxSensorDepth);
        }
コード例 #21
0
 void drawColor(nuitrack.ColorFrame _frame)
 {
     background.texture = _frame.ToTexture2D();
 }
コード例 #22
0
    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");
    }
コード例 #23
0
    void ChangeModulsState(bool skel, bool hand, bool depth, bool color, bool gest, bool user)
    {
//		Debug.Log ("" + skel + hand + depth + gest + user);
        if (skeletonTracker == null)
        {
            return;
        }
        if (prevSkel != skel)
        {
            skeletonData = null;
            prevSkel     = skel;
            if (skel)
            {
                skeletonTracker.OnSkeletonUpdateEvent += HandleOnSkeletonUpdateEvent;
            }
            else
            {
                skeletonTracker.OnSkeletonUpdateEvent -= HandleOnSkeletonUpdateEvent;
            }
        }
        if (prevHand != hand)
        {
            handTrackerData = null;
            prevHand        = hand;
            if (hand)
            {
                handTracker.OnUpdateEvent += HandleOnHandsUpdateEvent;
            }
            else
            {
                handTracker.OnUpdateEvent -= HandleOnHandsUpdateEvent;
            }
        }
        if (prevGest != gest)
        {
            prevGest = gest;
            if (gest)
            {
                gestureRecognizer.OnNewGesturesEvent += OnNewGestures;
            }
            else
            {
                gestureRecognizer.OnNewGesturesEvent -= OnNewGestures;
            }
        }
        if (prevDepth != depth)
        {
            depthFrame = null;
            prevDepth  = depth;
            if (depth)
            {
                depthSensor.OnUpdateEvent += HandleOnDepthSensorUpdateEvent;
            }
            else
            {
                depthSensor.OnUpdateEvent -= HandleOnDepthSensorUpdateEvent;
            }
        }
        if (prevColor != color)
        {
            colorFrame = null;
            prevColor  = color;
            if (color)
            {
                colorSensor.OnUpdateEvent += HandleOnColorSensorUpdateEvent;
            }
            else
            {
                colorSensor.OnUpdateEvent -= HandleOnColorSensorUpdateEvent;
            }
        }
        if (prevUser != user)
        {
            userFrame = null;
            prevUser  = user;
            if (user)
            {
                userTracker.OnUpdateEvent += HandleOnUserTrackerUpdateEvent;
            }
            else
            {
                userTracker.OnUpdateEvent -= HandleOnUserTrackerUpdateEvent;
            }
        }
    }
コード例 #24
0
    void ProcessFrame(nuitrack.DepthFrame depthFrame, nuitrack.ColorFrame colorFrame, nuitrack.UserFrame userFrame)
    {
        for (int i = 0; i < parts; i++)
        {
            if (!visualizationParts[i].activeSelf)
            {
                visualizationParts[i].SetActive(true);
            }
        }

        Color pointColor = Color.white;

        if (userFrame != null)
        {
            if (issuesProcessor.userIssues != null)
            {
                for (int i = 1; i < userCurrentCols.Length; i++)
                {
                    if (issuesProcessor.userIssues.ContainsKey(i))
                    {
                        userCurrentCols[i] =
                            (issuesProcessor.userIssues[i].isOccluded ||
                             issuesProcessor.userIssues[i].onBorderLeft ||
                             issuesProcessor.userIssues[i].onBorderRight ||
                             issuesProcessor.userIssues[i].onBorderTop) ?
                            occludedUserCols[i] : userCols[i];
                    }
                }
            }
        }

        for (int i = 0, pointIndex = 0, rgbOffset = 0; i < depthFrame.Rows; i += frameStep)
        {
            for (int j = 0; j < depthFrame.Cols; j += frameStep, ++pointIndex, rgbOffset += 3)
            {
                depthColors[pointIndex].r = depthFrame[i, j] / 16384f;

                uint userId = 0u;
                if (userFrame != null)
                {
                    userId = userFrame[i * userFrame.Rows / depthFrame.Rows,
                                       j *userFrame.Cols / depthFrame.Cols];
                }

                #region RGB coloring
                //int rgbOffset = 3 * (i * depthFrame.Cols + j);
                Color rgbCol = defaultColor;
                if (colorFrame != null)
                {
                    rgbCol = new Color32(colorFrame[i, j].Red, colorFrame[i, j].Green, colorFrame[i, j].Blue, 255);
                }
                //new Color32(depthFrame.rgb[rgbOffset + 2], depthFrame.rgb[rgbOffset + 1], depthFrame.rgb[rgbOffset + 0], 255);
                pointColor = rgbCol;// * userCurrentCols[userId];
                if (userId == 0)
                {
                    pointColor *= userCols[0];
                }
                Color segmColor = userCurrentCols[userId];
                //Debug.Log(j.ToString() + ", " + i.ToString() + " : " + rgbCol);
                #endregion
                //        pointColor = userCurrentCols[userId]; //user segmentation coloring

                rgbColors[pointIndex]  = pointColor;
                segmColors[pointIndex] = segmColor;
            }
        }
        depthTexture.SetPixels(depthColors);
        rgbTexture.SetPixels(rgbColors);
        segmentationTexture.SetPixels(segmColors);

        depthTexture.Apply();
        rgbTexture.Apply();
        segmentationTexture.Apply();
    }
コード例 #25
0
    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();
    }
コード例 #26
0
    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());
        }
    }
コード例 #27
0
 void ColorUpdate(nuitrack.ColorFrame _colorFrame)
 {
     colorFrame = _colorFrame;
     //Debug.Log(colorFrame.Timestamp.ToString());
 }
コード例 #28
0
 void DrawColor(nuitrack.ColorFrame frame)
 {
     background.texture = frame.ToTexture2D();
 }