public MainWindow()
        {
            InitializeComponent();

            try {
                // ContextとImageGeneratorの作成
                ScriptNode node;
                context = Context.CreateFromXmlFile( "../../SamplesConfig.xml", out node );
                context.GlobalMirror = false;
                image = context.FindExistingNode( NodeType.Image ) as ImageGenerator;

                // ユーザーの作成
                user = new UserGenerator( context );

                context.StartGeneratingAll();

                // 画像更新のためのスレッドを作成
                shouldRun = true;
                readerThread = new Thread( new ThreadStart( ReaderThread ) );
                readerThread.Start();
            }
            catch ( Exception ex ) {
                MessageBox.Show( ex.Message );
            }
        }
        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();
        }
        public MainWindow()
        {
            InitializeComponent();

            try {
                // ContextとImageGeneratorの作成
                ScriptNode node;
                context = Context.CreateFromXmlFile( "../../SamplesConfig.xml", out node );
                context.GlobalMirror = true;
                image = context.FindExistingNode( NodeType.Image ) as ImageGenerator;
                depth = context.FindExistingNode( NodeType.Depth ) as DepthGenerator;
                depth.AlternativeViewpointCapability.SetViewpoint( image );

                // ユーザーの作成
                user = context.FindExistingNode( NodeType.User ) as UserGenerator;

                // ユーザー認識のコールバックを登録
                user.NewUser += new EventHandler<NewUserEventArgs>( user_NewUser );

                //キャリブレーションにポーズが必要か確認
                if ( user.SkeletonCapability.DoesNeedPoseForCalibration ) {
                    // ポーズ検出のサポートチェック
                    if ( !user.IsCapabilitySupported( "User::PoseDetection" ) ) {
                        throw new Exception( "ポーズ検出をサポートしていません" );
                    }

                    // ポーズ検出のコールバックを登録
                    user.PoseDetectionCapability.PoseDetected +=
                        new EventHandler<PoseDetectedEventArgs>( poseDetect_PoseDetected );
                }

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

                // キャリブレーションのコールバックを登録
                user.SkeletonCapability.CalibrationEnd +=
                    new EventHandler<CalibrationEndEventArgs>( skelton_CalibrationEnd );

                // すべてをトラッキングする
                user.SkeletonCapability.SetSkeletonProfile( SkeletonProfile.HeadAndHands );

                // ジェスチャーの検出開始
                context.StartGeneratingAll();

                // 画像更新のためのスレッドを作成
                shouldRun = true;
                readerThread = new Thread( new ThreadStart( ReaderThread ) );
                readerThread.Start();
            }
            catch ( Exception ex ) {
                MessageBox.Show( ex.Message );
            }
        }
Example #4
0
	void Start() 
	{
		calibratedUsers = new List<int>();
		calibratingUsers = new List<int>();
		allUsers = new List<int>();

		this.userGenerator = OpenNIContext.OpenNode(NodeType.User) as UserGenerator; //new UserGenerator(this.Context.context);
		this.skeletonCapbility = this.userGenerator.SkeletonCapability;
		this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
		this.calibPose = this.skeletonCapbility.CalibrationPose;
		this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);

        this.userGenerator.NewUser += new EventHandler<NewUserEventArgs>(userGenerator_NewUser);
        this.userGenerator.LostUser += new EventHandler<UserLostEventArgs>(userGenerator_LostUser);
        this.poseDetectionCapability.PoseDetected += new EventHandler<PoseDetectedEventArgs>(poseDetectionCapability_PoseDetected);
        this.skeletonCapbility.CalibrationEnd += new EventHandler<CalibrationEndEventArgs>(skeletonCapbility_CalibrationEnd);
	}
        public MainWindow()
        {
            InitializeComponent();

            try
            {
                // OpenNIの初期化
                ScriptNode node;
                context = Context.CreateFromXmlFile("../../SamplesConfig.xml", out node);
                context.GlobalMirror = false;

                // depthの作成
                depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;

                // ユーザーの作成
                user = new UserGenerator(context);

                // ポーズが必要な場合は、最新版を入れてもらう
                if (user.SkeletonCapability.DoesNeedPoseForCalibration)
                {
                    throw new Exception("最新のOpenNIをインストールしてください");
                }

                // ユーザー検出、キャリブレーション完了のイベントを登録する
                user.NewUser += new EventHandler<NewUserEventArgs>(user_NewUser);
                user.SkeletonCapability.CalibrationComplete += new EventHandler<CalibrationProgressEventArgs>(SkeletonCapability_CalibrationComplete);

                // すべての骨格を追跡する
                user.SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All);

                // 動作を開始する
                context.StartGeneratingAll();

                // 画像更新のためのスレッドを作成
                shouldRun = true;
                readerThread = new Thread(new ThreadStart(ReaderThread));
                readerThread.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        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");
        }
        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();
        }
        public void DrawOrientation(ref WriteableBitmap image, int id, UserGenerator userGenerator, SkeletonJoint joint, Point3D corner)
        {
            SkeletonJointOrientation orientation = new SkeletonJointOrientation();
            SkeletonJointPosition position = new SkeletonJointPosition();

            position = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, joint);
            orientation = userGenerator.SkeletonCapability.GetSkeletonJointOrientation(id, joint);

            if (position.Confidence != 1 && orientation.Confidence != 1)
            {
                return;
            }

            SkeletonJointPosition v1 = new SkeletonJointPosition();
            SkeletonJointPosition v2 = new SkeletonJointPosition();
            v1.Confidence = v2.Confidence = 1;

            v1.Position = position.Position;
            v2.Position = new Point3D(v1.Position.X + 100 * orientation.X1,
                                      v1.Position.Y + 100 * orientation.Y1,
                                      v1.Position.Z + 100 * orientation.Z1);

            DrawTheLine(ref image, ref v1, ref v2);

            v1.Position = position.Position;
            v2.Position = new Point3D(v1.Position.X + 100 * orientation.X2,
                                      v1.Position.Y + 100 * orientation.Y2,
                                      v1.Position.Z + 100 * orientation.Z2);

            DrawTheLine(ref image, ref v1, ref v2);

            v1.Position = position.Position;
            v2.Position = new Point3D(v1.Position.X + 100 * orientation.X3,
                                      v1.Position.Y + 100 * orientation.Y3,
                                      v1.Position.Z + 100 * orientation.Z3);

            DrawTheLine(ref image, ref v1, ref v2);
        }
        public void DrawHeadAndHands(ref WriteableBitmap image, int id, UserGenerator userGenerator, DepthGenerator depthGenerator)
        {
            int headSize = 40; int handSize = 20;

            SkeletonJointPosition head = new SkeletonJointPosition();
            SkeletonJointPosition leftHand = new SkeletonJointPosition();
            SkeletonJointPosition rightHand = new SkeletonJointPosition();

            head = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.Head);
            leftHand = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.LeftHand);
            rightHand = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.RightHand);

            image.Lock();

            var b = new Bitmap(image.PixelWidth, image.PixelHeight, image.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format24bppRgb,
                image.BackBuffer);

            using (var bitmapGraphics = System.Drawing.Graphics.FromImage(b))
            {
                bitmapGraphics.SmoothingMode = SmoothingMode.HighSpeed;
                bitmapGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
                bitmapGraphics.CompositingMode = CompositingMode.SourceCopy;
                bitmapGraphics.CompositingQuality = CompositingQuality.HighSpeed;

                int[] headCoord = ConvertCoord(head, -headSize/2);
                int[] leftHandCoord = ConvertCoord(leftHand, -handSize/2);
                int[] rightHandCoord = ConvertCoord(rightHand, -handSize/2);

                bitmapGraphics.DrawEllipse(Pens.BlueViolet, headCoord[0], headCoord[1], headSize, headSize);
                bitmapGraphics.DrawEllipse(Pens.BlueViolet, leftHandCoord[0], leftHandCoord[1], handSize, handSize);
                bitmapGraphics.DrawEllipse(Pens.BlueViolet, rightHandCoord[0], rightHandCoord[1], handSize, handSize);

                bitmapGraphics.Dispose();
            }
            image.AddDirtyRect(new Int32Rect(0, 0, image.PixelWidth, image.PixelHeight));
            image.Unlock();
        }
        public SpatialController(ControllerStartup startupType, UserGenerator userGenerator)
        {
            this.raysToBeAnimated = new Ray3D[2]; // Left and right, in this case.
            this.userGenerator = userGenerator;
            this.animationLock = new object();
            this.calibrated = false;

            this.devices = new Device[Device.getNodes().Count];
            for (int i = 0; i < devices.Length; i++)
            {
                this.devices[i] = devices[i];
            }

            synth = new SpeechSynthesizer();
            synth.SelectVoice("Microsoft Anna");

            SpeakAndWriteToPrompt("Starting SpatialController!");

            switch (startupType)
            {
                case ControllerStartup.FromFile:
                    this.calibrated = true;
                    initFromFile();
                    break;
                case ControllerStartup.Calibrate:
                    // Wait for user to be recognized to start calibration.
                    break;
                default:
                    break;
            }

            dimmingDown = false;
            dimmingUp = false;
            dimmingStartY = -1000.0;

            VoiceCalibration();
        }
        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");
        }
 // private methods
 /// @brief private constructor
 /// 
 /// This is part of the singleton pattern, a protected constructor cannot be called externally (although
 /// it can be inherited for extensions. In which case the extender should also replace the singleton!
 private NIUserAndSkeleton()
 {
     m_userGenerator = null;
 }
    /// @brief Initialize the user and skeleton information
    /// 
    /// This method initializes the user and skeleton information. It assumes the 
    /// context is already valid (otherwise we fail).
    /// @note - Since we use a singleton pattern, multiple initializations will simply delete 
    /// the old information and create new one!
    /// @note - It is the responsibility of the initializer to call @ref Dispose.
    /// @param context the context used
    /// @param logger the logger object we will enter logs into
    /// @return true on success, false on failure. 
    public bool Init(NIEventLogger logger, NIContext context)
    {
        NIOpenNICheckVersion.Instance.ValidatePrerequisite();
        Dispose(); // to make sure we are not initialized
        if (InitWithContext(logger, context) == false)
            return false;

        m_userGenerator = context.CreateNode(NodeType.User) as UserGenerator;
        if (m_userGenerator == null || m_userGenerator.SkeletonCapability==null)
        {
            Log("Failed to create proper user generator.", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.Skeleton, NIEventLogger.VerboseLevel.Errors);
            // we either don't have a user generator or the user generator we received does not have a skeleton
            Dispose();
            return false;
        }
        // skeleton heuristics tries to handle the skeleton when the confidence is low. It can
        // have two values: 0 (no heuristics) or 255 (use heuristics).
        m_userGenerator.SetIntProperty("SkeletonHeuristics", 255);
        // makes sure we use all joints
        m_userGenerator.SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
        PoseDetectionCapability cap = UserNode.PoseDetectionCapability;
        if (cap != null)
            m_legalPoses = cap.GetAllAvailablePoses();
        else
            m_legalPoses = null;
        m_poseDetectionCounter = new List<poseDetectionReferenceCounter>();
        m_userGenerator.LostUser += new EventHandler<UserLostEventArgs>(LostUserCallback);

        return true;
    }
Example #14
0
        private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType? type)
        {
            lock (this)
            {
                if (!this.allNodes.ContainsKey(nodeHandle))
                {
                    if (type == null)
                    {
                        IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle);
                        type = NodeInfo.FromNative(pNodeInfo).Description.Type;
                    }

                    ProductionNode node;

                    switch (type)
                    {
                        case NodeType.Device:
                            node = new Device(this, nodeHandle, true);
                            break;
                        case NodeType.Depth:
                            node = new DepthGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Image:
                            node = new ImageGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Audio:
                            node = new AudioGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.IR:
                            node = new IRGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.User:
                            node = new UserGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Recorder:
                            node = new Recorder(this, nodeHandle, true);
                            break;
                        case NodeType.Player:
                            node = new Player(this, nodeHandle, true);
                            break;
                        case NodeType.Gesture:
                            node = new GestureGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Scene:
                            node = new SceneAnalyzer(this, nodeHandle, true);
                            break;
                        case NodeType.Hands:
                            node = new HandsGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Codec:
                            node = new Codec(this, nodeHandle, true);
                            break;
                        case NodeType.ProductionNode:
                            node = new ProductionNode(this, nodeHandle, true);
                            break;
                        case NodeType.Generator:
                            node = new Generator(this, nodeHandle, true);
                            break;
                        case NodeType.MapGenerator:
                            node = new MapGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.ScriptNode:
                            node = new ScriptNode(this, nodeHandle, true);
                            break;
                        default:
                            throw new NotImplementedException("C# wrapper: Unknown generator type!");
                    }
                    this.allNodes[nodeHandle] = node;
                }

                return this.allNodes[nodeHandle];
            } // lock
        }
        /// <summary>
        /// Saves the labelmap with the provided stream.
        /// </summary>
        protected unsafe void saveUserDataToFileStream(BinaryWriter userInformationWriter, UserGenerator userGenerator)
        {
            ushort* pLabels = (ushort*)userGenerator.GetUserPixels(0).LabelMapPtr.ToPointer();

            // At one position, only three bits of the 16 actual ushort bits
            // are used to indicate the user id. So by combining four of these
            // values, it is possible to write three bytes to the stream.
            // This might be implemented for a future release.
            
            for (int y = 0; y < imageMD.YRes; ++y)
            {
                for (int x = 0; x < imageMD.XRes; ++x)
                {
                    userInformationWriter.Write(*pLabels++);
                }
            }
        }
Example #16
0
		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;
			}
		}
Example #17
0
		private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType? type)
		{
			lock (this)
			{
				if (!this.allNodes.ContainsKey(nodeHandle))
				{
					if (type == null)
					{
						IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle);
                        type = NodeInfo.FromNative(pNodeInfo).Description.Type;
					}

					ProductionNode node;

                   	// start with concrete types
                    if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Device))
                    {
                        node = new Device(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Depth))
                    {
                        node = new DepthGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Image))
                    {
                        node = new ImageGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Audio))
                    {
                        node = new AudioGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.IR))
                    {
                        node = new IRGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.User))
                    {
                        node = new UserGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Recorder))
                    {
                        node = new Recorder(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Player))
                    {
                        node = new Player(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Gesture))
                    {
                        node = new GestureGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Scene))
                    {
                        node = new SceneAnalyzer(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Hands))
                    {
                        node = new HandsGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Codec))
                    {
                        node = new Codec(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ScriptNode))
                    {
                        node = new ScriptNode(this, nodeHandle, true);
                    }
                    // move on to abstract types
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.MapGenerator))
                    {
                        node = new MapGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Generator))
                    {
                        node = new Generator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ProductionNode))
                    {
                        node = new ProductionNode(this, nodeHandle, true);
                    }
                    else
                    {
                        throw new NotImplementedException("C# wrapper: Unknown generator type!");
                    }

					this.allNodes[nodeHandle] = node;
				}

				return this.allNodes[nodeHandle];
			} // lock
		}
Example #18
0
        /// <summary>
        /// Creates a new instance of SensorData with the specified configuration file.
        /// </summary>
        /// <param name="configuration">Configuration file path.</param>
        public HandTracker(string configuration)
        {
            InitializeCamera(configuration);
            InitializeBitmaps();
            InitializeThread();

            this.DepthGenerator.AlternativeViewpointCapability.SetViewpoint(this.ImageGenerator);
            this.userGenerator = new UserGenerator(this.Context);
            this.skeletonCapbility = this.userGenerator.SkeletonCapability;
            this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
            this.calibPose = this.skeletonCapbility.CalibrationPose;
            this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected;
            this.skeletonCapbility.CalibrationComplete += skeletonCapbility_CalibrationComplete;

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

            this.sessionManager = new NITE.SessionManager(this.Context, "Wave,Click", "RaiseHand");
            _handsGenerator = new HandsGenerator(Context);
            _handsGenerator.SetSmoothing(0.1f);

            _gestureGenerator = new GestureGenerator(Context);

            this.Context.StartGeneratingAll();
            Console.WriteLine("Start Generating All");

            pointControl = new PointControl("PointTracker");
            pointControl.PointCreate += new EventHandler<HandEventArgs>(pointControl_PointCreate);
            pointControl.PointUpdate += new EventHandler<HandEventArgs>(pointControl_PointUpdate);
            pointControl.PointDestroy += new EventHandler<IdEventArgs>(pointControl_PointDestroy);
            sessionManager.AddListener(pointControl);

            this.userGenerator.NewUser += userGenerator_NewUser;
            this.userGenerator.LostUser += userGenerator_LostUser;
            this.userGenerator.StartGenerating();
        }
Example #19
0
        private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType?type)
        {
            lock (this)
            {
                if (!this.allNodes.ContainsKey(nodeHandle))
                {
                    if (type == null)
                    {
                        IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle);
                        type = NodeInfo.FromNative(pNodeInfo).Description.Type;
                    }

                    ProductionNode node;

                    // start with concrete types
                    if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Device))
                    {
                        node = new Device(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Depth))
                    {
                        node = new DepthGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Image))
                    {
                        node = new ImageGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Audio))
                    {
                        node = new AudioGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.IR))
                    {
                        node = new IRGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.User))
                    {
                        node = new UserGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Recorder))
                    {
                        node = new Recorder(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Player))
                    {
                        node = new Player(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Gesture))
                    {
                        node = new GestureGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Scene))
                    {
                        node = new SceneAnalyzer(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Hands))
                    {
                        node = new HandsGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Codec))
                    {
                        node = new Codec(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ScriptNode))
                    {
                        node = new ScriptNode(this, nodeHandle, true);
                    }
                    // move on to abstract types
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.MapGenerator))
                    {
                        node = new MapGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Generator))
                    {
                        node = new Generator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ProductionNode))
                    {
                        node = new ProductionNode(this, nodeHandle, true);
                    }
                    else
                    {
                        throw new NotImplementedException("C# wrapper: Unknown generator type!");
                    }

                    this.allNodes[nodeHandle] = node;
                }

                return(this.allNodes[nodeHandle]);
            }             // lock
        }
Example #20
0
        /// <summary>
        /// Creates a new instance of SensorData with the specified configuration file.
        /// </summary>
        /// <param name="configuration">Configuration file path.</param>
        public SensorData(string configuration)
        {
            InitializeCamera(configuration);
            InitializeBitmaps();
            InitializeThread();

            //New flow router
            this.flowRouter = new NITE.FlowRouter();

            this.boxes = new MyBox("Box1");
            this.boxes.Leave += new MyBox.LeaveHandler(boxes_Leave);
            this.boxes.Update += new MyBox.UpdateHandler(boxes_Update);
            this.sessionManager.AddListener(this.flowRouter);
            this.sessionManager.SessionStart += new EventHandler<NITE.PositionEventArgs>(sessionManager_SessionStart);
            Console.WriteLine("Initialized Sensor Data");

            this.DepthGenerator.AlternativeViewpointCapability.SetViewpoint(this.ImageGenerator);
            this.userGenerator = new UserGenerator(this.Context);
            this.skeletonCapbility = this.userGenerator.SkeletonCapability;
            this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
            this.calibPose = this.skeletonCapbility.CalibrationPose;
            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.NewUser += userGenerator_NewUser;
            this.userGenerator.LostUser += userGenerator_LostUser;
            this.userGenerator.StartGenerating();
        }
    void Start()
    {
        this.hands.HandCreate += new EventHandler<HandCreateEventArgs>(hands_HandCreate);
        this.hands.HandUpdate += new EventHandler<HandUpdateEventArgs>(hands_HandUpdate);
        this.hands.HandDestroy += new EventHandler<HandDestroyEventArgs>(hands_HandDestroy);

        if (DetectWave) {
            this.gestures.AddGesture ("Wave");
        }
        if (DetectPush) {
            this.gestures.AddGesture ("Click");
        }

        if (ExperimentalGestureless) {
            this.gestures.AddGesture("RaiseHand");
        }

        this.gestures.GestureRecognized += new EventHandler<GestureRecognizedEventArgs> (gestures_GestureRecognized);

        if (RotateToUser) {
            if (null == userGenerator) {
                userGenerator = OpenNIContext.OpenNode(NodeType.User) as UserGenerator;
            }
        }
    }
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
              ScriptNode scriptNode;
              context = Context.CreateFromXmlFile( CONFIG_XML_PATH, out scriptNode );

              // 鏡モード(反転)にしない
              context.GlobalMirror = false;

              // イメージジェネレータの作成
              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("ユーザー検出をサポートしていません");
              }

              // ユーザー認識のコールバックを登録
              user.NewUser += new EventHandler<NewUserEventArgs>(user_NewUser);
              user.LostUser += new EventHandler<UserLostEventArgs>(user_LostUser);

              //キャリブレーションにポーズが必要か確認
              skelton = user.SkeletonCapability;
              if (skelton.DoesNeedPoseForCalibration) {
            // ポーズ検出のサポートチェック
            if (!user.IsCapabilitySupported("User::PoseDetection")) {
              throw new Exception("ユーザー検出をサポートしていません");
            }

            // キャリブレーションポーズの取得
            pose = skelton.CalibrationPose;

            // ポーズ検出のコールバックを登録
            PoseDetectionCapability poseDetect = user.PoseDetectionCapability;
            poseDetect.PoseDetected += new EventHandler<PoseDetectedEventArgs>(poseDetect_PoseDetected);
            poseDetect.OutOfPose += new EventHandler<OutOfPoseEventArgs>( poseDetect_OutOfPose );
              }

              // キャリブレーションのコールバックを登録
              skelton.CalibrationStart += new EventHandler<CalibrationStartEventArgs>(skelton_CalibrationStart);
              skelton.CalibrationComplete += new EventHandler<CalibrationProgressEventArgs>( skelton_CalibrationComplete );

              // すべてをトラッキングする
              skelton.SetSkeletonProfile(SkeletonProfile.All);

              // ジェスチャーの検出開始
              context.StartGeneratingAll();
        }
        public void DrawStickLine(ref WriteableBitmap image, int id, UserGenerator userGenerator, SkeletonJoint first, SkeletonJoint second, Point3D corner)
        {
            SkeletonJointPosition a = new SkeletonJointPosition();
            SkeletonJointPosition b = new SkeletonJointPosition();

            a = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, first);
            b = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, second);

            if (a.Confidence == 1 && b.Confidence == 1)
            {
                // choose color
            }
            else
            {
                if ((a.Position.X == 0 && a.Position.Y == 0 && a.Position.Z == 0) ||
                    (b.Position.X == 0 && b.Position.Y == 0 && b.Position.Z == 0))
                {
                    return;
                }
            }

            DrawTheLine(ref image, ref a, ref b);
        }
Example #24
0
 private void Initialize()
 {
     ScriptNode scriptNode;
     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.userGenerator.NewUser += this.OnUserGeneratorNewUser;
     this.userGenerator.LostUser += this.OnUserGeneratorLostUser;
     this.skeletonCapbility.CalibrationComplete += this.OnSkeletonCapbilityCalibrationComplete;
     this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);
     this.joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>();
     this.userGenerator.StartGenerating();
 }
Example #25
0
		void Close()
		{
			if (FStarted)
			{
				if (FUserGenerator != null)
					FUserGenerator.Dispose();
				FUserGenerator = null;
				FStarted = false;
			}
		}
Example #26
0
    // Use this for initialization
    void Start()
    {
        this.context=Context.CreateFromXmlFile(XML_CONFIG,out scriptNode);
        //Al Ejecutar esta linea al salir de probar el nodo sigue trabajando para eso ocupamos el onApplicationQuit
        this.depth=context.FindExistingNode(NodeType.Depth) as DepthGenerator;
        if(depth==null){
            throw new Exception("Nodo de Profundidad no encontrado");
        }
        this.userGenerator=new UserGenerator(this.context);
        this.skeletonCapability=this.userGenerator.SkeletonCapability;
        this.poseDetectionCapability=this.userGenerator.PoseDetectionCapability;
        this.calibPose=this.skeletonCapability.CalibrationPose;
        //Agregas los handlers
        this.userGenerator.NewUser+=userGenerator_NewUser;
        this.userGenerator.LostUser+=userGenerator_LostUser;
        this.poseDetectionCapability.PoseDetected+=poseDetectionCapability_PoseDetected;
        this.skeletonCapability.CalibrationComplete+=skeletonCapability_CalibrationComplete;
        //Activar los joints depende del profile
        //http://openni.org/docs2/Reference/_xn_types_8h_a294999eabe6eeab319a61d3d0093b174.html#a294999eabe6eeab319a61d3d0093b174
        this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
        this.joints=new Dictionary<int,Dictionary<SkeletonJoint,SkeletonJointPosition>>();

        this.userGenerator.StartGenerating();
        this.shouldRun=true;
    }
 /// <summary>
 /// Initializes the usergenerator based on the config file
 /// </summary>
 private void InitializeUserGenerator()
 {
     UserGenerator = Context.FindExistingNode(NodeType.User) as UserGenerator;
     if (this.UserGenerator == null)
     {
         throw new OpenNI.GeneralException("Viewer must have a user node!");
     }
 }
 /// @brief Release a previously initialize image node.
 /// 
 /// This method releases a previously initialized image node.
 /// @note - Since we use a singleton pattern, only one place should do a release, otherwise the
 /// result could become problematic for other objects
 /// @note - It is the responsibility of the whoever called @ref Init to do the release. 
 /// @note - The release should be called BEFORE releasing the context. If the context is invalid, the result is
 /// undefined.
 public override void Dispose()
 {
     if (m_context == null)
     {
         return;
     }
     if (m_userGenerator != null)
     {
         if (m_poseDetectionCounter != null)
         {
             m_poseDetectionCounter.Clear();
             m_poseDetectionCounter = null;
         }
         m_context.ReleaseNode(m_userGenerator); // we call this even if the context is invalid because it is a singleton which will release stuff
         m_userGenerator = null;
     }
     base.Dispose();
 }
    /*
    private int distanciaAnt=0;
    private int escalaAnt=0;
    */
    void Start()
    {
        Debug.Log("START APP");
        this.context=Context.CreateFromXmlFile(XML_CONFIG, out scriptNode);
        this.depth=this.context.FindExistingNode(NodeType.Depth) as DepthGenerator;
        if(depth==null){
            throw new Exception("Nodo de Profundidad no encontrado");
        }

        //User Tracking
        this.userGenerator=new UserGenerator(this.context);
        this.skeletonCapability=this.userGenerator.SkeletonCapability;
        this.poseDetectionCapability=this.userGenerator.PoseDetectionCapability;
        this.calibPose=this.skeletonCapability.CalibrationPose;
        this.userGenerator.NewUser+=userGenerator_NewUser;
        this.userGenerator.LostUser+=userGenerator_LostUser;
        this.poseDetectionCapability.PoseDetected+=poseDetectionCapability_PoseDetected;
        this.skeletonCapability.CalibrationComplete+=skeletonCapability_CalibrationComplete;
        this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.All);
        this.userGenerator.StartGenerating();
        this.joints=new Dictionary<int,Dictionary<SkeletonJoint,SkeletonJointPosition>>();
        //
    }
        // 初期化
        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("ユーザー検出をサポートしていません");
              }

              // ユーザー認識のコールバックを登録
              user.NewUser += new EventHandler<NewUserEventArgs>(user_NewUser);
              user.LostUser += new EventHandler<UserLostEventArgs>(user_LostUser);
        }
Example #31
0
        private void VerifyInit()
        {
            if (context != null)
            {
                return;
            }
            string initFile = @"data/openni.xml";

            bool isInit = false;
            while (!isInit)
            {
                try
                {
                    context = new Context(initFile);
                    isInit = true;
                }
                catch (StatusException ex)
                {
                    Trace.WriteLine("OpenNI StatusException: " + ex.ToString());
                    isInit = false;
                    Thread.Sleep(1000);
                }
                catch (GeneralException ex)
                {
                    Trace.WriteLine("GeneralException: " + ex.ToString());
                    isInit = false;
                    IsGeneratorThreadRunning = false;
                    return;
                }
            }

            this.joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>();

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

            this.userGenerator.NewUser += new EventHandler<NewUserEventArgs>(userGenerator_NewUser);
            this.userGenerator.LostUser += new EventHandler<UserLostEventArgs>(userGenerator_LostUser);
            this.poseDetectionCapability.PoseDetected += new EventHandler<PoseDetectedEventArgs>(poseDetectionCapability_PoseDetected);
            this.skeletonCapability.CalibrationEnd += new EventHandler<CalibrationEndEventArgs>(skeletonCapability_CalibrationEnd);

            this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.Upper);
            this.userGenerator.StartGenerating();

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

            depthGenerator.NewDataAvailable += new EventHandler(depthGenerator_NewDataAvailable);

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

            depthGenerator.StartGenerating();
        }
Example #32
0
        private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType?type)
        {
            lock (this)
            {
                if (!this.allNodes.ContainsKey(nodeHandle))
                {
                    if (type == null)
                    {
                        IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle);
                        type = SafeNativeMethods.xnNodeInfoGetDescription(pNodeInfo).Type;
                    }

                    ProductionNode node;

                    switch (type)
                    {
                    case NodeType.Device:
                        node = new Device(this, nodeHandle, true);
                        break;

                    case NodeType.Depth:
                        node = new DepthGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.Image:
                        node = new ImageGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.Audio:
                        node = new AudioGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.IR:
                        node = new IRGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.User:
                        node = new UserGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.Recorder:
                        node = new Recorder(this, nodeHandle, true);
                        break;

                    case NodeType.Player:
                        node = new Player(this, nodeHandle, true);
                        break;

                    case NodeType.Gesture:
                        node = new GestureGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.Scene:
                        node = new SceneAnalyzer(this, nodeHandle, true);
                        break;

                    case NodeType.Hands:
                        node = new HandsGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.Codec:
                        node = new Codec(this, nodeHandle, true);
                        break;

                    case NodeType.ProductionNode:
                        node = new ProductionNode(this, nodeHandle, true);
                        break;

                    case NodeType.Generator:
                        node = new Generator(this, nodeHandle, true);
                        break;

                    case NodeType.MapGenerator:
                        node = new MapGenerator(this, nodeHandle, true);
                        break;

                    case NodeType.ScriptNode:
                        node = new ScriptNode(this, nodeHandle, true);
                        break;

                    default:
                        throw new NotImplementedException("C# wrapper: Unknown generator type!");
                    }
                    this.allNodes[nodeHandle] = node;
                }

                return(this.allNodes[nodeHandle]);
            }             // lock
        }