void OnRenderObject()
        {
            int rectX = (int)foregroundImgRect.xMin;
            //int rectY = (int)foregroundImgRect.yMax;
            int rectY = (int)foregroundImgRect.yMin;

            float scaleX = foregroundImgRect.width / depthImageWidth;
            float scaleY = foregroundImgRect.height / depthImageHeight;

            // draw grid
            //DrawGrid();

            // display blob rectangles
            int bi = 0;

            foreach (var b in blobs)
            {
                float x = (depthScale.x >= 0f ? b.minx : depthImageWidth - b.maxx) * scaleX;  // b.minx * scaleX;
                float y = (depthScale.y >= 0f ? b.miny : depthImageHeight - b.maxy) * scaleY; // b.maxy * scaleY;

                Rect rectBlob = new Rect(rectX + x, rectY + y, (b.maxx - b.minx) * scaleX, (b.maxy - b.miny) * scaleY);
                KinectInterop.DrawRect(rectBlob, 2, Color.white);

                Vector3 blobCenter = b.GetBlobCenter();
                x = (depthScale.x >= 0f ? blobCenter.x : depthImageWidth - blobCenter.x) * scaleX;  // blobCenter.x * scaleX;
                y = (depthScale.y >= 0f ? blobCenter.y : depthImageHeight - blobCenter.y) * scaleY; // blobCenter.y* scaleY; //

                Vector3 blobPos = new Vector3(rectX + x, rectY + y, 0);
                KinectInterop.DrawPoint(blobPos, 3, Color.green);

                bi++;
            }
        }
Ejemplo n.º 2
0
    void Update()
    {
        if (!manager || !manager.IsInitialized())
        {
            return;
        }

        // get required player
        long userId = manager.GetUserIdByIndex(playerIndex);

        if (trackedUserId != userId)
        {
            // user lost
            trackedUserId = 0;
        }

        if (trackedUserId == 0 && userId != 0)
        {
            // new user found
            trackedUserId = userId;
        }

        if (trackedUserId != 0 && sensorData.bodyIndexImage != null && sensorData.depthImage != null &&
            sensorData.lastDepthFrameTime != lastDepthFrameTime)
        {
            lastDepthFrameTime = sensorData.lastDepthFrameTime;
            userBodyIndex      = (byte)manager.GetBodyIndexByUserId(trackedUserId);

            TrackDepthAroundJoint((int)KinectInterop.JointType.HandLeft, ref dposHandLeft, ref rectObjectHandLeft, ref depthMinMaxHL, ref fillRatioLeftHand);
            TrackDepthAroundJoint((int)KinectInterop.JointType.HandRight, ref dposHandRight, ref rectObjectHandRight, ref depthMinMaxHR, ref fillRatioRightHand);

//			CalculateObjectSize(dposHandLeft, rectObjectHandLeft, depthMinMaxHL, ref sizeObjectHandLeft);
//			CalculateObjectSize(dposHandRight, rectObjectHandRight, depthMinMaxHR, ref sizeObjectHandRight);

            if (drawHandRectangles)
            {
                Texture2D texDepth = manager.GetUsersLblTex2D();

                bool bRectDrawn = false;
                if (rectObjectHandLeft.width != 0f && rectObjectHandLeft.height != 0f && dposHandLeft != Vector2.zero)
                {
                    KinectInterop.DrawRect(texDepth, rectObjectHandLeft, fillRatioLeftHand > fillThreshold ? Color.green : Color.yellow);
                    bRectDrawn = true;
                }

                if (rectObjectHandRight.width != 0f && rectObjectHandRight.height != 0f && dposHandRight != Vector2.zero)
                {
                    KinectInterop.DrawRect(texDepth, rectObjectHandRight, fillRatioRightHand > fillThreshold ? Color.green : Color.yellow);
                    bRectDrawn = true;
                }

                if (bRectDrawn)
                {
                    texDepth.Apply();
                }
            }

            StringBuilder sbStatusText = new StringBuilder();

            sbStatusText.AppendFormat("LH-Fill: {0:F1}%", fillRatioLeftHand * 100f);
            if (fillRatioLeftHand > fillThreshold)
            {
                sbStatusText.Append(" - Object Found");
            }
            sbStatusText.AppendLine();

            sbStatusText.AppendFormat("RF-Fill: {0:F1}%", fillRatioRightHand * 100f);
            if (fillRatioRightHand > fillThreshold)
            {
                sbStatusText.Append(" - Object Found");
            }
            sbStatusText.AppendLine();

//			if (!float.IsNaN(sizeObjectHandLeft.x) && !float.IsNaN(sizeObjectHandLeft.y) && !float.IsNaN(sizeObjectHandLeft.z))
//			{
//				sbStatusText.AppendFormat("L: ({0:F2}, {1:F2}, {2:F2}), {3:F1}%\n", sizeObjectHandLeft.x, sizeObjectHandLeft.y, sizeObjectHandLeft.z, fillRatioLeftHand * 100f);
//			}
//
//			if (!float.IsNaN(sizeObjectHandRight.x) && !float.IsNaN(sizeObjectHandRight.y) && !float.IsNaN(sizeObjectHandRight.z))
//			{
//				sbStatusText.AppendFormat("R: ({0:F2}, {1:F2}, {2:F2}), {3:F1}%\n", sizeObjectHandRight.x, sizeObjectHandRight.y, sizeObjectHandRight.z, fillRatioRightHand * 100f);
//			}
//
//			if (fillRatioLeftHand > fillThreshold)
//				sbStatusText.Append("Found object in the left hand.\n");
//			if (fillRatioRightHand > fillThreshold)
//				sbStatusText.Append("Found object in the right hand.\n");

            if (statusText)
            {
                statusText.text = sbStatusText.ToString();
            }
        }
    }