protected override bool InitTexture(out Texture2D refText, out int xSize, out int ySize)
    {
        if (base.InitTexture(out refText, out xSize, out ySize) == false)
        {
            return(false);
        }
        if (m_settingManager.CurrentContext.Depth == null)
        {
            m_settingManager.m_logger.Log("No depth", UNIEventLogger.Categories.Initialization, UNIEventLogger.Sources.BaseObjects, UNIEventLogger.VerboseLevel.Errors);
            return(false);
        }
        if (m_factor <= 0)
        {
            m_settingManager.m_logger.Log("Illegal factor", UNIEventLogger.Categories.Initialization, UNIEventLogger.Sources.BaseObjects, UNIEventLogger.VerboseLevel.Errors);
            return(false);
        }

        MapOutputMode mom = m_settingManager.CurrentContext.Depth.MapOutputMode;

        xSize   = mom.XRes / m_factor;
        ySize   = mom.YRes / m_factor;
        refText = new Texture2D(xSize, ySize);

        //depthmap data
        rawDepthMap = new short[(int)(mom.XRes * mom.YRes)];
        //histogram stuff
        int maxDepth = m_settingManager.CurrentContext.Depth.DeviceMaxDepth;

        depthHistogramMap = new float[maxDepth];

        UNIOpenNICheckVersion.Instance.ValidatePrerequisite();
        m_depthMetaData = new DepthMetaData();

        return(true);
    }
Exemplo 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();
            }
        }
Exemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();

            this.context = new Context(SAMPLE_XML_FILE);
            this.depth   = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            this.image   = context.FindExistingNode(NodeType.Image) as ImageGenerator;
            //this.scene = context.FindExistingNode(NodeType.Scene) as SceneAnalyzer;

            // align depth with rgb
            this.depth.GetAlternativeViewPointCap().SetViewPoint(image);

            if (this.depth == null ||
                this.image == null)
            {
                throw new Exception("Viewer must have depth and image nodes!");
            }

            this.userGenerator = new UserGenerator(this.context);
            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();
        }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        // init texture
        MapOutputMode mom = OpenNIContext.Instance.Depth.MapOutputMode;

        YRes            = mom.YRes;
        XRes            = mom.XRes;
        depthMapTexture = new Texture2D(mom.XRes / factor, mom.YRes / factor);

        // depthmap data
        rawDepthMap    = new short[(int)(mom.XRes * mom.YRes)];
        depthMapPixels = new Color32[(mom.XRes / factor) * (mom.YRes / factor)];

        // histogram stuff
        int maxDepth = (int)OpenNIContext.Instance.Depth.DeviceMaxDepth;

        depthHistogramMap = new float[maxDepth];

        if (null == target)
        {
            target = GetComponent <Renderer>();
        }

        if (null == target && null != GetComponent <GUITexture>())
        {
            target = GetComponent <GUITexture>().GetComponent <Renderer>();
        }

        if (target)
        {
            target.material.mainTexture = depthMapTexture;
        }
    }
Exemplo n.º 5
0
 public void SetupScanner(string Config)
 {
     lock (this)
     {
         try
         {
             this.context = Context.CreateFromXmlFile(Config, out scriptNode);
             this.GDepth  = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
             this.GImage  = context.FindExistingNode(NodeType.Image) as ImageGenerator;
             if (this.GDepth == null)
             {
                 throw new Exception("Viewer must have a depth node!");
             }
             if (this.GImage == null)
             {
                 throw new Exception("3D Scanner must have a image node!");
             }
             MapOutputMode mapMode = this.GDepth.MapOutputMode;
             configurated = true;
         }
         catch (Exception e)
         {
             LOG.Instance.publishMessage("ERROR : " + e.Message + " " + e.InnerException);
             configurated = false;
         }
     }
 }
    protected override bool InitTexture(out Texture2D refText, out int xSize, out int ySize)
    {
        if (base.InitTexture(out refText, out xSize, out ySize) == false)
        {
            return(false);
        }
        if (m_settingManager.ImageValid == false)
        {
            m_settingManager.m_logger.Log("Invalid image", UNIEventLogger.Categories.Initialization, UNIEventLogger.Sources.Image, UNIEventLogger.VerboseLevel.Errors);
            return(false);
        }
        if (m_factor <= 0)
        {
            m_settingManager.m_logger.Log("Illegal factor", UNIEventLogger.Categories.Initialization, UNIEventLogger.Sources.Image, UNIEventLogger.VerboseLevel.Errors);
            return(false);
        }

        //get the resolution from the image
        MapOutputMode mom = m_settingManager.Image.Image.MapOutputMode;

        //update the resolution by the factor
        xSize = mom.XRes / m_factor;
        ySize = mom.YRes / m_factor;
        //create a new texture.
        refText = new Texture2D(XRes, ySize, TextureFormat.RGB24, false);
        //create a new meta data object.
        UNIOpenNICheckVersion.Instance.ValidatePrerequisite();
        m_imageMetaDate = new ImageMetaData();
        return(true);
    }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        // init stuff
        MapOutputMode mom = OpenNIContext.Instance.Depth.MapOutputMode;

        YRes    = mom.YRes;
        XRes    = mom.XRes;
        factorX = (int)(XRes / DesiredResolution.x);
        factorY = (int)(YRes / DesiredResolution.y);
        // depthmap data
        rawDepthMap = new short[(int)(mom.XRes * mom.YRes)];

        // the actual mesh we'll use

        mesh = new Mesh();

        meshFilter      = (MeshFilter)GetComponent(typeof(MeshFilter));
        meshFilter.mesh = mesh;

        int YScaled = YRes / factorY;
        int XScaled = XRes / factorX;

        verts = new Vector3[XScaled * YScaled];
        uvs   = new Vector2[verts.Length];
        tris  = new int[(XScaled - 1) * (YScaled - 1) * 2 * 3];
        pts   = new Point3D[XScaled * YScaled];
        CalculateTriangleIndices(YScaled, XScaled);
        CalculateUVs(YScaled, XScaled);
    }
Exemplo n.º 9
0
        /// <summary>
        /// This method gets executed when the window loads. In it, we initialize our connection with Kinect
        /// and set up the timer which will update our depth image.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Initialize the context from the configuration file
                this.context = new Context(@"..\..\data\openniconfig.xml");
                // Get the depth generator from the config file.
                this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
                if (this.depth == null)
                {
                    throw new Exception(@"Error in Data\openniconfig.xml. No depth node found.");
                }
                MapOutputMode mapMode = this.depth.GetMapOutputMode();
                this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error initializing OpenNI.");
                MessageBox.Show(ex.Message);
                this.Close();
            }

            // Set the timer to update teh depth image every 10 ms.
            DispatcherTimer dispatcherTimer = new DispatcherTimer();

            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
            dispatcherTimer.Start();
            Console.WriteLine("Finished loading");
        }
Exemplo n.º 10
0
    protected override bool InitTexture(out Texture2D refText, out int xSize, out int ySize)
    {
        if (base.InitTexture(out refText, out xSize, out ySize) == false)
        {
            return(false);
        }
        // make sure we have an image to work with
        if (m_context.ImageValid == false)
        {
            m_context.m_Logger.Log("Invalid image", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.Image, NIEventLogger.VerboseLevel.Errors);
            return(false);
        }
        if (m_factor <= 0)
        {
            m_context.m_Logger.Log("Illegal factor", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.Image, NIEventLogger.VerboseLevel.Errors);
            return(false);
        }
        // get the resolution from the image
        MapOutputMode mom = m_context.Image.Image.MapOutputMode;

        // update the resolution by the factor
        ySize = mom.YRes / m_factor;
        xSize = mom.XRes / m_factor;
        // create the texture
        refText = new Texture2D(xSize, ySize, TextureFormat.RGB24, false);
        // create a new meta data object.
        NIOpenNICheckVersion.Instance.ValidatePrerequisite();
        m_metaData = new ImageMetaData();

        //MiAdd
        renderer.material.mainTexture = refText;

        return(true);
    }
Exemplo n.º 11
0
        public MainWindow()
        {
            InitializeComponent();

            this.context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode);
            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       = this.userGenerator.SkeletonCapability;
            this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
            this.calibPose = this.skeletonCapbility.CalibrationPose;

            this.userGenerator.NewUser  += userGenerator_NewUser;
            this.userGenerator.LostUser += userGenerator_LostUser;
            this.poseDetectionCapability.PoseDetected  += poseDetectionCapability_PoseDetected;
            this.skeletonCapbility.CalibrationComplete += skeletonCapbility_CalibrationComplete;

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


            this.histogram = new int[this.depth.DeviceMaxDepth];

            MapOutputMode mapMode = this.depth.MapOutputMode;

            this.bitmap       = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes /*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/);
            this.shouldRun    = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();
        }
Exemplo n.º 12
0
        static void Run()
        {
            string SAMPLE_XML_FILE = @"../../../../Data/SamplesConfig.xml";

            ScriptNode scriptNode;
            Context    context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode);

            DepthGenerator depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;

            if (depth == null)
            {
                Console.WriteLine("Sample must have a depth generator!");
                return;
            }

            MapOutputMode mapMode = depth.MapOutputMode;

            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.XRes / 2, (int)mapMode.YRes / 2]);
            }
        }
Exemplo n.º 13
0
    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.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();

        MapOutputMode mapMode = this.depth.GetMapOutputMode();


        this.shouldRun = true;
    }
Exemplo n.º 14
0
        public MapOutputMode GetMapOutputMode()
        {
            MapOutputMode mode   = new MapOutputMode();
            UInt32        status = OpenNIImporter.xnGetMapOutputMode(this.InternalObject, ref mode);

            WrapperUtils.CheckStatus(status);
            return(mode);
        }
Exemplo n.º 15
0
    void Start()
    {
/*really unity?
 *
 *  do you do that for real?
 *
 */

        InitializeCharacter();
        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*/);
        usersLblTex = new Texture2D((int)mapMode.nXRes, (int)mapMode.nYRes);
        Debug.Log("usersLblTex = w: " + usersLblTex.width + " h: " + usersLblTex.height);


        usersMapSize   = mapMode.nXRes * mapMode.nYRes;
        usersMapColors = new Color[usersMapSize];
        usersMapRect   = new Rect(Screen.width - usersLblTex.width / 2, Screen.height - usersLblTex.height / 2, usersLblTex.width / 2, usersLblTex.height / 2);
        usersLabelMap  = new short[usersMapSize];
        usersDepthMap  = new short[usersMapSize];

        usersHistogramMap = new float[5000];



        //DepthMetaData depthMD = new DepthMetaData();


        this.shouldRun = true;
        //this.readerThread = new Thread(ReaderThread);
        //	this.readerThread.Start();
    }
Exemplo n.º 16
0
        public MapOutputMode[] GetSupportedMapOutputModes()
        {
            uint count = OpenNIImporter.xnGetSupportedMapOutputModesCount(this.InternalObject);

            MapOutputMode[] supportedModes = new MapOutputMode[count];
            UInt32          status         = OpenNIImporter.xnGetSupportedMapOutputModes(this.InternalObject, supportedModes, ref count);

            WrapperUtils.CheckStatus(status);
            return(supportedModes);
        }
Exemplo n.º 17
0
        public MapOutputMode[] GetSupportedMapOutputModes()
        {
            uint count = SafeNativeMethods.xnGetSupportedMapOutputModesCount(this.InternalObject);

            MapOutputMode[] supportedModes = new MapOutputMode[count];
            int             status         = SafeNativeMethods.xnGetSupportedMapOutputModes(this.InternalObject, supportedModes, ref count);

            WrapperUtils.ThrowOnError(status);
            return(supportedModes);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Initializes the image and depth bitmap sources.
        /// </summary>
        private void InitializeBitmaps()
        {
            MapOutputMode mapMode = DepthGenerator.MapOutputMode;

            int width  = (int)mapMode.XRes;
            int height = (int)mapMode.YRes;

            _imageBitmap = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null);
            _depthBitmap = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null);
        }
Exemplo n.º 19
0
        void Open(int i)
        {
            try
            {
                Close(i);


                Device state   = FState[i];
                var    context = new Context();
                FState[i].Context = context;
                context.AddLicense(FLicense);
                context.GlobalMirror = false;

                NodeInfoList list = context.EnumerateProductionTrees(global::OpenNI.NodeType.Device, null);
                NodeInfo     node = null;
                if (FPinInNodes[i] != "")
                {
                    foreach (NodeInfo nodeitem in list)
                    {
                        if (nodeitem.CreationInfo == FPinInNodes[i])
                        {
                            node = nodeitem;
                            break;
                        }
                    }

                    if (node == null)
                    {
                        throw (new Exception("This device is unavailable. Check upstream ListDevices node"));
                    }

                    context.CreateProductionTree(node);
                }

                state.DepthGenerator = new DepthGenerator(context);
                MapOutputMode depthMode = new MapOutputMode();
                depthMode.FPS  = 30;
                depthMode.XRes = 640;
                depthMode.YRes = 480;

                state.DepthGenerator.MapOutputMode = depthMode;
                state.DepthGenerator.StartGenerating();

                state.Start();

                FPinOutContext[i] = state;
                FPinOutStatus[i]  = "OK";
            }
            catch (Exception e)
            {
                Close(i);
                FPinOutStatus[i] = e.Message;
            }
        }
        }//end UpdateDepth()

        #endregion

        #region Display Depth Map
        /// <summary>
        /// This method gets executed when the window loads. In it, we initialize our connection with Kinect
        /// and set up the timer which will update our depth image.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Initialize the context from the configuration file
                this.context = new Context(@"..\..\data\openniconfig.xml");
                // Get the depth generator from the config file.
                this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
                if (this.depth == null)
                {
                    throw new Exception(@"Error in Data\openniconfig.xml. No depth node found.");
                }
                MapOutputMode mapMode = this.depth.GetMapOutputMode();
                this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                // Initialize Matrixes
                this.depthMatrix           = new Matrix <Double>(480, 640);
                this.depthMatrixROI        = new Matrix <Double>(480, 640);
                this.depthMatrixROIByte    = new Matrix <Byte>(480, 640);
                this.backgroundDepthMatrix = new Matrix <Double>(480, 640);
                // Initialize Images
                this.depthMatrixImage     = new Image <Gray, double>(640, 480);
                this.depthMatrixROIImage  = new Image <Gray, byte>(640, 480);
                this.backgroundDepthImage = new Image <Gray, double>(640, 480);
                this.trackingImage        = new Image <Bgr, byte>(640, 480, new Bgr(0, 0, 0));

                // Initialize Blob Tracking Components
                // Blob Tracking Parameter
                blobParam              = new Emgu.CV.VideoSurveillance.BlobTrackerAutoParam <Gray>();
                blobParam.BlobTracker  = new Emgu.CV.VideoSurveillance.BlobTracker(Emgu.CV.CvEnum.BLOBTRACKER_TYPE.CC);
                blobParam.BlobDetector = new Emgu.CV.VideoSurveillance.BlobDetector(Emgu.CV.CvEnum.BLOB_DETECTOR_TYPE.CC);
                //blobParam.FGDetector = new Emgu.CV.VideoSurveillance.FGDetector<Gray>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
                //blobParam.FGTrainFrames = 10;
                // Blob Tracking initialization
                blobTracker = new Emgu.CV.VideoSurveillance.BlobTrackerAuto <Gray>(blobParam);

                progressBar1.Minimum = 0;
                progressBar1.Maximum = ((Convert.ToInt16(textBoxLifespan.Text) * 4) / _tickDuration);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error initializing OpenNI.");
                MessageBox.Show(ex.Message);
                this.Close();
            }

            // Set the timer to update teh depth image every 10 ms.
            DispatcherTimer dispatcherTimer = new DispatcherTimer();

            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, _tickDuration);
            dispatcherTimer.Start();
            Console.WriteLine("Finished loading");
        }
Exemplo n.º 21
0
        /// <summary>
        /// Instancia um objeto do tipo RGBCamera associado ao Context context.
        /// </summary>
        public RGBCamera(Context context)
        {
            this.generator = new ImageGenerator(context);
            this.generator.MirrorCapability.SetMirror(true);             // dados serão espelhados
            MapOutputMode mapOutputMode = new MapOutputMode();

            mapOutputMode.FPS            = 30;  // frames por segundo
            mapOutputMode.XRes           = 640; // resolução
            mapOutputMode.YRes           = 480;
            this.generator.MapOutputMode = mapOutputMode;
            this.metadata = new ImageMetaData();
        }
Exemplo n.º 22
0
        public MainWindow()
        {
            InitializeComponent();

            console = new Console();
            console.Show();
            console.Top  = 0;
            console.Left = 0;

            Console.Write("TrackingNI by Richard Pianka and Ramsey Abouzahra");

            context        = new Context(CONFIG_FILE);
            imageGenerator = new ImageGenerator(context);
            depthGenerator = new DepthGenerator(context);
            userGenerator  = new UserGenerator(context);

            poseDetectionCapability = userGenerator.PoseDetectionCapability;
            skeletonCapability      = userGenerator.SkeletonCapability;

            MapOutputMode mapMode = depthGenerator.MapOutputMode;

            int width  = (int)mapMode.XRes;
            int height = (int)mapMode.YRes;

            imageBitmap          = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null);
            depthBitmap          = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null);
            depthBitmapCorrected = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null);
            imageData            = new ImageMetaData();
            depthData            = new DepthMetaData();

            skeletonDraw = new SkeletonDraw();

            Histogram = new int[depthGenerator.DeviceMaxDepth];

            reader = new Thread(new ThreadStart(Reader));
            reader.IsBackground = true;
            worker = new BackgroundWorker();
            stop   = false;

            CompositionTarget.Rendering += new EventHandler(Worker);
            Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);

            userGenerator.NewUser  += new EventHandler <NewUserEventArgs>(NewUser);
            userGenerator.LostUser += new EventHandler <UserLostEventArgs>(LostUser);

            skeletonCapability.CalibrationStart += new EventHandler <CalibrationStartEventArgs>(CalibrationStart);
            skeletonCapability.CalibrationEnd   += new EventHandler <CalibrationEndEventArgs>(CalibrationEnd);
            skeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
            poseDetectionCapability.PoseDetected += new EventHandler <PoseDetectedEventArgs>(PoseDetected);
            poseDetectionCapability.PoseEnded    += new EventHandler <PoseEndedEventArgs>(PoseEnded);
            reader.Start();
            worker.DoWork += new DoWorkEventHandler(WorkerTick);
        }
Exemplo n.º 23
0
        public MainWindow()
        {
            InitializeComponent();
            //full screen

            this.Left           = this.Top = 0;
            this.panelView.Size = new Size(App.Default.AppScreenWidth, App.Default.AppScreenHeight);

            this.Width  = Screen.PrimaryScreen.WorkingArea.Width;
            this.Height = Screen.PrimaryScreen.WorkingArea.Height;

            formState.Maximize(this);
            this.TopMost         = true;
            this.Bounds          = Screen.PrimaryScreen.Bounds;
            this.Location        = Screen.PrimaryScreen.WorkingArea.Location;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState     = FormWindowState.Maximized;
            Taskbar.Hide();

            this.context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode);

            //this.context.
            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       = this.userGenerator.SkeletonCapability;
            this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
            this.calibPose = this.skeletonCapbility.CalibrationPose;

            this.userGenerator.NewUser  += userGenerator_NewUser;
            this.userGenerator.LostUser += userGenerator_LostUser;
            this.poseDetectionCapability.PoseDetected  += poseDetectionCapability_PoseDetected;
            this.skeletonCapbility.CalibrationComplete += skeletonCapbility_CalibrationComplete;

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


            this.histogram = new int[this.depth.DeviceMaxDepth];

            MapOutputMode mapMode = this.depth.MapOutputMode;

            this.bitmap       = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes);
            this.shouldRun    = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();
        }
Exemplo n.º 24
0
        public bool SetConfig(XmlElement xmlconfig)
        {
            // TO-DO: add some configuration parameters if of any use

            this.context = new Context("NiteKinectConfig.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.userGenerator.NewUser  += userGenerator_NewUser;
            this.userGenerator.LostUser += userGenerator_LostUser;
            //
            this.skeletonCapbility = this.userGenerator.SkeletonCapability;
            this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);
            this.skeletonCapbility.CalibrationEnd += skeletonCapbility_CalibrationEnd;
            //
            this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
            this.calibPose = this.skeletonCapbility.CalibrationPose;
            this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected;
            //
            this.handsGenerator              = new HandsGenerator(this.context);
            this.handsGenerator.HandCreate  += handsGenerator_HandCreate;
            this.handsGenerator.HandDestroy += handsGenerator_HandDestroy;
            this.handsGenerator.HandUpdate  += handsGenerator_HandUpdate;
            //
            this.gestureGenerator = new GestureGenerator(this.context);
            this.gestureGenerator.AddGesture("Wave");
            this.gestureGenerator.AddGesture("Click");
            this.gestureGenerator.AddGesture("RaiseHand");
            this.gestureGenerator.GestureRecognized += gestureGenerator_GestureRecognized;
            //
            this.joints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointPosition> >();
            //
            this.userGenerator.StartGenerating();
            this.handsGenerator.StartGenerating();
            this.gestureGenerator.StartGenerating();
            //
            this.histogram = new int[this.depth.DeviceMaxDepth];
            MapOutputMode mapMode = this.depth.MapOutputMode;

            //
            this.bitmap                = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes);
            this.shouldRun             = true;
            this.readerThread          = new Thread(ReaderThread);
            this.readerThread.Priority = ThreadPriority.Lowest;
            this.readerThread.Start();
            //
            return(true);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Instancia um objeto do tipo DepthSensor associado ao Context context.
        /// </summary>
        public DepthSensor(Context context)
        {
            this.generator = new DepthGenerator(context);
            this.generator.MirrorCapability.SetMirror(true);             // dados serão espelhados
            MapOutputMode mapOutputMode = new MapOutputMode();

            mapOutputMode.FPS            = 30;  // frames por segundo
            mapOutputMode.XRes           = 640; // resolução
            mapOutputMode.YRes           = 480;
            this.generator.MapOutputMode = mapOutputMode;
            this.metadata  = new DepthMetaData();
            this.histogram = new int[this.Generator.DeviceMaxDepth];
        }
Exemplo n.º 26
0
            private string InitialiseImage()
            {
                string messages = "";

                MapOutputMode imageMode = new MapOutputMode();

                imageMode.XRes = FSize.Width;
                imageMode.YRes = FSize.Height;
                imageMode.FPS  = 30;

                if (Mode == ImageNodeMode.RGB)
                {
                    if (FIRGenerator != null)
                    {
                        FIRGenerator.StopGenerating();
                        FIRGenerator.Dispose();
                    }
                    FRGBGenerator = new ImageGenerator(FState.Context);

                    FRGBGenerator.MapOutputMode = imageMode;
                    Image.Image.Initialise(FSize, TColorFormat.RGB8);

                    if (FState.DepthGenerator.AlternativeViewpointCapability.IsViewpointSupported(FRGBGenerator))
                    {
                        FState.DepthGenerator.AlternativeViewpointCapability.SetViewpoint(FRGBGenerator);
                    }
                    else
                    {
                        messages += "AlternativeViewportCapability not supported\n";
                    }
                    FRGBGenerator.StartGenerating();
                }
                else
                {
                    if (FRGBGenerator != null)
                    {
                        FRGBGenerator.StopGenerating();
                        FRGBGenerator.Dispose();
                    }
                    FIRGenerator = new IRGenerator(FState.Context);
                    FIRGenerator.MapOutputMode = imageMode;
                    FIRGenerator.StartGenerating();

                    Image.Image.Initialise(FSize, TColorFormat.L16);
                }

                return(messages);
            }
        public KinectManager(InputProvider inputProvider)
        {
            this.inputProvider = inputProvider;

            //get configuration
            String OpenNiconfigPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + CONFIG_XML_FILE;

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

            this.maxDepth = this.depth.DeviceMaxDepth;

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

            this.userGenerator.NewUser  += userGenerator_NewUser;
            this.userGenerator.LostUser += userGenerator_LostUser;
            this.poseDetectionCapability.PoseDetected  += poseDetectionCapability_PoseDetected;
            this.skeletonCapbility.CalibrationComplete += skeletonCapbility_CalibrationComplete;

            this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.Upper);
            this.users = new Dictionary <int, User>();
            this.userGenerator.StartGenerating();

            this.mapMode = this.depth.MapOutputMode;

            //load settings
            updateSettings();

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

            this.settingsUpdateThread = new Thread(runUpdateSettings);
            this.settingsUpdateThread.Start();

            Console.WriteLine("Device initialized");
        }
Exemplo n.º 28
0
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
            ScriptNode scriptNode;

            context = Context.CreateFromXmlFile(CONFIG_XML_PATH, out scriptNode);

            // イメージジェネレータの作成
            image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
            if (image == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // デプスジェネレータの作成
            depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (depth == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // デプスの座標をイメージに合わせる
            depth.AlternativeViewpointCapability.SetViewpoint(image);

            // ユーザージェネレータの作成
            user = context.FindExistingNode(NodeType.User) as UserGenerator;
            if (depth == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // ユーザー検出機能をサポートしているか確認
            if (!user.IsCapabilitySupported("User::Skeleton"))
            {
                throw new Exception("ユーザー検出をサポートしていません");
            }

            // 背景イメージを作成
            MapOutputMode mapMode = image.MapOutputMode;

            background = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes,
                                    System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        }
        /// <summary>
        /// Creates a new control instance with a live device as data
        /// source. The current image data can be obtained by the
        /// <see cref="Image"/>-property. The
        /// <see cref="NewImageDataAvailable"/> event informs about when the
        /// data is updated, the <see cref="ErrorOccured"/>-event about
        /// errors.
        /// Start the generation-process by calling
        /// <see cref="StartGenerating"/> and stop it by calling
        /// <see cref="StopGenerating"/>.
        /// </summary>
        /// <exception cref="System.Exception">Thrown if the device could not
        /// be initialized properly.</exception>
        public OpenNILiveStreamController()
        {
            // Create a new context and the data-generating nodes.
            context = new Context();
            context.GlobalMirror = false;

            // Image
            imageGenerator = new ImageGenerator(context);
            MapOutputMode mapMode = new MapOutputMode();

            mapMode.FPS  = 30;
            mapMode.XRes = VIDEO_WIDTH;
            mapMode.YRes = VIDEO_HEIGHT;
            imageGenerator.MapOutputMode = mapMode;
            imageGenerator.PixelFormat   = OpenNI.PixelFormat.RGB24;

            // Depth
            depthGenerator = new DepthGenerator(context);
            depthGenerator.AlternativeViewpointCapability.SetViewpoint(imageGenerator);
            histogram = new int[depthGenerator.DeviceMaxDepth];
            if (depthGenerator == null || imageGenerator == null)
            {
                throw new Exception("Could not initialize kinect device.");
            }

            // User generator
            userGenerator           = new UserGenerator(context);
            skeletonCapability      = userGenerator.SkeletonCapability;
            poseDetectionCapability = userGenerator.PoseDetectionCapability;
            calibPose = skeletonCapability.CalibrationPose;

            userGenerator.NewUser  += userGenerator_NewUser;
            userGenerator.LostUser += userGenerator_LostUser;
            poseDetectionCapability.PoseDetected +=
                poseDetectionCapability_PoseDetected;
            skeletonCapability.CalibrationEnd +=
                skeletonCapability_CalibrationEnd;
            skeletonCapability.SetSkeletonProfile(SkeletonProfile.All);

            // Error handling
            context.ErrorStateChanged += context_ErrorStateChanged;
        }
Exemplo n.º 30
0
        //---------------------------------------------------------------------
        // Kinect provider as background-worker
        //---------------------------------------------------------------------
        public KinectProvider()
        {
            try
            {
                this.context = new Context(SAMPLE_XML_FILE);
            }
            catch (Exception exp)
            {
                MessageBox.Show("Exception: " + exp.Message, "earthmine Kinect",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            this.image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
            //this.scene = context.FindExistingNode(NodeType.Scene) as SceneAnalyzer;

            // align depth with rgb
            this.depth.GetAlternativeViewPointCap().SetViewPoint(image);

            if (this.depth == null ||
                this.image == null)
            {
                throw new Exception("Viewer must have depth and image nodes!");
            }

            this.userGenerator = new UserGenerator(this.context);
            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.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            //this.KinectBitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            this.KinectBitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            //this.ShouldRun = true;
            //this.readerThread = new Thread(ReaderThread);
            //this.readerThread.Start();
        }