Esempio n. 1
0
        static void Main(string[] args)
        {
            dk.KinectWrapProperties kwp;
               dk.KinectWrap kw;

               kwp = new dk.KinectWrapProperties();
               kwp.HasHandTracking = true;
               kwp.HasGestureRecognition = true;
               kwp.HandTrackHandler = HandTrack;
               kwp.GestureHandler = GestureHandle;
               kwp.Gestures = new dk.GestureType[1] { dk.GestureType.Wave };
               kw = new dk.KinectWrap(kwp);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            dk.KinectWrapProperties kwp;
            dk.KinectWrap           kw;

            kwp = new dk.KinectWrapProperties();
            kwp.HasHandTracking       = true;
            kwp.HasGestureRecognition = true;
            kwp.HandTrackHandler      = HandTrack;
            kwp.GestureHandler        = GestureHandle;
            kwp.Gestures = new dk.GestureType[1] {
                dk.GestureType.Wave
            };
            kw = new dk.KinectWrap(kwp);
        }
Esempio n. 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public KinectWrap(KinectWrapProperties properties)
 {
     string xml;
        if (properties == null) {
             throw new Exception("KinectWrapProperties not provided");
        }
        if (properties.HasGestureRecognition && properties.Gestures == null) {
             throw new Exception("KinectWrapProperties Gestures must at least have 1 gesture");
        }
        this._resources = new ResourceManager(typeof(XmlFiles));
        xml = this._resources.GetString("openniconfig");
        this._xmlFileName = Guid.NewGuid().ToString().Replace("{", "").Replace("}", "").Replace("-", "") + ".xml";
        this._xmlFileName = System.Reflection.Assembly.GetExecutingAssembly().Location + this._xmlFileName;
        using (StreamWriter wr = new StreamWriter(this._xmlFileName)) {
             wr.Write(xml);
        }
        this._context = new OpenNI.Context(this._xmlFileName);
        if (properties.HasHandTracking) {
             this._hands = new OpenNI.HandsGenerator(this._context);
             this._hands.HandUpdate += new OpenNI.HandsGenerator.HandUpdateHandler(
                  delegate(OpenNI.ProductionNode node, uint id, ref OpenNI.Point3D position, float fTime) {
                       if (properties.HandTrackHandler != null) {
                            properties.HandTrackHandler.Invoke(new Point3D() { X = position.X, Y = position.Y, Z = position.Z });
                       }
                  });
             if (!properties.HasGestureRecognition) {
                  this._hands.HandCreate += new OpenNI.HandsGenerator.HandCreateHandler(
                       delegate(OpenNI.ProductionNode node, uint id, ref OpenNI.Point3D position, float fTime) {
                            this._hands.StartTracking(ref position);
                       });
             }
        }
        if (properties.HasGestureRecognition) {
             this._gesture = new OpenNI.GestureGenerator(this._context);
             foreach (GestureType g in properties.Gestures) {
                  switch (g) {
                       case GestureType.Wave: {
                                 this._gesture.AddGesture("Wave");
                                 break;
                            }
                       default: {
                                 break;
                            }
                  }
             }
             this._gesture.GestureRecognized += new OpenNI.GestureGenerator.GestureRecognizedHandler(
                  delegate(OpenNI.ProductionNode node, string strGesture, ref OpenNI.Point3D idPosition, ref OpenNI.Point3D endPosition) {
                       if (properties.GestureHandler != null) {
                            GestureType gt;
                            switch (strGesture) {
                                 case "Wave": {
                                           gt = GestureType.Wave;
                                           break;
                                      }
                                 default: {
                                           gt = GestureType.Wave;
                                           break;
                                      }
                            }
                            properties.GestureHandler.Invoke(gt, new Point3D() { X = endPosition.X, Y = endPosition.Y, Z = endPosition.Z });
                       }
                       if (properties.HasHandTracking) {
                            this._hands.StartTracking(ref endPosition);
                       }
                  });
        }
        if (properties.HasHandTracking) {
             this._hands.StartGenerating();
        }
        if (properties.HasGestureRecognition) {
             this._gesture.StartGenerating();
        }
        System.Threading.Thread th = new System.Threading.Thread(delegate() {
             try {
                  while (true) {
                       this._context.WaitAnyUpdateAll();
                  }
             }
             finally {
                  this.Dispose();
             }
        });
        th.Start();
 }
Esempio n. 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        public KinectWrap(KinectWrapProperties properties)
        {
            string xml;

            if (properties == null)
            {
                throw new Exception("KinectWrapProperties not provided");
            }
            if (properties.HasGestureRecognition && properties.Gestures == null)
            {
                throw new Exception("KinectWrapProperties Gestures must at least have 1 gesture");
            }
            this._resources   = new ResourceManager(typeof(XmlFiles));
            xml               = this._resources.GetString("openniconfig");
            this._xmlFileName = Guid.NewGuid().ToString().Replace("{", "").Replace("}", "").Replace("-", "") + ".xml";
            this._xmlFileName = System.Reflection.Assembly.GetExecutingAssembly().Location + this._xmlFileName;
            using (StreamWriter wr = new StreamWriter(this._xmlFileName)) {
                wr.Write(xml);
            }
            this._context = new OpenNI.Context(this._xmlFileName);
            if (properties.HasHandTracking)
            {
                this._hands             = new OpenNI.HandsGenerator(this._context);
                this._hands.HandUpdate += new OpenNI.HandsGenerator.HandUpdateHandler(
                    delegate(OpenNI.ProductionNode node, uint id, ref OpenNI.Point3D position, float fTime) {
                    if (properties.HandTrackHandler != null)
                    {
                        properties.HandTrackHandler.Invoke(new Point3D()
                        {
                            X = position.X, Y = position.Y, Z = position.Z
                        });
                    }
                });
                if (!properties.HasGestureRecognition)
                {
                    this._hands.HandCreate += new OpenNI.HandsGenerator.HandCreateHandler(
                        delegate(OpenNI.ProductionNode node, uint id, ref OpenNI.Point3D position, float fTime) {
                        this._hands.StartTracking(ref position);
                    });
                }
            }
            if (properties.HasGestureRecognition)
            {
                this._gesture = new OpenNI.GestureGenerator(this._context);
                foreach (GestureType g in properties.Gestures)
                {
                    switch (g)
                    {
                    case GestureType.Wave: {
                        this._gesture.AddGesture("Wave");
                        break;
                    }

                    default: {
                        break;
                    }
                    }
                }
                this._gesture.GestureRecognized += new OpenNI.GestureGenerator.GestureRecognizedHandler(
                    delegate(OpenNI.ProductionNode node, string strGesture, ref OpenNI.Point3D idPosition, ref OpenNI.Point3D endPosition) {
                    if (properties.GestureHandler != null)
                    {
                        GestureType gt;
                        switch (strGesture)
                        {
                        case "Wave": {
                            gt = GestureType.Wave;
                            break;
                        }

                        default: {
                            gt = GestureType.Wave;
                            break;
                        }
                        }
                        properties.GestureHandler.Invoke(gt, new Point3D()
                        {
                            X = endPosition.X, Y = endPosition.Y, Z = endPosition.Z
                        });
                    }
                    if (properties.HasHandTracking)
                    {
                        this._hands.StartTracking(ref endPosition);
                    }
                });
            }
            if (properties.HasHandTracking)
            {
                this._hands.StartGenerating();
            }
            if (properties.HasGestureRecognition)
            {
                this._gesture.StartGenerating();
            }
            System.Threading.Thread th = new System.Threading.Thread(delegate() {
                try {
                    while (true)
                    {
                        this._context.WaitAnyUpdateAll();
                    }
                }
                finally {
                    this.Dispose();
                }
            });
            th.Start();
        }