Beispiel #1
0
        private void FindValidSkeletonPoints(ARBody arBody)
        {
            int index = 0;

            int[] isExists;
            int   validPointNum = 0;

            float[] points;
            float[] skeletonPoints;

            // Determine whether the data returned by the algorithm is 3D human
            // skeleton data or 2D human skeleton data, and obtain valid skeleton points.
            if (arBody.CoordinateSystemType == ARCoordinateSystemType.CoordinateSystemType3dCamera)
            {
                isExists       = arBody.GetSkeletonPointIsExist3D();
                points         = new float[isExists.Length * 3];
                skeletonPoints = arBody.GetSkeletonPoint3D();
            }
            else
            {
                isExists       = arBody.GetSkeletonPointIsExist2D();
                points         = new float[isExists.Length * 3];
                skeletonPoints = arBody.GetSkeletonPoint2D();
            }

            // Save the three coordinates of each joint point(each point has three coordinates).
            for (int i = 0; i < isExists.Length; i++)
            {
                if (isExists[i] != 0)
                {
                    points[index++] = skeletonPoints[3 * i];
                    points[index++] = skeletonPoints[3 * i + 1];
                    points[index++] = skeletonPoints[3 * i + 2];
                    validPointNum++;
                }
            }
            mSkeletonPoints = FloatBuffer.Wrap(points);
            mPointsNum      = validPointNum;
        }
        private void FindValidConnectionSkeletonLines(ARBody arBody)
        {
            mPointsLineNum = 0;
            int[]   connections = arBody.GetBodySkeletonConnection();
            float[] linePoints  = new float[LINE_POINT_RATIO * connections.Length];
            float[] coors;
            int[]   isExists;

            if (arBody.CoordinateSystemType == ARCoordinateSystemType.CoordinateSystemType3dCamera)
            {
                coors    = arBody.GetSkeletonPoint3D();
                isExists = arBody.GetSkeletonPointIsExist3D();
            }
            else
            {
                coors    = arBody.GetSkeletonPoint2D();
                isExists = arBody.GetSkeletonPointIsExist2D();
            }

            // Filter out valid skeleton connection lines based on the returned results,
            // which consist of indexes of two ends, for example, [p0,p1;p0,p3;p0,p5;p1,p2].
            // The loop takes out the 3D coordinates of the end points of the valid connection
            // line and saves them in sequence.
            for (int j = 0; j < connections.Length; j += 2)
            {
                if (isExists[connections[j]] != 0 && isExists[connections[j + 1]] != 0)
                {
                    linePoints[mPointsLineNum * 3]     = coors[3 * connections[j]];
                    linePoints[mPointsLineNum * 3 + 1] = coors[3 * connections[j] + 1];
                    linePoints[mPointsLineNum * 3 + 2] = coors[3 * connections[j] + 2];
                    linePoints[mPointsLineNum * 3 + 3] = coors[3 * connections[j + 1]];
                    linePoints[mPointsLineNum * 3 + 4] = coors[3 * connections[j + 1] + 1];
                    linePoints[mPointsLineNum * 3 + 5] = coors[3 * connections[j + 1] + 2];
                    mPointsLineNum += 2;
                }
            }
            mLinePoints = FloatBuffer.Wrap(linePoints);
        }