Inheritance: ObjectWrapper
Esempio n. 1
0
        static void Run()
        {
            string SAMPLE_XML_FILE = @"../../../../Data/SamplesConfig.xml";

            Context context = new Context(SAMPLE_XML_FILE);

            DepthGenerator depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (depth == null)
            {
                Console.WriteLine("Sample must have a depth generator!");
                return;
            }

            MapOutputMode mapMode = depth.GetMapOutputMode();

            DepthMetaData depthMD = new DepthMetaData();

            Console.WriteLine("Press any key to stop...");

            while (!Console.KeyAvailable)
            {
                context.WaitOneUpdateAll(depth);

                depth.GetMetaData(depthMD);

                Console.WriteLine("Frame {0} Middle point is: {1}.", depthMD.FrameID, depthMD[(int)mapMode.nXRes/2, (int)mapMode.nYRes/2]);
            }
        }
Esempio n. 2
0
        public StreamView()
        {
            InitializeComponent();

            pictureBoxOverlay.BackColor = Color.Transparent;

            try
            {
                this.context = new Context(@".\Data\openniconfig.xml");
                this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
                if (this.depth == null)
                {
                    throw new Exception(@"Error in Data\openniconfig.xml. No depth node found.");
                }

                this.histogram = new int[this.depth.GetDeviceMaxDepth()];

                MapOutputMode mapMode = this.depth.GetMapOutputMode();

                this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            }
            catch (Exception ex)
            {
                ///
                /// - todo: proper error logging here
                ///

                MessageBox.Show("Error initializing OpenNI.");
                MessageBox.Show(ex.Message);

                this.Close();
            }
        }
Esempio n. 3
0
        private NuiSource()
        {
            context = new Context("openni.xml");

            // Initialise generators
            imageGenerator = this.context.FindExistingNode(NodeType.Image) as ImageGenerator;
            depthGenerator = this.context.FindExistingNode(NodeType.Depth) as DepthGenerator;

            imageMetadata = new ImageMetaData();
            var imageMapMode = imageGenerator.GetMapOutputMode();

            depthMetadata = new DepthMetaData();
            var depthMapMode = depthGenerator.GetMapOutputMode();
            depthHistogram = new int[depthGenerator.GetDeviceMaxDepth()];

            // Initialise bitmaps
            cameraImage = new WriteableBitmap((int)imageMapMode.nXRes, (int)imageMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null);
            depthImage = new WriteableBitmap((int)depthMapMode.nXRes, (int)depthMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null);

            // Initialise background thread
            var cameraThread = new Thread(this.CameraThread) { IsBackground = true };
            cameraThread.Start();

            var userGenerator = new UserGenerator(context);
            userGenerator.NewUser += this.UserGenerator_NewUser;
            userGenerator.LostUser += this.UserGenerator_LostUser;
        }
Esempio n. 4
0
        public static bool IsConnected()
        {
            bool isConnected = false;

            try
            {
                // string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                var dir = GTPath.GetLocalApplicationDataPath();
                DirectoryInfo dirInfo = new DirectoryInfo(new Uri(dir).LocalPath);
                Context ctx = new Context(dirInfo.FullName + "\\" + configFile);
                ProductionNode irNode = ctx.FindExistingNode(NodeType.IR) as IRGenerator;

                if (irNode != null)
                    isConnected = true;

                irNode.Dispose();
                ctx.Dispose();
                
            }
            catch (Exception ex)
            { 
                isConnected = false;
            }

            return isConnected;
        }
Esempio n. 5
0
        void Initialize()
        {
            this.context = new Context("SamplesConfig.xml");
            this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (this.depth == null)
            {
                throw new Exception("Viewer must have a depth node!");
            }

            this.userGenerator = new UserGenerator(this.context);
            this.skeletonCapbility = new SkeletonCapability(this.userGenerator);
            this.poseDetectionCapability = new PoseDetectionCapability(this.userGenerator);
            this.calibPose = this.skeletonCapbility.GetCalibrationPose();

            this.userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser);
            this.userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser);
            this.poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected);
            this.skeletonCapbility.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapbility_CalibrationEnd);

            this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);
            this.userGenerator.StartGenerating();

            App.ViewModel.Status = "Waiting to acquire user";

            this.ShouldRun = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();
        }
Esempio n. 6
0
 private static IntPtr Create(Context context, CodecID codecID, ProductionNode initializer)
 {
     IntPtr nodeHandle;
     UInt32 status = OpenNIImporter.xnCreateCodec(context.InternalObject, codecID.InternalValue, initializer.InternalObject, out nodeHandle);
     WrapperUtils.CheckStatus(status);
     return nodeHandle;
 }
Esempio n. 7
0
        private NuiSource()
        {
            this.context = new Context("openni.xml");

            // Initialise generators
            this.imageGenerator = this.context.FindExistingNode(NodeType.Image) as ImageGenerator;
            this.depthGenerator = this.context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            this.depthGenerator.GetAlternativeViewPointCap().SetViewPoint(this.imageGenerator);

            this.userGenerator = new UserGenerator(this.context);
            this.imageMetadata = new ImageMetaData();
            var imageMapMode = this.imageGenerator.GetMapOutputMode();

            this.depthMetadata = new DepthMetaData();
            var depthMapMode = this.depthGenerator.GetMapOutputMode();
            this.depthHistogram = new int[this.depthGenerator.GetDeviceMaxDepth()];

            // Initialise bitmaps
            this.cameraImage = new WriteableBitmap(
                (int)imageMapMode.nXRes, (int)imageMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null);
            this.depthImage = new WriteableBitmap(
                (int)depthMapMode.nXRes, (int)depthMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null);

            // Initialise user generator
            this.userGenerator.NewUser += this.UserGenerator_NewUser;
            this.userGenerator.LostUser += this.UserGenerator_LostUser;
            this.userGenerator.StartGenerating();
            this.ShowPlayerLabels = true;

            // Initialise background thread
            var cameraThread = new Thread(this.CameraThread) { IsBackground = true };
            cameraThread.Start();
        }
Esempio n. 8
0
 private static IntPtr Create(Context context, string formatName)
 {
     IntPtr nodeHandle;
     UInt32 status = OpenNIImporter.xnCreateRecorder(context.InternalObject, formatName, out nodeHandle);
     WrapperUtils.CheckStatus(status);
     return nodeHandle;
 }
Esempio n. 9
0
        public MainWindow()
        {
            InitializeComponent();

            this.context = new Context(SAMPLE_XML_FILE);
            this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (this.depth == null)
            {
                throw new Exception("Viewer must have a depth node!");
            }

            this.userGenerator = new UserGenerator(this.context);
            this.skeletonCapbility = new SkeletonCapability(this.userGenerator);
            this.poseDetectionCapability = new PoseDetectionCapability(this.userGenerator);
            this.calibPose = this.skeletonCapbility.GetCalibrationPose();

            this.userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser);
            this.userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser);
            this.poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected);
            this.skeletonCapbility.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapbility_CalibrationEnd);

            this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);
            this.joints = new Dictionary<uint,Dictionary<SkeletonJoint,SkeletonJointPosition>>();
            this.userGenerator.StartGenerating();

            this.histogram = new int[this.depth.GetDeviceMaxDepth()];

            MapOutputMode mapMode = this.depth.GetMapOutputMode();

            this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/);
            this.shouldRun = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();
        }
Esempio n. 10
0
 private static IntPtr Create(Context context, string name)
 {
     IntPtr handle;
     UInt32 status = OpenNIImporter.xnCreateMockNode(context.InternalObject, NodeType.Depth, name, out handle);
     WrapperUtils.CheckStatus(status);
     return handle;
 }
Esempio n. 11
0
 private static IntPtr Create(Context context, Query query, EnumerationErrors errors)
 {
     IntPtr handle;
     UInt32 status = OpenNIImporter.xnCreateIRGenerator(context.InternalObject, out handle,
         query == null ? IntPtr.Zero : query.InternalObject,
         errors == null ? IntPtr.Zero : errors.InternalObject);
     WrapperUtils.CheckStatus(status);
     return handle;
 }
Esempio n. 12
0
        public void Start()
        {
            this.context = new Context (SAMPLE_XML_FILE);
            this.depth = context.FindExistingNode (NodeType.Depth) as DepthGenerator;
            if (this.depth == null) {
                throw new Exception ("Viewer must have a depth node!");
            }

            this.depthMD = new DepthMetaData ();
            this.histogram = new int[this.depth.GetDeviceMaxDepth ()];
        }
        void Setup()
        {
            //build the context
            Context = new Context(CONFIG);

            //build the session manager
            SeshManager = new SessionManager(Context,"RaiseHand","RaiseHand");
            SeshManager.SetQuickRefocusTimeout(15000);

            //build the flow router
            Flowy = new FlowRouter();

            //build the Broadcaster
        }
Esempio n. 14
0
 /// <summary>
 /// Destructor
 /// </summary>
 public void Dispose()
 {
     File.Delete(this._xmlFileName);
     if (this._hands != null)
     {
         this._hands.Dispose();
         this._hands = null;
     }
     if (this._gesture != null)
     {
         this._gesture.Dispose();
         this._gesture = null;
     }
     this._context.Dispose();
     this._context = null;
 }
Esempio n. 15
0
        /// <summary>
        /// Setup builds an XN Context, Session Manager and all the detectors. 
        /// It also adds the callbacks for the SessionManager and adds the listeners on the Broadcaster. 
        /// </summary>
        private void Setup()
        {
            //build the context
            Context = new Context(CONFIG);
            //build session manager
            SeshManager = new SessionManager(Context,"RaiseHand","RaiseHand");
            SeshManager.SetQuickRefocusTimeout(15000);

            //build the detectors
            Pushy = new PushDetector();
            Swipy = new SwipeDetector();
            //setup all the callbacks
            SetupCallbacks();
            SeshManager.SessionStart += SessionStarted;
            //add the flow router to the session
            SeshManager.AddListener(Pushy);
            SeshManager.AddListener(Swipy);
        }
Esempio n. 16
0
        public Form1()
        {
            InitializeComponent();

            this.context = new Context(SAMPLE_XML_FILE);
            this.image = context.FindExistingNode(NodeType.Image) as ImageGenerator;

            if (this.image == null)
            {
                throw new Exception("Viewer must have an image node!");
            }

            var mapMode = this.image.GetMapOutputMode();

            this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            this.shouldRun = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();
        }
Esempio n. 17
0
        public MainWindow()
        {
            InitializeComponent();

            this.context = new Context(SAMPLE_XML_FILE);
            this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (this.depth == null)
            {
                throw new Exception("Viewer must have a depth node!");
            }

            this.histogram = new int[this.depth.GetDeviceMaxDepth()];

            MapOutputMode mapMode = this.depth.GetMapOutputMode();

            this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            this.shouldRun = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();
        }
Esempio n. 18
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. 19
0
 /// <summary>
 /// Instanciates a new manager with a configuration file
 /// </summary>
 public OpenNIManager(string filename)
 {
     _context = new Context(filename);
     _motor = new KinectMotor();
 }
Esempio n. 20
0
 public Recorder(Context context, string formatName)
     : this(Create(context, formatName), false)
 {
 }
Esempio n. 21
0
 public Recorder(Context context)
     : this(context, null)
 {
 }
Esempio n. 22
0
 public UserGenerator(Context context)
     : this(context, null, null)
 {
 }
Esempio n. 23
0
        public void Initialize()
        {
            context = new Context(@"..\..\..\data\openniconfig.xml");
            depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            rgb = context.FindExistingNode(NodeType.Image) as ImageGenerator;
            if (depth == null)
                throw new Exception(@"Error in Data\openniconfig.xml. No depth node found.");
            if (rgb == null)
                throw new Exception(@"Error in Data\openniconfig.xml. No rgb node found.");
            MapOutputMode mapMode = depth.GetMapOutputMode();

            // Initialize member variables
            depthHistogram = new int[depth.GetDeviceMaxDepth()];

            // initialize rgb array
            xn.ImageMetaData rgbMD = rgb.GetMetaData();
            rgbData = new byte[rgbMD.XRes * rgbMD.YRes * 3];
            rgbWidth = rgbMD.XRes;
            rgbHeight = rgbMD.YRes;

            xn.DepthMetaData depthMD = depth.GetMetaData();
            depthData = new ushort[depthMD.XRes * depthMD.YRes];
            oldDepthData = new ushort[depthMD.XRes * depthMD.YRes];
            histogramImage = new byte[depthMD.XRes * depthMD.YRes * 3];
            depthWidth = depthMD.XRes;
            depthHeight = depthMD.YRes;
            depthOffsetX = depthMD.XOffset;
            depthOffsetY = depthMD.YOffset;

            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 30);
            dispatcherTimer.Start();
        }
Esempio n. 24
0
 public UserGenerator(Context context, Query query, EnumerationErrors errors)
     : this(Create(context, query, errors), false)
 {
 }
Esempio n. 25
0
 public UserGenerator(Context context, Query query)
     : this(context, query, null)
 {
 }
Esempio n. 26
0
 public DepthGenerator(Context context)
     : this(context, null, null)
 {
 }
Esempio n. 27
0
 public HandsGenerator(Context context)
     : this(context, null, null)
 {
 }
Esempio n. 28
0
 public DepthGenerator(Context context, Query query)
     : this(context, query, null)
 {
 }
Esempio n. 29
0
 public ImageGenerator(Context context)
     : this(context, null, null)
 {
 }
Esempio n. 30
0
 public ImageGenerator(Context context, Query query)
     : this(context, query, null)
 {
 }
        public void initKinect()
        {

            kinectStarted = true;

            FMessage[0] = "Init OpenNI Node";

            this.context = new Context(SAMPLE_XML_FILE);
            this.depth = context.FindExistingNode(xn.NodeType.Depth) as DepthGenerator;

            if (this.depth == null)
            {
                //throw new Exception("Viewer must have a depth node!");
                FLogger.Log(LogType.Debug, "non ci siamo eh");
            }
            else
            {
                FLogger.Log(LogType.Debug, "Ecchime sono un Primesense attivato e running....:P");
            }

            this.userGenerator = new UserGenerator(this.context);
            this.skeletonCapbility = new SkeletonCapability(this.userGenerator);
            this.poseDetectionCapability = new PoseDetectionCapability(this.userGenerator);
            this.calibPose = this.skeletonCapbility.GetCalibrationPose();

            this.userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser);
            this.userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser);
            this.poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected);
            this.skeletonCapbility.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapbility_CalibrationEnd);

            this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);
            this.joints = new Dictionary<uint, Dictionary<SkeletonJoint, SkeletonJointPosition>>();
            this.userGenerator.StartGenerating();

            FMessage[0] = "OpenNI Node registered";

            this.histogram = new int[this.depth.GetDeviceMaxDepth()];

            MapOutputMode mapMode = this.depth.GetMapOutputMode();

            texW = (int)mapMode.nXRes;
            texH = (int)mapMode.nYRes;
            FLogger.Log(LogType.Debug, "Winit: " + texW + "Hinit: " + texH);
            FLogger.Log(LogType.Debug, "kinectStarted = " + kinectStarted);
            this.bitmap = new System.Drawing.Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format32bppArgb);


            this.shouldRun = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();

            FMessage[0] = "OpenNI Thread Started ";

        }
Esempio n. 32
0
 public MockDepthGenerator(Context context, string name)
     : this(Create(context, name), false)
 {
 }