Ejemplo n.º 1
0
    // clips color camera image to the dimensions of the user
    private Texture2D ClipUserImage(long userId, Texture2D texImage)
    {
        BodySlicer slicer = BodySlicer.Instance;

        if (slicer && texImage)
        {
            if (slicer.getCalibratedUserId() != userId)
            {
                slicer.OnCalibrationSuccess(userId);
            }

            BodySliceData sliceH = slicer.getBodySliceData(BodySlice.HEIGHT);
            BodySliceData sliceW = slicer.getBodySliceData(BodySlice.WIDTH);

            if (sliceH.isSliceValid && sliceW.isSliceValid)
            {
                int rectX = (int)sliceW.startColorPoint.x;
                int rectW = sliceW.colorPointsLength;

                int rectY = (int)sliceH.startColorPoint.y;
                int rectH = sliceH.colorPointsLength;

                Texture2D texClipped = new Texture2D(rectW, rectH, TextureFormat.ARGB32, false);
                texClipped.SetPixels(texImage.GetPixels(rectX, rectY, rectW, rectH));

                return(texClipped);
            }
        }

        return(texImage);
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (manager && manager.IsInitialized())
        {
            Texture2D depthImage = manager ? manager.GetUsersLblTex() : null;

            if (bodySlicer && bodySlicer.getLastFrameTime() != lastFrameTime)
            {
                lastFrameTime = bodySlicer.getLastFrameTime();
                int sliceCount = bodySlicer.getBodySliceCount();

                if (depthImage)
                {
                    //depthImage = GameObject.Instantiate(depthImage) as Texture2D;

                    for (int i = 0; i < sliceCount; i++)
                    {
                        BodySliceData bodySlice = bodySlicer.getBodySliceData((BodySlice)i);

                        if (depthImage && bodySlice.isSliceValid &&
                            bodySlice.startDepthPoint != Vector2.zero && bodySlice.endDepthPoint != Vector2.zero)
                        {
                            KinectInterop.DrawLine(depthImage, (int)bodySlice.startDepthPoint.x, (int)bodySlice.startDepthPoint.y,
                                                   (int)bodySlice.endDepthPoint.x, (int)bodySlice.endDepthPoint.y, Color.red);
                        }
                    }

                    depthImage.Apply();
                }

                if (statusText)
                {
                    if (bodySlicer.getCalibratedUserId() != 0)
                    {
                        userHeight = !float.IsNaN(userHeight) ? Mathf.Lerp(userHeight, bodySlicer.getUserHeight(), smoothFactor * Time.deltaTime) : bodySlicer.getUserHeight();
                        string sUserInfo = string.Format("User {0} Height: {1:F2} m", bodySlicer.playerIndex, userHeight);

                        userW1 = !float.IsNaN(userW1) ? Mathf.Lerp(userW1, bodySlicer.getSliceWidth(BodySlice.TORSO_1), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_1);
                        userW2 = !float.IsNaN(userW2) ? Mathf.Lerp(userW2, bodySlicer.getSliceWidth(BodySlice.TORSO_2), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_2);
                        userW3 = !float.IsNaN(userW3) ? Mathf.Lerp(userW3, bodySlicer.getSliceWidth(BodySlice.TORSO_3), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_3);
                        userW4 = !float.IsNaN(userW4) ? Mathf.Lerp(userW4, bodySlicer.getSliceWidth(BodySlice.TORSO_4), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_4);

                        sUserInfo += string.Format("\n\nTorso-4: {3:F2} m\nTorso-3: {2:F2} m\nTorso-2: {1:F2} m\nTorso-1: {0:F2} m", userW1, userW2, userW3, userW4);

                        statusText.text = sUserInfo;
                    }
                    else
                    {
                        statusText.text = string.Format("User {0} not found", bodySlicer.playerIndex);;
                    }
                }
            }

            if (backgroundImage)
            {
                backgroundImage.texture = depthImage;
            }
        }
    }