예제 #1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(0);

            return;
        }

        if (adapter == null)
        {
            return;
        }

        if (adapter.SensorType != sensorType)
        {
            adapter.SensorType = sensorType;
        }

        Frame frame = adapter.UpdateFrame();

        if (frame != null)
        {
            if (frame.ImageData != null && frame.UserSpaceData != null)
            {
                greenScreenFilter.UpdateFilter(frame);
                if (greenScreenFilter.Result != null)
                {
                    greenScreenViewTexture = ValidateTexture(greenScreenViewTexture, frame.DepthWidth, frame.DepthHeight, greenScreenViewRawImage);

                    if (greenScreenViewTexture != null)
                    {
                        greenScreenViewTexture.LoadRawTextureData(greenScreenFilter.Result);
                        greenScreenViewTexture.Apply(false);
                    }
                }
            }

            Body body = frame.GetClosestBody();

            if (body != null)
            {
                screemViewStickman.UpdateStickman(adapter, frame, body, greenScreenViewTransform, Visualization.Depth);
            }
        }
    }
예제 #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(0);

            return;
        }

        if (adapter == null)
        {
            return;
        }

        if (adapter.SensorType != sensorType)
        {
            adapter.SensorType = sensorType;
        }

        Frame frame = adapter.UpdateFrame();

        if (frame != null)
        {
            if (frame.ImageData != null && frame.UserSpaceData != null)
            {
                greenScreenFilter.UpdateFilter(frame);
                if (greenScreenFilter.Result != null)
                {
                    greenScreenViewTexture = ValidateTexture(greenScreenViewTexture, frame.DepthWidth, frame.DepthHeight, greenScreenViewRawImage);

                    if (greenScreenViewTexture != null)
                    {
                        greenScreenViewTexture.LoadRawTextureData(greenScreenFilter.Result);
                        greenScreenViewTexture.Apply(false);
                    }
                }
            }

            Body body = frame.GetClosestBody();

            if (body != null)
            {
                screenViewStickman.UpdateStickman(adapter, frame, body, greenScreenViewTransform, Visualization.Depth);

                uiPlaneScale = greenScreenViewTransform.localScale;
                uiPlaneScale.Set(
                    uiPlaneScale.X * ((RectTransform)greenScreenViewTransform).root.localScale.x * ((RectTransform)greenScreenViewTransform).rect.size.x,
                    uiPlaneScale.Y * ((RectTransform)greenScreenViewTransform).root.localScale.y * ((RectTransform)greenScreenViewTransform).rect.size.y, 1);

                float spineLengthWorld;
                float spineLengthScreen;
                MeasureBoneLength(body, JointType.SpineShoulder, JointType.SpineBase, boneLengths[0], 2, 4, out spineLengthWorld, out spineLengthScreen);

                float armLeftLengthWorld;
                float armLeftLengthScreen;
                MeasureBoneLength(body, JointType.ShoulderLeft, JointType.ElbowLeft, boneLengths[1], 5, 6, out armLeftLengthWorld, out armLeftLengthScreen);

                float forearmLeftLengthWorld;
                float forearmLeftLengthScreen;
                MeasureBoneLength(body, JointType.ElbowLeft, JointType.WristLeft, boneLengths[2], 6, 7, out forearmLeftLengthWorld, out forearmLeftLengthScreen);

                float armRightLengthWorld;
                float armRightLengthScreen;
                MeasureBoneLength(body, JointType.ShoulderRight, JointType.ElbowRight, boneLengths[3], 8, 9, out armRightLengthWorld, out armRightLengthScreen);

                float forearmRightLengthWorld;
                float forearmRightLengthScreen;
                MeasureBoneLength(body, JointType.ElbowRight, JointType.WristRight, boneLengths[4], 9, 10, out forearmRightLengthWorld, out forearmRightLengthScreen);

                float thighLeftLengthWorld;
                float thighLeftLengthScreen;
                MeasureBoneLength(body, JointType.HipLeft, JointType.KneeLeft, boneLengths[5], 11, 12, out thighLeftLengthWorld, out thighLeftLengthScreen);

                float calfLeftLengthWorld;
                float calfLeftLengthScreen;
                MeasureBoneLength(body, JointType.KneeLeft, JointType.AnkleLeft, boneLengths[6], 12, 13, out calfLeftLengthWorld, out calfLeftLengthScreen);

                float thighRightLengthWorld;
                float thighRightLengthScreen;
                MeasureBoneLength(body, JointType.HipRight, JointType.KneeRight, boneLengths[7], 14, 15, out thighRightLengthWorld, out thighRightLengthScreen);

                float calfRightLengthWorld;
                float calfRightLengthScreen;
                MeasureBoneLength(body, JointType.KneeRight, JointType.AnkleRight, boneLengths[8], 15, 16, out calfRightLengthWorld, out calfRightLengthScreen);

                MeasureBoneWidth(frame, body, JointType.SpineShoulder, JointType.SpineBase, boneWidthTexts[0], boneLines[0], spineLengthWorld, spineLengthScreen);
                MeasureBoneWidth(frame, body, JointType.ShoulderLeft, JointType.ElbowLeft, boneWidthTexts[1], boneLines[1], armLeftLengthWorld, armLeftLengthScreen);
                MeasureBoneWidth(frame, body, JointType.ElbowLeft, JointType.WristLeft, boneWidthTexts[2], boneLines[2], forearmLeftLengthWorld, forearmLeftLengthScreen);
                MeasureBoneWidth(frame, body, JointType.ShoulderRight, JointType.ElbowRight, boneWidthTexts[3], boneLines[3], armRightLengthWorld, armRightLengthScreen);
                MeasureBoneWidth(frame, body, JointType.ElbowRight, JointType.WristRight, boneWidthTexts[4], boneLines[4], forearmRightLengthWorld, forearmRightLengthScreen);
                MeasureBoneWidth(frame, body, JointType.HipLeft, JointType.KneeLeft, boneWidthTexts[5], boneLines[5], thighLeftLengthWorld, thighLeftLengthScreen);
                MeasureBoneWidth(frame, body, JointType.KneeLeft, JointType.AnkleLeft, boneWidthTexts[6], boneLines[6], calfLeftLengthWorld, calfLeftLengthScreen);
                MeasureBoneWidth(frame, body, JointType.HipRight, JointType.KneeRight, boneWidthTexts[7], boneLines[7], thighRightLengthWorld, thighRightLengthScreen);
                MeasureBoneWidth(frame, body, JointType.KneeRight, JointType.AnkleRight, boneWidthTexts[8], boneLines[8], calfRightLengthWorld, calfRightLengthScreen);
            }
        }
    }