Пример #1
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();
        }
Пример #2
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();
        }
Пример #3
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();
        }
Пример #4
0
    void OnPostRender()
    {
        if (!mat) {
            mat = new Material(Shader.Find("VertexLit"));
        }
        mat.SetPass (0);

        if (depthGenerator != null) {
            IntPtr depthP = depthGenerator.GetDepthMapPtr ();
            int focalLength = (int)depthGenerator.GetIntProperty ("ZPD");
            double pixelSize = depthGenerator.GetRealProperty ("ZPPS");
            Matrix4x4 m = camera.worldToCameraMatrix;

            bool result;

            // Draw the point cloud
            result = setMatrix (m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9],
            m[10], m[11], m[12], m[13], m[14], m[15]);
            setBias (openNI.bias.x, openNI.bias.y, openNI.bias.z);
            setScale (openNI.scale.x, openNI.scale.y, openNI.scale.z);
            setRotation (openNI.rotation.x, openNI.rotation.y, openNI.rotation.z);
            result = drawPointCloud (focalLength, pixelSize, 640, 480, depthP);
            Debug.Log ("DrawPointCloud returned: " + result);
        } else {
            // Try again
            openNI = GameObject.FindGameObjectWithTag ("OpenNI").GetComponent (typeof(OpenNI)) as OpenNI;
            depthGenerator = openNI.depth;
        }
    }
Пример #5
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();
            }
        }
Пример #6
0
    void Start()
    {
        Debug.Log ("Start(): Initializing nodes.");

        this.context = new Context (SAMPLE_XML_FILE);
        this.depth = context.FindExistingNode (NodeType.Depth) as DepthGenerator;
        if (this.depth == null) {
            Debug.LogError ("Viewer must have a depth node!");
        }
        this.hands = context.FindExistingNode (NodeType.Hands) as HandsGenerator;
        if (this.hands == null) {
            Debug.LogError ("Viewer must have a hands node!");
        }
        this.gestures = context.FindExistingNode (NodeType.Gesture) as GestureGenerator;
        if (this.gestures == null) {
            Debug.LogError ("Viewer must have a gestures node!");
        }

        this.hands.HandCreate += new HandsGenerator.HandCreateHandler (hands_HandCreate);
        this.hands.HandUpdate += new HandsGenerator.HandUpdateHandler (hands_HandUpdate);
        this.hands.HandDestroy += new HandsGenerator.HandDestroyHandler (hands_HandDestroy);

        this.gestures.AddGesture ("Wave");
        this.gestures.AddGesture ("RaiseHand");
        this.gestures.GestureRecognized += new GestureGenerator.GestureRecognizedHandler (gestures_GestureRecognized);
        this.gestures.StartGenerating ();
    }
Пример #7
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;
        }
Пример #8
0
 private static IntPtr CreateBasedOn(DepthGenerator basedOn, string name)
 {
     IntPtr handle;
     UInt32 status = OpenNIImporter.xnCreateMockNodeBasedOn(basedOn.GetContext().InternalObject,
         basedOn.InternalObject, name, out handle);
     WrapperUtils.CheckStatus(status);
     return handle;
 }
Пример #9
0
        private static IntPtr CreateBasedOn(DepthGenerator basedOn, string name)
        {
            IntPtr handle;
            UInt32 status = OpenNIImporter.xnCreateMockNodeBasedOn(basedOn.GetContext().InternalObject,
                                                                   basedOn.InternalObject, name, out handle);

            WrapperUtils.CheckStatus(status);
            return(handle);
        }
Пример #10
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 ()];
        }
Пример #11
0
    void OnPostRender()
    {
        if (depthGenerator != null) {
            IntPtr depthP = depthGenerator.GetDepthMapPtr ();
            int focalLength = (int)depthGenerator.GetIntProperty ("ZPD");
            double pixelSize = depthGenerator.GetRealProperty ("ZPPS");
            Matrix4x4 m = camera.worldToCameraMatrix;

            bool result;

            // Set up colliders
            result = myLib.SetNumColliders (boxTriggers.Length);
            for (int i = 0; i < boxTriggers.Length; i++) {
                Transform boxTrigger = boxTriggers[i];
                float minX = boxTrigger.localScale.x * -0.5f + boxTrigger.position.x;
                float maxX = boxTrigger.localScale.x * 0.5f + boxTrigger.position.x;
                float minY = boxTrigger.localScale.y * -0.5f + boxTrigger.position.y;
                float maxY = boxTrigger.localScale.y * 0.5f + boxTrigger.position.y;
                float minZ = boxTrigger.localScale.z * -0.5f + boxTrigger.position.z;
                float maxZ = boxTrigger.localScale.z * 0.5f + boxTrigger.position.z;
                result = myLib.SetCollider (i, minX, maxX, minY, maxY, minZ, maxZ);
            }

            // Draw the point cloud
            result = myLib.SetMatrix (m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9],
            m[10], m[11], m[12], m[13], m[14], m[15]);
            result = myLib.DrawPointCloud (focalLength, pixelSize, 640, 480, depthP);
            Debug.Log ("DrawPointCloud returned: " + result);

            // Show any collisions
            for (int i = 0; i < boxTriggers.Length; i++) {
                Transform boxTrigger = boxTriggers[i];
                AudioSource audio = audioSources[i];
                TriggerCell triggerCell = triggerCells[i];
                result = myLib.IsColliderHit (i);
                triggerCell.Hit (result);
                if (result) {
                    boxTrigger.renderer.material = onMaterial;
                    if (!audio.isPlaying) {
                        audio.Play();
                    }
                } else {
                    boxTrigger.renderer.material = offMaterial;
                }
            }
        } else {
            // Try again
            OpenNI2 openNI = GameObject.FindGameObjectWithTag ("OpenNI").GetComponent (typeof(OpenNI2)) as OpenNI2;
            depthGenerator = openNI.depth;
        }
    }
Пример #12
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();
        }
Пример #13
0
    void Start()
    {
        rgbTexture = new Texture2D (640, 480, TextureFormat.RGB24, false);
        rgbMaterial.mainTextureScale = new Vector2 (0.62f, 0.93f); // fixes weird scaling problem
        rgbMaterial.mainTexture = rgbTexture;

        context = new Context (XML_FILE);
        depth = context.FindExistingNode (NodeType.Depth) as DepthGenerator;
        if (depth == null) {
            Debug.LogError ("Viewer must have a depth node!");
            return;
        }

        imageGenerator = context.FindExistingNode (NodeType.Image) as ImageGenerator;
        if (imageGenerator == null) {
            Debug.LogError ("Viewer must have an image generator!");
            return;
        }
        depth.GetAlternativeViewPointCap ().SetViewPoint (imageGenerator);

        imageGenerator.StartGenerating ();
    }
Пример #14
0
        public static Dictionary<SkeletonJoint, SkeletonJointPosition> GetSkeleton(SkeletonCapability skeletonCapability, DepthGenerator depthGenerator, uint user)
        {
            // 骨格情報取得
            var dic = new Dictionary<SkeletonJoint, SkeletonJointPosition>();
            dic.Add(SkeletonJoint.Head, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.Head));
            dic.Add(SkeletonJoint.Neck, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.Neck));
            dic.Add(SkeletonJoint.RightShoulder, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.RightShoulder));
            dic.Add(SkeletonJoint.RightElbow, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.RightElbow));
            dic.Add(SkeletonJoint.RightHand, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.RightHand));
            dic.Add(SkeletonJoint.LeftShoulder, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.LeftShoulder));
            dic.Add(SkeletonJoint.LeftElbow, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.LeftElbow));
            dic.Add(SkeletonJoint.LeftHand, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.LeftHand));
            dic.Add(SkeletonJoint.Torso, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.Torso));
            dic.Add(SkeletonJoint.RightHip, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.RightHip));
            dic.Add(SkeletonJoint.RightKnee, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.RightKnee));
            dic.Add(SkeletonJoint.RightFoot, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.RightFoot));
            dic.Add(SkeletonJoint.LeftHip, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.LeftHip));
            dic.Add(SkeletonJoint.LeftKnee, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.LeftKnee));
            dic.Add(SkeletonJoint.LeftFoot, Joint(skeletonCapability, depthGenerator, user, SkeletonJoint.LeftFoot));

            return dic;
        }
Пример #15
0
 public MockDepthGenerator(DepthGenerator basedOn)
     : this(basedOn, null)
 {
 }
Пример #16
0
 public MockDepthGenerator(DepthGenerator basedOn, string name)
     : this(CreateBasedOn(basedOn, name), false)
 {
 }
        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 ";

        }
Пример #18
0
 void Start()
 {
     openNI = GameObject.FindGameObjectWithTag ("OpenNI").GetComponent (typeof(OpenNI)) as OpenNI;
     depthGenerator = openNI.depth;
 }
Пример #19
0
    void Start()
    {
        context = new Context(XML_FILE);
        depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
        if (depth == null) {
            Debug.LogError("Viewer must have a depth node!");
            return;
        }
        imageGenerator = context.FindExistingNode(NodeType.Image) as ImageGenerator;
        if (imageGenerator == null) {
            Debug.LogError("Viewer must have an image generator!");
            return;
        }

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

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

        skeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
        userGenerator.StartGenerating();

        MapOutputMode mapMode = depth.GetMapOutputMode();

        GameObject o = new GameObject("User");
        mainUser = o.transform;
        mainUser.position = new Vector3(0,0,0);
        mainUser.parent = transform;

        GameObject obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject;
        center = obj.transform;
        //center.parent = mainUser;
        obj.name = "Center";
        createDefaultLineRenderer(center);

        obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject;
        leftArm = obj.transform;
        //leftArm.parent = mainUser;
        obj.name = "L Arm";
        createDefaultLineRenderer(leftArm);

        obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject;
        rightArm = obj.transform;
        //rightArm.parent = mainUser;
        obj.name = "R Arm";
        createDefaultLineRenderer(rightArm);

        obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject;
        leftLeg = obj.transform;
        //leftLeg.parent = mainUser;
        obj.name = "L Leg";
        createDefaultLineRenderer(leftLeg);

        obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject;
        rightLeg = obj.transform;
        //rightLeg.parent = mainUser;
        obj.name = "R Leg";
        createDefaultLineRenderer(rightLeg);
    }
Пример #20
0
 private static SkeletonJointPosition Joint(SkeletonCapability skeletonCapability, DepthGenerator depthGenerator, uint user, SkeletonJoint joint)
 {
     var pos = new SkeletonJointPosition();
     skeletonCapability.GetSkeletonJointPosition(user, joint, ref pos);
     if (pos.position.Z == 0)
     {
         pos.fConfidence = 0;
     }
     else
     {
         pos.position = depthGenerator.ConvertRealWorldToProjective(pos.position);
     }
     return pos;
 }
Пример #21
0
 public MockDepthGenerator(DepthGenerator basedOn) :
     this(basedOn, null)
 {
 }
Пример #22
0
 public MockDepthGenerator(DepthGenerator basedOn, string name) :
     this(CreateBasedOn(basedOn, name), false)
 {
 }
        /// <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");
        }
Пример #24
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;
    }
Пример #25
0
    void Start()
    {
        myLib = new MyLib ();
        openNI = GameObject.FindGameObjectWithTag ("OpenNI").GetComponent (typeof(OpenNI2)) as OpenNI2;
        depthGenerator = openNI.depth;

        // Find all triggers
        GameObject triggers = GameObject.FindGameObjectWithTag("Triggers") as GameObject;
        boxTriggers = new Transform[triggers.transform.GetChildCount()];
        audioSources = new AudioSource[triggers.transform.GetChildCount()];
        triggerCells = new TriggerCell[triggers.transform.GetChildCount()];
        int i = 0;
        foreach (Transform t in triggers.transform) {
            boxTriggers[i] = t;
            audioSources[i] = t.GetComponent (typeof(AudioSource)) as AudioSource;
            triggerCells[i] = t.GetComponent (typeof(TriggerCell)) as TriggerCell;
            i++;
        }
    }
Пример #26
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");
        }
Пример #27
0
        public void Run()
        {
            this.context = new Context (SAMPLE_XML_FILE);

            var ges = context.FindExistingNode (NodeType.Gesture) as GestureGenerator;
            if (ges == null)
                throw new Exception ("Viewer must have a gesture node!");

            //foreach (var ggs in ges.EnumerateAllGestures ()) Console.Error.WriteLine (ggs); return;

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

            user_gen = new UserGenerator (context);
            skel_cap = new SkeletonCapability (user_gen);
            pose_cap = new PoseDetectionCapability (user_gen);
            calib_pose = skel_cap.GetCalibrationPose ();

            user_gen.NewUser += delegate (ProductionNode node, uint id) {
                if (user_count++ > 0)
                    Console.Error.WriteLine ("WARNING: this application does not recognize more than 1 person");
                else
                    pose_cap.StartPoseDetection (calib_pose, id);
            };

            user_gen.LostUser += delegate (ProductionNode node, uint id) {
                user_count--;
                joints.Remove (id);
            };

            pose_cap.PoseDetected += delegate (ProductionNode node, string pose, uint id) {
                pose_cap.StopPoseDetection (id);
                skel_cap.RequestCalibration (id, true);
            };

            skel_cap.CalibrationEnd += delegate (ProductionNode node, uint id, bool success) {
                if (success) {
                    skel_cap.StartTracking (id);
                    joints.Add (id, new Dictionary<SkeletonJoint, SkeletonJointPosition>());
                } else {
                    pose_cap.StartPoseDetection (calib_pose, id);
                }
            };

            skel_cap.SetSkeletonProfile (SkeletonProfile.All);
            joints = new Dictionary<uint,Dictionary<SkeletonJoint,SkeletonJointPosition>> ();
            user_gen.StartGenerating ();

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

            MapOutputMode mapMode = this.depth.GetMapOutputMode ();

            tcp_client = new TcpClient ();
            tcp_client.Connect ("localhost", 9801);
            tcp_writer = new StreamWriter (tcp_client.GetStream ());

            //			bitmap = new Bitmap ((int) mapMode.nXRes, (int) mapMode.nYRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/);
            should_run = true;
            readerThread = new Thread (ReaderThread);
            readerThread.Start ();

            shouldPrintState = false;

            Console.WriteLine ("Type [CR] to stop");
            Console.ReadLine ();
            should_run = false;
        }
Пример #28
0
    void Start()
    {
        texture = new Texture2D (640, 480, TextureFormat.RGB24, false);
        rgbMaterial.mainTextureScale = new Vector2 (0.62f, 0.93f);
        // fixes weird scaling problem
        rgbMaterial.mainTexture = texture;

        context = new Context (XML_FILE);
        depth = context.FindExistingNode (NodeType.Depth) as DepthGenerator;
        if (depth == null) {
            Debug.LogError ("Viewer must have a depth node!");
            return;
        }

        imageGenerator = context.FindExistingNode (NodeType.Image) as ImageGenerator;
        if (imageGenerator == null) {
            Debug.LogError ("Viewer must have an image generator!");
            return;
        }
        depth.GetAlternativeViewPointCap ().SetViewPoint (imageGenerator);

        //handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator;
        //if (handsGenerator == null) {
        //	Debug.LogError("Viewer must have a hands generator!");
        //	return;
        //}
        //handsGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);

        //gestureGenerator = context.FindExistingNode (NodeType.Gesture) as GestureGenerator;
        //if (gestureGenerator == null) {
        //	Debug.LogError ("Viewer must have a gesture node!");
        //}
        //gestureGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);

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

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

        skeletonCapability.SetSkeletonProfile (SkeletonProfile.All);

        userGenerator.StartGenerating ();
        imageGenerator.StartGenerating ();

        //handsGenerator.HandCreate += new HandsGenerator.HandCreateHandler (hands_HandCreate);
        //handsGenerator.HandUpdate += new HandsGenerator.HandUpdateHandler (hands_HandUpdate);
        //handsGenerator.HandDestroy += new HandsGenerator.HandDestroyHandler (hands_HandDestroy);

        //gestureGenerator.AddGesture ("Wave");
        //gestureGenerator.GestureRecognized += new GestureGenerator.GestureRecognizedHandler (gestures_GestureRecognized);
        //gestureGenerator.StartGenerating();

        if (drawSkeleton) {
            GameObject o = new GameObject ("User");
            mainUser = o.transform;
            mainUser.position = new Vector3 (0, 0, 0);
            mainUser.parent = transform;

            GameObject obj = Instantiate (o, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
            center = obj.transform;
            //center.parent = mainUser;
            obj.name = "Center";
            createDefaultLineRenderer (center);

            obj = Instantiate (o, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
            leftArm = obj.transform;
            //leftArm.parent = mainUser;
            obj.name = "L Arm";
            createDefaultLineRenderer (leftArm);

            obj = Instantiate (o, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
            rightArm = obj.transform;
            //rightArm.parent = mainUser;
            obj.name = "R Arm";
            createDefaultLineRenderer (rightArm);

            obj = Instantiate (o, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
            leftLeg = obj.transform;
            //leftLeg.parent = mainUser;
            obj.name = "L Leg";
            createDefaultLineRenderer (leftLeg);

            obj = Instantiate (o, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
            rightLeg = obj.transform;
            //rightLeg.parent = mainUser;
            obj.name = "R Leg";
            createDefaultLineRenderer (rightLeg);
        }
    }
Пример #29
0
        /// <summary>
        /// OpenNIスレッドの起動
        /// 
        /// </summary>
        private void StartOpenNI()
        {
            try
            {
                context = new Context(Application.StartupPath + Settings.OPENNI_CONFIG);
            } catch(GeneralException ge){
                Console.WriteLine(ge.Message);
                this.Close();
                return;
            }
            depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (this.depthGenerator == null)
            {
                throw new Exception("Viewer must have a depth node!");
            }

            userGenerator = new UserGenerator(context);
            userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser);
            userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser);
            userGenerator.StartGenerating();

            imageGenerator = context.FindExistingNode(NodeType.Image) as ImageGenerator;
            imageGenerator.StartGenerating();

            poseDetectionCapability = new PoseDetectionCapability(userGenerator);
            poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected);

            skeletonCapability = new SkeletonCapability(userGenerator);
            skeletonCapability.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapability_CalibrationEnd);
            skeletonCapability.SetSkeletonProfile(SkeletonProfile.All);

            depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);

            histogram = new int[depthGenerator.GetDeviceMaxDepth()];

            // 出力モード
            //this.mapMode = depthGenerator.GetMapOutputMode();
            this.mapMode = imageGenerator.GetMapOutputMode();

            bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/);
            shouldRun = true;
            openNiThread = new Thread(ReaderThread);
            openNiThread.Start();
        }
Пример #30
0
        private void InitOpenNi(AsyncStateData asyncData)
        {
            _niContext = new Context("openni.xml");

            _imageNode = (ImageGenerator)_niContext.FindExistingNode(NodeType.Image);

            _imageMeta = new ImageMetaData();
            _imageNode.GetMetaData(_imageMeta);

            // create the image bitmap source on
            asyncData.AsyncOperation.SynchronizationContext.Send(
                md => CreateImageBitmap(_imageMeta, out _rgbImageSource),
                null);

            // add depth node
            _depthNode = (DepthGenerator)_niContext.FindExistingNode(NodeType.Depth);

            _depthMeta = new DepthMetaData();
            _depthNode.GetMetaData(_depthMeta);

            asyncData.AsyncOperation.SynchronizationContext.Send(
                state => CreateImageBitmap(_depthMeta, out _depthImageSource, PixelFormats.Pbgra32),
                null);

            // add scene node
            //_sceneNode = (SceneAnalyzer) _niContext.FindExistingNode(NodeType.Scene);

            //_sceneMeta = new SceneMetaData();
            ////_sceneNode.GetMetaData(_sceneMeta);

            //asyncData.AsyncOperation.SynchronizationContext.Send(
            //    state => CreateImageBitmap(_sceneMeta, out _sceneImageSource, PixelFormats.Pbgra32),
            //    null);
        }
Пример #31
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();
    }
Пример #32
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();
        }
Пример #33
0
        private void CreateAndRun()
        {
            m_context = new Context(@"data\openNI.xml");
            m_imageGenerator = new ImageGenerator(m_context);
            m_depthGenerator = new DepthGenerator(m_context);

            SessionManager sessionManager = new SessionManager(m_context, "Wave", "RaiseHand");

            // update the state
            Dispatcher.BeginInvoke(() => { State = SessionState.Idle; });

            sessionManager.SessionStart += SessionManager_SessionStart;
            sessionManager.SessionEnd += SessionManager_SessionEnd;

            PointControl pointControl = new PointControl();
            pointControl.PrimaryPointCreate += PointControl_PrimaryPointCreate;
            pointControl.PrimaryPointDestroy += PointControl_PrimaryPointDestroy;
            pointControl.PrimaryPointUpdate += PointControl_PrimaryPointUpdate;

            SwipeDetector swipeDetector = new SwipeDetector();
            swipeDetector.UseSteady = true;
            swipeDetector.SwipeLeft += SwipeDetector_SwipeLeft;
            swipeDetector.SwipeRight += SwipeDetector_SwipeRight;

            PointDenoiser denoiser = new PointDenoiser();
            denoiser.AddListener(pointControl);
            denoiser.AddListener(swipeDetector);
            sessionManager.AddListener(denoiser);

            while (m_running)
            {
                m_context.WaitAndUpdateAll();
                sessionManager.Update(m_context);
            }
        }