コード例 #1
0
        public KinectManager()
        {
            try
            {
                _context = new Context(@"..\..\Data\openniconfig.xml");
                _depth_generator = _context.FindExistingNode(NodeType.Depth) as DepthGenerator;
                if (_depth_generator == null)
                    throw new Exception(@"Error in Data\openniconfig.xml - No depth node found.");

                _user_generator = new UserGenerator(_context);
                _skeleton_caps = _user_generator.SkeletonCapability;
                _pose_detect_caps = _user_generator.PoseDetectionCapability;
                _calibration_pose = _skeleton_caps.CalibrationPose;

                // event handler for detection
                _user_generator.NewUser += (_user_generator_NewUser);
                _user_generator.LostUser += (_user_generator_LostUser);
                _pose_detect_caps.PoseDetected += (_pose_detect_caps_PoseDetected);
                _skeleton_caps.CalibrationEnd += (_skeleton_caps_CalibrationEnd);

                _skeleton_caps.SetSkeletonProfile(SkeletonProfile.All);

                // initialize joints
                _joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>();
                _joint_orientation = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointOrientation>>();

                // start generating data
                _user_generator.StartGenerating();

            }catch(Exception ex)
            {
                Console.WriteLine("Error initializing OpenNi.");
                Console.WriteLine(ex.Message);
            }

            // update timer for the depth image
            DispatcherTimer dispatcher_timer = new DispatcherTimer();
            dispatcher_timer.Tick += new EventHandler(dispatcher_timer_Tick);
            dispatcher_timer.Interval = new TimeSpan(0, 0, 0, 0, 10); // update every 10 ms
            dispatcher_timer.Start();
            Console.WriteLine("Finished loading");
        }
コード例 #2
0
        public UserController(Context context, string calibrationPath)
        {
            this.Context = context;
            this.CalibrationPath = calibrationPath;
            this.Users = new Dictionary<int, KinectUser>();
            _UserLock = new object();
            _SkeletonLock = new object();

            _UserGenerator = new UserGenerator(Context);
            _SkeletonCapability = _UserGenerator.SkeletonCapability;
            _PoseDetectionCapability = _UserGenerator.PoseDetectionCapability;

            _CalibrationPose = _SkeletonCapability.CalibrationPose;

            _UserGenerator.NewUser += new EventHandler<NewUserEventArgs>(_UserGenerator_NewUser);
            _UserGenerator.LostUser += new EventHandler<UserLostEventArgs>(_UserGenerator_LostUser);
            _PoseDetectionCapability.PoseDetected += new EventHandler<PoseDetectedEventArgs>(PoseDetectionCapability_PoseDetected);
            _SkeletonCapability.CalibrationComplete += new EventHandler<CalibrationProgressEventArgs>(_SkeletonCapability_CalibrationComplete);

            _SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
            _UserGenerator.StartGenerating();
        }
コード例 #3
0
ファイル: UserNode.cs プロジェクト: smakhtin/VVVV.Nodes.Image
		void FState_Initialised(object sender, EventArgs e)
		{
			try
			{
				//initialise
				FUserGenerator = new UserGenerator(FState.Context);
				FUserGenerator.NewUser += new EventHandler<NewUserEventArgs>(FUserGenerator_NewUser);
				FUserGenerator.LostUser += new EventHandler<UserLostEventArgs>(FUserGenerator_LostUser);
				FUserGenerator.UserReEnter += new EventHandler<UserReEnterEventArgs>(FUserGenerator_UserReEnter);
				FUserGenerator.UserExit += new EventHandler<UserExitEventArgs>(FUserGenerator_UserExit);
				FUserGenerator.StartGenerating();

				FPinOutMask[0] = FImageMask.Link;
				FImageMask.Image.Initialise(new Size(640, 480), TColorFormat.L16);

				FState.Update += new EventHandler(FState_Update);

				FStarted = true;
				FPinOutStatus[0] = "OK";
			}
			catch (StatusException err)
			{
				Close();
				FPinOutStatus[0] = err.Message;
			}
		}
コード例 #4
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            FUserGenerator = new UserGenerator(FContextIn[0]);
                            FSkeletonCapability = FUserGenerator.SkeletonCapability;
                            FPoseDetectionCapability = FUserGenerator.PoseDetectionCapability;
                            FCalibPose = FSkeletonCapability.CalibrationPose;

                            FUserGenerator.NewUser += userGenerator_NewUser;
                            FUserGenerator.LostUser += userGenerator_LostUser;
                            FPoseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected;
                            FSkeletonCapability.CalibrationComplete += skeletonCapbility_CalibrationComplete;

                            FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]);
                            FJoints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointTransformation>>();

                            FUserGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            if ( (FUserGenerator != null) && (FUserIdIn != null) )
            {
                if (FEnabledIn.IsChanged)
                    if (FEnabledIn[0])
                        FUserGenerator.StartGenerating();
                    else
                        FUserGenerator.StopGenerating();

                if (FUserGenerator.IsDataNew)
                {
                    if (FSkeletonProfileIn.IsChanged)
                        FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]);

                    if (FSmoothingIn.IsChanged)
                        FSkeletonCapability.SetSmoothing(FSmoothingIn[0]);

                    FUserIdOut.SliceCount = 0;
                    FStatusOut.SliceCount = 0;

                    FJointPositionOut.SliceCount = 0;
                    FJointOrientationXOut.SliceCount = 0;
                    FJointOrientationYOut.SliceCount = 0;
                    FJointOrientationZOut.SliceCount = 0;

                    if (FUserGenerator.NumberOfUsers > 0)
                    {
                        //get all Users and sort them
                        int[] users = FUserGenerator.GetUsers();

                        FUserIdOut.SliceCount = users.Length;
                        FStatusOut.SliceCount = users.Length;

                        Array.Sort(users);
                        for (int i = 0; i<users.Length; i++) {

                            int userId = users[i];
                            bool userIsTracked = FSkeletonCapability.IsTracking(userId);
                            bool userIsCalibrated = FSkeletonCapability.IsCalibrated(userId);
                            bool userIsCalibrating = FSkeletonCapability.IsCalibrating(userId);

                            if(userIsTracked) FStatusOut[i] = "Tracking user ";
                            else if(userIsCalibrating) FStatusOut[i] = "Calibrating user ";
                            else FStatusOut[i] = "Looking for pose on user ";
                            FStatusOut[i] += userId.ToString();
                            FUserIdOut[i] = userId;

                            //if((userId != FUserIdIn[0]) && (!userIsTracked)) FSkeletonCapability.StopTracking(userId);

                            if(FUserIdIn.IsChanged && (userId != FUserIdIn[0]))
                            {
                                //if(!userIsTracked) FSkeletonCapability.StartTracking(userId);

                            }

                        } //for

                        if(FSkeletonCapability.IsTracking(FUserIdIn[0]))
                        {

                            int binSize = FJointIn.SliceCount;
                            FJointPositionOut.SliceCount = binSize;
                            FJointOrientationXOut.SliceCount = FJointOrientationYOut.SliceCount = FJointOrientationZOut.SliceCount = binSize;

                            for (int i = 0; i < binSize; i++)
                            {
                                var j = GetJoint(FUserIdIn[0], FJointIn[i]);

                                var p = j.Position.Position;
                                if (j.Position.Confidence >= FConfidenceIn[0])
                                    FJointPositionOut[i] = new Vector3D(p.X, p.Y, p.Z) / 1000;

                                var o = j.Orientation;
                                if (o.Confidence > FConfidenceIn[0])
                                {
                                    FJointOrientationXOut[i] = new Vector3D(o.X1, o.Y1, o.Z1);
                                    FJointOrientationYOut[i] = new Vector3D(o.X2, o.Y2, o.Z2);
                                    FJointOrientationZOut[i] = new Vector3D(o.X3, o.Y3, o.Z3);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                FUserIdOut.SliceCount = 0;
                FStatusOut.SliceCount = 0;
                FJointPositionOut.SliceCount = 0;
                FJointOrientationXOut.SliceCount = 0;
                FJointOrientationYOut.SliceCount = 0;
                FJointOrientationZOut.SliceCount = 0;
            }
        }
コード例 #5
0
ファイル: Sensor.cs プロジェクト: skpdvdd/NITEVis
        public Sensor(string config)
        {
            if (string.IsNullOrEmpty(config))
                throw new ArgumentNullException();

            try
            {
                _context = Context.CreateFromXmlFile(config, out _scriptNode);
                _depthGenerator = _context.FindExistingNode(NodeType.Depth) as DepthGenerator;
                _imageGenerator = _context.FindExistingNode(NodeType.Image) as ImageGenerator;
                _userGenerator = _context.FindExistingNode(NodeType.User) as UserGenerator;

                if (_depthGenerator == null)
                    throw new ApplicationException("No depth node found.");

                if (_imageGenerator == null)
                    throw new ApplicationException("No image node found.");

                if (_userGenerator == null)
                    throw new ApplicationException("No user node found.");

                if (_depthGenerator.MapOutputMode.FPS != _imageGenerator.MapOutputMode.FPS)
                    throw new ApplicationException("Depth and image node must have common framerates.");

                if (_depthGenerator.MapOutputMode.XRes != _imageGenerator.MapOutputMode.XRes)
                    throw new ApplicationException("Depth and image node must have common horizontal resolutions.");

                if (_depthGenerator.MapOutputMode.YRes != _imageGenerator.MapOutputMode.YRes)
                    throw new ApplicationException("Depth and image node must have common vertical resolutions.");

                _depthMetaData = new DepthMetaData();
                _imageMetaData = new ImageMetaData();

                _imageWidth = _depthGenerator.MapOutputMode.XRes;
                _imageHeight = _depthGenerator.MapOutputMode.YRes;

                _userGenerator.NewUser += new EventHandler<NewUserEventArgs>(_userGenerator_NewUser);
                _userGenerator.LostUser += new EventHandler<UserLostEventArgs>(_userGenerator_LostUser);
                _userGenerator.StartGenerating();

                _bitmapGenerator = new BitmapGenerator(this);

                _readerWaitHandle = new AutoResetEvent(false);

                _readerThread = new Thread(delegate()
                {
                    try
                    {
                        while (_run)
                        {
                            if (_pause)
                                _readerWaitHandle.WaitOne();

                            _context.WaitAndUpdateAll();

                            _depthGenerator.GetMetaData(_depthMetaData);
                            _imageGenerator.GetMetaData(_imageMetaData);

                            if (_depthMetaData.XRes != _imageWidth || _imageMetaData.XRes != _imageWidth)
                                throw new ApplicationException("Image width must not change.");

                            if (_depthMetaData.YRes != _imageHeight || _imageMetaData.YRes != _imageHeight)
                                throw new ApplicationException("Image height must not change.");

                            if (GeneratorUpdate != null)
                                GeneratorUpdate(this, EventArgs.Empty);
                        }
                    }
                    catch (ThreadInterruptedException)
                    {
                        Console.WriteLine("Reader thread interrupted.");
                    }
                    catch (Exception e)
                    {
                        throw new ApplicationException("Error while processing sensor data.", e);
                    }
                }) { Name = "ONI Reader Thread" };
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #6
0
ファイル: NiteOpenNet.cs プロジェクト: timofei7/TiNWii
    void Start()
    {
        InitializeCharacter ();
        context = new Context (XML_SETUP_FILE);
        sessionManager = new SessionManager(context, "Wave", "RaiseHand");
        depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
        handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator;

        //image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
        //gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
        if (depthGenerator == null) throw new Exception("Viewer must have a depth node!");
        //if (gesture == null) throw new Exception("Viewer must have a gesture node!");
        //if (image == null) throw new Exception("Viewer must have a image node!");

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

        foreach (String s in poseDetectionCapability.GetAllAvailablePoses())
            Debug.LogWarning("available pose found: " +s);

        //foreach (String s in gestureGenerator.EnumerateAllGestures())
        //	Debug.LogWarning("available gesture found: " + s);

        //gestureGenerator.GestureRecognized += HandleGestureGestureRecognized;
        //gesture.AddGesture("Click");
        //gestureGenerator.AddGesture("RaiseHand"); //seems buggy
        //gestureGenerator.AddGesture("Wave");

        swipeDetector = new SwipeDetector();
        //steadyDetector = new SteadyDetector();//(3, 1f);

        //swipeDetector.SwipeLeft += HandleSwipeDetectorSwipeLeft;

        //Session Managment
        sessionManager.SessionStart += HandleSessionManagerSessionStart;
        sessionManager.SessionEnd += HandleSessionManagerSessionEnd;

        //User Generator
        userGenerator.NewUser += HandleUserGeneratorNewUser;
        userGenerator.LostUser += HandleUserGeneratorLostUser;
        poseDetectionCapability.PoseDetected += HandlePoseDetectionCapabilityPoseDetected;
        skeletonCapability.CalibrationEnd += HandleSkeletonCapabilityCalibrationEnd;

        skeletonCapability.SetSkeletonProfile (SkeletonProfile.All);
        skeletonCapability.SetSmoothing(.5f); // give us some smooothing

        //Start generating
        userGenerator.StartGenerating();
        //handsGenerator.MirrorCapability.SetMirror(true); // TODO: should this be true?
        handsGenerator.StartGenerating();
        //gestureGenerator.StartGenerating();

        //slider selector
        //selectableSlider2D = new SelectableSlider2D(Screen.width, Screen.height);
        //selectableSlider2D.ValueChange += HandleSelectableSlider2DValueChange;
        //selectableSlider2D.ItemHover += HandleSelectableSlider2DItemHover;
        //selectableSlider2D.ItemSelect += HandleSelectableSlider2DItemSelect;

        pointDenoiser = new PointDenoiser();
        pointDenoiser.AddListener(swipeDetector);
        //pointDenoiser.AddListener(steadyDetector);
        //pointDenoiser.AddListener(selectableSlider2D);

        //flowRouter = new FlowRouter();
        //flowRouter.ActiveListener = pointDenoiser;

        sessionManager.AddListener(pointDenoiser);

        MapOutputMode mapMode = depthGenerator.MapOutputMode;

        // Init depth & label map related stuff
        usersMapSize = mapMode.XRes * mapMode.YRes;
        //usersLabelTexture = new Texture2D(mapMode.XRes, mapMode.YRes); //nonPOT slow
        usersLabelTexture = new Texture2D(1024,512);
        //speed up by using power of two and then setpixel() with blockwidth (640) and blockheight (480)
        usersMapColors = new Color[usersMapSize];
        usersMapRect = new Rect(Screen.width - usersLabelTexture.width / 2, Screen.height - usersLabelTexture.height / 2, usersLabelTexture.width / 2, usersLabelTexture.height / 2);
        usersLabelMap = new short[usersMapSize];
        usersDepthMap = new short[usersMapSize];
        usersHistogramMap = new float[5000];

        this.shouldRun = true;

        if (NiteInitializingEvent != null) //notify others that we're done initializing
            NiteInitializingEvent(this, EventArgs.Empty);
    }
コード例 #7
0
		//called when data for any output pin is requested
		public void Evaluate(int SpreadMax)
		{
			if (FPinInContext[0] != FState)
				FState = FPinInContext[0];

			if (FState == null)
			{
				Close();
				return;
			}

			if (FState.Running && !FStarted && FState.Context != null)
			{
				try
				{
					//initialise
					FUserGenerator = new UserGenerator(FState.Context);
					FUserGenerator.NewUser += new EventHandler<NewUserEventArgs>(FUserGenerator_NewUser);
					FUserGenerator.LostUser += new EventHandler<UserLostEventArgs>(FUserGenerator_LostUser);
					FUserGenerator.UserReEnter += new EventHandler<UserReEnterEventArgs>(FUserGenerator_UserReEnter);
					FUserGenerator.UserExit += new EventHandler<UserExitEventArgs>(FUserGenerator_UserExit);
					FUserGenerator.StartGenerating();

					FPinOutMask[0] = FImageMask.Link;
					FImageMask.Image.Initialise(new Size(640, 480), TColourFormat.L16);

					FState.Update += new EventHandler(FState_Update);

					FStarted = true;
					FPinOutStatus[0] = "OK";
				}
				catch (StatusException e)
				{
					Close();
					FPinOutStatus[0] = e.Message;
				}
			}

			if (FStarted)
				GiveOutputs();
			else
			{
				FPinOutID.SliceCount = 0;
				FPinOutPresent.SliceCount = 0;
			}
		}