Exemplo n.º 1
0
 /// <summary>
 /// Tomar datos de esqueleto de kinect
 /// </summary>
 protected void updateKinectData()
 {
     for (int i = 0; i < kinectBonesMapping.Count; i++)
     {
         Tuple <JointType, int> mapping = kinectBonesMapping[i];
         Vector3 kBonePos = TgcKinectUtils.toVector3(kinectSkeleton.Joints[mapping.Item1].Position);
         kinectBonePos[mapping.Item2] = kBonePos;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Dibujar esqueleto de debug
        /// Llamar a init() la primera vez.
        /// </summary>
        public void render(Skeleton skeleton)
        {
            //Actualizar datos
            if (skeleton != null)
            {
                //Obtener la posicion de todos los joints
                int idx = -1;
                foreach (Joint joint in skeleton.Joints)
                {
                    idx++;

                    //Obtener posicion
                    jointBoxes[idx].Position = TgcKinectUtils.toVector3(joint.Position);

                    //Setear color segun estado del joint
                    Color jointColor = joint.TrackingState == JointTrackingState.Tracked ? Color.Red : Color.Yellow;
                    if (jointColor != jointBoxes[idx].Color)
                    {
                        jointBoxes[idx].Color = jointColor;
                        jointBoxes[idx].updateValues();
                    }
                }

                //Armar los huesos entre dos joints
                idx = -1;
                foreach (BoneOrientation bone in skeleton.BoneOrientations)
                {
                    idx++;

                    //Indice de origen y de destino
                    int n1 = (int)bone.StartJoint;
                    int n2 = (int)bone.EndJoint;

                    //Actualizar posiciones
                    jointLines[idx].PStart = jointBoxes[n1].Position;
                    jointLines[idx].PEnd   = jointBoxes[n2].Position;
                    jointLines[idx].updateValues();
                }
            }

            //Render
            for (int i = 0; i < jointLines.Length; i++)
            {
                jointLines[i].render();
            }

            for (int i = 0; i < jointBoxes.Length; i++)
            {
                jointBoxes[i].render();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Actualizar informacion de esqueleto
        /// </summary>
        /// <param name="rawSkeleton">Datos crudos trackeados</param>
        /// <param name="data">Datos procesados que se actualizan</param>
        private void buildSkeletonData(Skeleton rawSkeleton, TgcKinectSkeletonData data)
        {
            if (!skeletonTracked)
            {
                if (rawSkeleton.Joints[JointType.HipCenter].TrackingState == JointTrackingState.Tracked)
                {
                    skeletonTracked = true;
                    skeletonCenter  = TgcKinectUtils.toVector3(rawSkeleton.Joints[JointType.HipCenter].Position);
                }
            }



            //Copiar esqueleto de frame actual a frame anterior, sin escalar las posiciones porque ya estaban escaladas de antes
            this.copySkeleton(data.Current.KinectSkeleton, data.Previous.KinectSkeleton, false);

            //Copiar posicion central
            data.Previous.CenterPos = data.Current.CenterPos;

            //Copiar BSphere de frame actual a frame anterior
            data.Previous.RightHandSphere.setCenter(data.Current.RightHandSphere.Center);
            data.Previous.LeftHandSphere.setCenter(data.Current.LeftHandSphere.Center);

            //Copiar pos2D de las dos manos al frame anterior
            data.Previous.RightHandPos = data.Current.RightHandPos;
            data.Previous.LefttHandPos = data.Current.LefttHandPos;

            //Copiar esqueleto recien trackeado al frame actual, adaptando proporciones
            this.copySkeleton(rawSkeleton, data.Current.KinectSkeleton, true);

            //Actualizar posicion central
            data.Current.CenterPos = TgcKinectUtils.toVector3(data.Current.KinectSkeleton.Joints[JointType.HipCenter].Position);

            //Actualizar BSphere de manos de frame actual
            data.Current.RightHandSphere.setCenter(TgcKinectUtils.toVector3(data.Current.KinectSkeleton.Joints[JointType.HandRight].Position));
            data.Current.LeftHandSphere.setCenter(TgcKinectUtils.toVector3(data.Current.KinectSkeleton.Joints[JointType.HandLeft].Position));

            //Actualizar posicion 2D de manos
            this.updateHandsScreenPos(rawSkeleton, data);


            //Agregar nuevo cuadro a historial
            TgcKinectSkeletonData.HandFrame newFrame = new TgcKinectSkeletonData.HandFrame();
            newFrame.Pos3D = new Vector3[2];
            newFrame.Pos2D = new Vector2[2];
            newFrame.Pos3D[TgcKinectSkeletonData.RIGHT_HAND] = data.Current.RightHandSphere.Center;
            newFrame.Pos3D[TgcKinectSkeletonData.LEFT_HAND]  = data.Current.LeftHandSphere.Center;
            newFrame.Pos2D[TgcKinectSkeletonData.RIGHT_HAND] = data.Current.RightHandPos;
            newFrame.Pos2D[TgcKinectSkeletonData.LEFT_HAND]  = data.Current.LefttHandPos;
            data.HandsFrames.AddFirst(newFrame);

            //Ver si hay que eliminar el ultimo cuadro viejo del historial
            if (data.HandsFrames.Count > this.historyFramesCount)
            {
                data.HandsFrames.RemoveLast();
            }


            //Hacer analisis de datos en el historial de frames, para la mano derecha
            this.computeAxisAnalysis(data, TgcKinectSkeletonData.RIGHT_HAND, 0);
            this.computeAxisAnalysis(data, TgcKinectSkeletonData.RIGHT_HAND, 1);
            this.computeAxisAnalysis(data, TgcKinectSkeletonData.RIGHT_HAND, 2);

            //Hacer analisis de datos en el historial de frames, para la mano izquierda
            this.computeAxisAnalysis(data, TgcKinectSkeletonData.LEFT_HAND, 0);
            this.computeAxisAnalysis(data, TgcKinectSkeletonData.LEFT_HAND, 1);
            this.computeAxisAnalysis(data, TgcKinectSkeletonData.LEFT_HAND, 2);
        }