Exemplo n.º 1
0
        // Parse handHeatMaps
        public static void ParseHandHeatMaps(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
        {
            Debug.AssertFormat(ptrArray.Length == 2, "HandHeatMaps array length invalid: " + ptrArray.Length);
            Debug.AssertFormat(sizeArray.Length == 4, "HandHeatMaps size length invalid: " + sizeArray.Length);
            int volume = 1;

            foreach (var i in sizeArray)
            {
                volume *= i;
            }
            if (volume == 0)
            {
                return;
            }

            // Left
            var valArrayL = new float[volume];

            Marshal.Copy(ptrArray[0], valArrayL, 0, volume);
            var handHeatMapsL = new MultiArray <float>(valArrayL, sizeArray);
            // Right
            var valArrayR = new float[volume];

            Marshal.Copy(ptrArray[1], valArrayR, 0, volume);
            var handHeatMapsR = new MultiArray <float>(valArrayR, sizeArray);

            datum.handHeatMaps = new Pair <MultiArray <float> >(handHeatMapsL, handHeatMapsR);
        }
Exemplo n.º 2
0
        // Parse faceRectangles
        public static void ParseFaceRectangles(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
        {
            Debug.AssertFormat(ptrArray.Length == 1, "FaceRect array length is invalid: " + ptrArray.Length);
            Debug.AssertFormat(sizeArray.Length == 2, "FaceRect size length is invalid: " + sizeArray.Length);
            int volume = 1;

            foreach (var i in sizeArray)
            {
                volume *= i;
            }
            if (volume == 0)
            {
                return;
            }

            var valArray = new float[volume];

            Marshal.Copy(ptrArray[0], valArray, 0, volume);

            // Using UnityEngine.Rect
            var list = new List <Rect>();

            for (int i = 0; i < sizeArray[0]; i++)
            {
                list.Add(new Rect(valArray[i * 4 + 0], valArray[i * 4 + 1], valArray[i * 4 + 2], valArray[i * 4 + 3]));
            }

            datum.faceRectangles = list;
        }
Exemplo n.º 3
0
        public static void ParseOutput(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray, OutputType type)
        {
            switch (type)
            {
            case OutputType.None: break;

            case OutputType.DatumsInfo: ParseDatumsInfo(ref datum, ptrArray, sizeArray); break;

            case OutputType.Name: ParseName(ref datum, ptrArray, sizeArray); break;

            case OutputType.PoseKeypoints: ParsePoseKeypoints(ref datum, ptrArray, sizeArray); break;

            case OutputType.PoseIds: ParsePoseIds(ref datum, ptrArray, sizeArray); break;

            case OutputType.PoseScores: ParsePoseScores(ref datum, ptrArray, sizeArray); break;

            case OutputType.FaceRectangles: ParseFaceRectangles(ref datum, ptrArray, sizeArray); break;

            case OutputType.FaceKeypoints: ParseFaceKeypoints(ref datum, ptrArray, sizeArray); break;

            case OutputType.HandRectangles: ParseHandRectangles(ref datum, ptrArray, sizeArray); break;

            case OutputType.HandKeypoints: ParseHandKeypoints(ref datum, ptrArray, sizeArray); break;

            case OutputType.Image: ParseImage(ref datum, ptrArray, sizeArray); break;

            default: Debug.Log("Output type not supported yet: " + type); break;
            }
        }
Exemplo n.º 4
0
 // Get NEXT output frame. Note that frame is possible to be omitted if buffer size overflow.
 public static bool OPGetOutput(out OpenPoseDatum data)
 {
     if (dataBuffer.Count > 0)
     {
         data = dataBuffer.Dequeue();
         return(true);
     }
     else
     {
         data = new OpenPoseDatum();
         return(false);
     }
 }
Exemplo n.º 5
0
 // Parse handRectangles
 public static void ParseHandRectangles(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
 {
     Debug.AssertFormat(sizeArray.Length == 2, "HandKeypoints size length invalid: " + sizeArray.Length);
     Debug.AssertFormat(sizeArray[0] == 2 && sizeArray[1] == 4, "HandKeypoints sizes invalid");
     datum.handRectangles = new List <Pair <Rect> >();
     foreach (var ptr in ptrArray)
     {
         var tempData = new float[8];
         Marshal.Copy(ptr, tempData, 0, 8);
         Rect left  = new Rect(tempData[0], tempData[1], tempData[2], tempData[3]);
         Rect right = new Rect(tempData[4], tempData[5], tempData[6], tempData[7]);
         datum.handRectangles.Add(new Pair <Rect>(left, right));
     }
 }
Exemplo n.º 6
0
 // OP thread
 private static void OPExecuteThread()
 {
     State = OPState.Running;
     try {
         // Start OP with output callback
         OPBind._OPRun();
         // Thread end, clean up
         dataBuffer.Clear();
         currentData = new OpenPoseDatum();
     } finally {
         // Change state
         State = OPState.Ready;
     }
 }
Exemplo n.º 7
0
        // Parse id, subId, subIdMax, frameNumber
        public static void ParseDatumsInfo(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
        {
            Debug.AssertFormat(ptrArray.Length == 4, "DatumsInfo array length invalid: " + ptrArray.Length);
            Debug.AssertFormat(sizeArray.Length == 1, "DatumsInfo size length invalid: " + sizeArray.Length);
            var temp = new long[4];             // use long to marshal

            Marshal.Copy(ptrArray[0], temp, 0, 1);
            Marshal.Copy(ptrArray[1], temp, 1, 1);
            Marshal.Copy(ptrArray[2], temp, 2, 1);
            Marshal.Copy(ptrArray[3], temp, 3, 1);
            datum.id          = (ulong)temp[0];
            datum.subId       = (ulong)temp[1];
            datum.subIdMax    = (ulong)temp[2];
            datum.frameNumber = (ulong)temp[3];
        }
Exemplo n.º 8
0
        // Parse poseIds
        public static void ParsePoseIds(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
        {
            Debug.AssertFormat(ptrArray.Length == 1, "PoseIds array length invalid: " + ptrArray.Length);
            Debug.AssertFormat(sizeArray.Length == 1, "PoseIds size length invalid: " + sizeArray.Length);
            int volume = 1;

            foreach (var i in sizeArray)
            {
                volume *= i;
            }
            if (volume == 0)
            {
                return;
            }

            var valArray = new long[volume];

            Marshal.Copy(ptrArray[0], valArray, 0, volume);
            datum.poseIds = new MultiArray <long>(valArray, sizeArray);
        }
Exemplo n.º 9
0
        // Parse cvInputData
        public static void ParseImage(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
        {
            Debug.AssertFormat(ptrArray.Length == 1, "Image array length invalid: " + ptrArray.Length);
            Debug.AssertFormat(sizeArray.Length == 3, "Image size length invalid: " + sizeArray.Length);
            int volume = 1;

            foreach (var i in sizeArray)
            {
                volume *= i;
            }
            if (volume == 0)
            {
                return;
            }

            var valArray = new byte[volume];

            Marshal.Copy(ptrArray[0], valArray, 0, volume);
            datum.cvInputData = new MultiArray <byte>(valArray, sizeArray);
        }
Exemplo n.º 10
0
        // Parse faceKeypoints
        public static void ParseFaceKeypoints(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
        {
            Debug.AssertFormat(ptrArray.Length == 1, "FaceKeypoints array length invalid: " + ptrArray.Length);
            Debug.AssertFormat(sizeArray.Length == 3, "FaceKeypoints size length invalid: " + ptrArray.Length);
            int volume = 1;

            foreach (var i in sizeArray)
            {
                volume *= i;
            }
            if (volume == 0)
            {
                return;
            }

            var valArray = new float[volume];

            Marshal.Copy(ptrArray[0], valArray, 0, volume);
            datum.faceKeypoints = new MultiArray <float>(valArray, sizeArray);
        }
Exemplo n.º 11
0
 // Parse name
 public static void ParseName(ref OpenPoseDatum datum, IntPtr[] ptrArray, int[] sizeArray)
 {
     Debug.AssertFormat(ptrArray.Length == 1, "Name array length invalid: " + ptrArray.Length);
     Debug.AssertFormat(sizeArray.Length == 1, "Name size length invalid: " + sizeArray.Length);
     datum.name = Marshal.PtrToStringAnsi(ptrArray[0]);
 }