void Start () 
	{

		// Below is only for Kinect 1
        settingsManager = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager;
	
		if (settingsManager == null || !settingsManager.UserGenrator.Valid || settingsManager.CurrentContext.Depth == null)
        {
            Kinect1Update = false;
            return;
        }

        depthGenerator = new OpenNI.DepthGenerator(settingsManager.CurrentContext.BasicContext);        

        OpenNI.MapOutputMode mapOutputMode = settingsManager.CurrentContext.Depth.MapOutputMode;
        width = mapOutputMode.XRes / factor;
        height = mapOutputMode.YRes / factor;
        texture = new Texture2D(width, height);

        depthMap = new short[(int)(mapOutputMode.XRes * mapOutputMode.YRes)];
        depthHistogramMap = new float[settingsManager.CurrentContext.Depth.DeviceMaxDepth];

        NIOpenNICheckVersion.Instance.ValidatePrerequisite();
        metaData = new OpenNI.DepthMetaData();

        mapPixels = new Color[width * height];
	}
        // 初期化
        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);

              // レコーダーの作成と記録対象の追加
              recoder = new OpenNI.Recorder(context);
              recoder.SetDestination(RecordMedium.File, RECORD_PATH);
              recoder.AddNodeToRecording(image);
              recoder.AddNodeToRecording(depth);
              recoder.Record();
        }
Beispiel #3
0
 // 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 NIContext()
 {
     m_context = null;
     m_depth = null;
     m_scriptNode = null;
     m_recordingPlayer = null;
 }
        // 初期化
        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("ユーザー検出をサポートしていません");
              }
        }
        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();
        }
Beispiel #6
0
		private static IntPtr CreateBasedOn(DepthGenerator basedOn, string name)
		{
			IntPtr handle;
			int status = SafeNativeMethods.xnCreateMockNodeBasedOn(basedOn.Context.InternalObject, 
				basedOn.InternalObject, name, out handle);
			WrapperUtils.ThrowOnError(status);
			return handle;
		}
        public DebugController(Context context, KinectUser user, IRenderEngine renderEngine)
        {
            _DepthGenerator = new DepthGenerator(context);

            this.User = user;
            this.RenderEngine = renderEngine;

            _DebugLines = new Dictionary<SkeletonJoint, ILine>();
        }
        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 );
            }
        }
        public DepthVideoController(Context kinectContext, ITextureController textureController)
        {
            this.Context = kinectContext;
            this.TextureController = textureController;

            _DepthGenerator = Context.FindExistingNode(NodeType.Depth) as DepthGenerator;

            if (_DepthGenerator == null)
            {
                throw new Exception("Viewer must have a depth node!");
            }

            _Histogram = new int[_DepthGenerator.DeviceMaxDepth];
            _Bitmap = new Bitmap((int)_DepthGenerator.MapOutputMode.XRes, (int)_DepthGenerator.MapOutputMode.YRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/);
        }
        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");
        }
        // 初期化
        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);
              }
        }
        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.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 = false;
                depth = context.FindExistingNode( NodeType.Depth ) as DepthGenerator;

                // 画像更新のためのスレッドを作成
                shouldRun = true;
                readerThread = new Thread( new ThreadStart( () =>
                {
                    while ( shouldRun ) {
                        context.WaitAndUpdateAll();
                        DepthMetaData depthMD = depth.GetMetaData();

                        // ImageMetaDataをBitmapSourceに変換する(unsafeにしなくてもOK!!)
                        this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () =>
                        {
                            Int16[] depthArray = new Int16[depthMD.XRes * depthMD.YRes];
                            Marshal.Copy( depthMD.DepthMapPtr, depthArray, 0, depthArray.Length );
                            for ( int i = 0; i < depthArray.Length; i++ ) {
                                depthArray[i] = (Int16)(0xffff - (0xffff * depthArray[i] / depth.DeviceMaxDepth));
                            }

                            image1.Source = BitmapSource.Create( depthMD.XRes, depthMD.YRes,
                                96, 96, PixelFormats.Gray16, null, depthArray,
                                depthMD.XRes * depthMD.BytesPerPixel );
                        } ) );
                    }
                } ) );
                readerThread.Start();
            }
            catch ( Exception ex ) {
                MessageBox.Show( ex.Message );
            }
        }
        //Starts up necessary files to take data
        //Must run before TakeData()
        Kinect()
        {
            //Sets locations of XML File
            string SAMPLE_XML_FILE = @"..\\..\\..\\SamplesConfig.xml";

            //Declares object of ScriptNode and defines context
            ScriptNode scriptNode;
            context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode);

            //Declares the depth generator
            depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            //If the depth generator does not exist returns error messag
            if (depth == null)
            {
                Console.WriteLine("Sample must have a depth generator!");
                Console.ReadLine();
                return;
            }
            //Declares necessary variables and classes to take depth
            //DepthGenerator depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            mapMode = depth.MapOutputMode;
            depthMD = new DepthMetaData();
        }
        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();
        }
    // private ctor for singleton
    private OpenNIContext()
    {
        this.context = new Context();
        if (null == context)
        {
            return;
        }

        if (oniFile != "") {
            context.OpenFileRecording(oniFile);
        }

        // NITE license from OpenNI.org
        License ll = new License();
        ll.Key = "0KOIk2JeIBYClPWVnMoRKn5cdY4=";
        ll.Vendor = "PrimeSense";
        context.AddLicense(ll);

        this.Depth = openNode(NodeType.Depth) as DepthGenerator;
        this.mirror = this.Depth.MirrorCapability;
        if (oniFile == "") {
            this.Mirror = true;
        }
    }
Beispiel #18
0
    public void Awake()
    {
        Debug.Log("Initing OpenNI" + (LoadFromXML ? "(" + XMLFilename + ")" : ""));
        try {
            this.context = LoadFromXML ? new Context(XMLFilename) : new Context();
        }
        catch (Exception ex) {
            Debug.LogError("Error opening OpenNI context: " + ex.Message);
            return;
        }

        // add license manually if not loading from XML
        if (!LoadFromXML) {
            License ll = new License();
            ll.Key = LicenseKey;
            ll.Vendor = LicenseVendor;
            context.AddLicense(ll);
        }

        if (LoadFromRecording)
        {
            context.OpenFileRecordingEx(RecordingFilename);
            Player player = openNode(NodeType.Player) as Player;
            player.PlaybackSpeed = 0.0;
            StartCoroutine(ReadNextFrameFromRecording(player));
        }

        this.Depth = openNode(NodeType.Depth) as DepthGenerator;
        this.mirrorCap = this.Depth.MirrorCapability;
        if (!LoadFromRecording) {
            this.mirrorCap.SetMirror(Mirror);
            mirrorState = Mirror;
        }
    }
Beispiel #19
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();
 }
        // 初期化
        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);

              // ジェスチャージェネレータの作成
              gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
              if (depth == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // ジェスチャーの作成と登録
              gestures = gesture.EnumerateAllGestures();
              gesture.AddGesture(gestures[gestureIndex]);
              string[] activeGestures = gesture.GetAllActiveGestures();

              // ジェスチャーの機能確認
              foreach (string name in gestures) {
            Trace.WriteLine(name + ":" +
              "Available:" + gesture.IsGestureAvailable(name) +
              " ProgressSupported:" + gesture.IsGestureProgressSupported(name));
              }

              // ジェスチャー用のコールバックを登録
              gesture.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(gesture_GestureRecognized);
              gesture.GestureProgress += new EventHandler<GestureProgressEventArgs>(gesture_GestureProgress);
              gesture.GestureChanged += new EventHandler(gesture_GestureChanged);

              // ジェスチャーの検出開始
              context.StartGeneratingAll();
        }
Beispiel #21
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>
 /// Initializes the depth variable based on the config file
 /// </summary>
 private void InitializeDepth()
 {
     this.depth = Context.FindExistingNode(NodeType.Depth) as DepthGenerator;
     if (this.depth == null)
     {
         throw new OpenNI.GeneralException("Viewer must have a depth node!");
     }
 }
        /// <summary>
        /// Converts a JointDictionary with 3D data to the corresponding one
        /// with 2D data. Note that the Z-Coordinate is left unchanged, though
        /// it has no meaning in the resulting 2D space and can be seen as 0.
        /// </summary>
        public JointDictionary Convert3Dto2D(JointDictionary source, DepthGenerator generator)
        {
            if (!source.Is3DData)
                return new JointDictionary(source);
            else
            {
                JointDictionary ret = new JointDictionary(false);

                foreach (SkeletonJoint joint in source.Keys)
                {
                    SkeletonJointPosition pos = new SkeletonJointPosition();
                    pos.Confidence = source[joint].Confidence;
                    pos.Position = generator.ConvertRealWorldToProjective(source[joint].Position);
                    ret.Add(joint, pos);
                }
                return ret;
            }
        }
        // 初期化
        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);

              // カメラ画像の
              //   ミラー状態が変更されたことを通知するコールバックを登録
              //   ミラー状態の取得
              OpenNI.MirrorCapability imageMirror = image.MirrorCapability;
              imageMirror.MirrorChangedEvent += new EventHandler(Form1_MirrorChangedEvent);
              mirrorState.Add(image.ToString(), imageMirror.IsMirrored());

              // デプスの
              //   ミラー状態が変更されたことを通知するコールバックを登録
              //   ミラー状態の取得
              OpenNI.MirrorCapability depthMirror = depth.MirrorCapability;
              depthMirror.MirrorChangedEvent += new EventHandler(Form1_MirrorChangedEvent);
              mirrorState.Add(depth.ToString(), depthMirror.IsMirrored());

              // ヒストグラムバッファの作成
              histogram = new int[depth.DeviceMaxDepth];
        }
    // Use this for initialization
    void Start()
    {
        player=GameObject.Find("Player");
        Debug.Log ("---------"+player.transform.localPosition);
        camaraMenu=GameObject.Find(CAMARA_MENU).camera;
        camaraPlayer=GameObject.Find(CAMARA_PLAYER).camera;
        seleccionarCamara(CAMARA_PLAYER);
        playMemory="1";
        audio.clip = clip1;
        audio.Play();
        puntoInicial=GameObject.Find("puntoInicial");
        puntoFinal=GameObject.Find("puntoFinal");
        determinaEspacioUnity();
        determinaCentro();
        transform.position=new Vector3(xMedia,yMedia,zMedia);
        //
        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");
        }
        this.hands=this.context.FindExistingNode(NodeType.Hands) as HandsGenerator;
        if(this.hands==null){
            throw new Exception("Nodo de Manos no encontrado");
        }
        this.gesture=this.context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
        if(this.gesture==null){
            throw new Exception("Nodo de Gestos no encontrado");
        }

        fadeCountCircle();
        //handdlers
        this.hands.HandCreate+=hands_HandCreate;
        this.hands.HandUpdate+=hands_HandUpdate;
        this.hands.HandDestroy+=hands_HandDestroy;

        this.gesture.AddGesture(WAVE);
        this.gesture.AddGesture(CLICK);
        this.gesture.GestureRecognized+=gesture_GestureRecognized;
        this.gesture.StartGenerating();
        //iniciaPuntos
        iniciaPuntos();
    }
        public bool initializeSensor(String xmlPath)
        {
            try

            {

                pbuffer =new  Point[6];
                openpalm = new OpenPalm();
                scrHeight = SystemInformation.PrimaryMonitorSize.Height;
                scrWidth = SystemInformation.PrimaryMonitorSize.Width;

                mouseSpeed = SystemInformation.MouseSpeed * 0.15;
                pointCollections = new PointCollection();
                /*OpenNI objects - Context, DepthGenerator and DepthMetaData are initialized here*/
                cxt = new Context(xmlPath);
                depthGen = cxt.FindExistingNode(NodeType.Depth) as DepthGenerator;
                gsHandsGenerator = cxt.FindExistingNode(NodeType.Hands) as HandsGenerator;
                gsHandsGenerator.SetSmoothing(0.1f);
                depthMeta = new DepthMetaData();
                if (depthGen == null) return false;

                xRes = depthGen.MapOutputMode.XRes;
                yRes = depthGen.MapOutputMode.YRes;

                /*NITE objects - Session manager, PointControl is initialized here*/
                sessionMgr = new SessionManager(cxt, "Wave", "RaiseHand");

                pointCtrl = new PointControl("PointTracker");
                steadydetector = new SteadyDetector();
                flrouter = new FlowRouter();
                brodcaster = new Broadcaster();
                steadydetector.DetectionDuration = 200;

                steadydetector.Steady+=new EventHandler<SteadyEventArgs>(steadydetector_Steady);
                steadydetector.NotSteady+=new EventHandler<SteadyEventArgs>(steadydetector_NotSteady);
              /*  pointCtrl.PrimaryPointCreate += new EventHandler<HandFocusEventArgs>(pointCtrl_PrimaryPointCreate);
                pointCtrl.PrimaryPointUpdate += new EventHandler<HandEventArgs>(pointCtrl_PrimaryPointUpdate);
                pointCtrl.PrimaryPointDestroy += new EventHandler<IdEventArgs>(pointCtrl_PrimaryPointDestroy);*/
                pointCtrl.PointCreate += new EventHandler<HandEventArgs>(pointCtrl_PointCreate);
                pointCtrl.PointUpdate += new EventHandler<HandEventArgs>(pointCtrl_PointUpdate);
                pointCtrl.PointDestroy += new EventHandler<IdEventArgs>(pointCtrl_PointDestroy);

                sessionMgr.AddListener(steadydetector);
               sessionMgr.AddListener(pointCtrl);  //make the session manager listen to the point control

                isActive = false;                   //set lifecycle flag to false
                            //fill the handpoint coordinates with invalid values
                         //initialize the clipping matrix

                HandPointBuffer = new ArrayList();

            }
            catch (Exception e) { return false; }

            return true;
        }
Beispiel #27
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;
    }
Beispiel #28
0
    void Start()
    {
        //Debug.Log("START");
        determinaCentro();

        //Debug.Log("X "+xMedia+" Y "+yMedia+" Z "+zMedia);
        transform.position=new Vector3(xMedia,yMedia,zMedia);

        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");
        }
        this.hands=this.context.FindExistingNode(NodeType.Hands) as HandsGenerator;
        if(this.hands==null){
            throw new Exception("Nodo de Manos no encontrado");
        }
        this.gesture=this.context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
        if(this.gesture==null){
            throw new Exception("Nodo de Gestos no encontrado");
        }
        //handdlers
        this.hands.HandCreate+=hands_HandCreate;
        this.hands.HandUpdate+=hands_HandUpdate;
        this.hands.HandDestroy+=hands_HandDestroy;

        this.gesture.AddGesture(WAVE);
        this.gesture.GestureRecognized+=gesture_GestureRecognized;
        this.gesture.StartGenerating();
    }
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
              context = new Context();
              // OpenFileRecordingExを使うように促されるが、使用するとアクセスバイオレーションになる
              context.OpenFileRecording(RECORD_PATH);

              // プレーヤーの作成
              player = context.FindExistingNode(NodeType.Player) as OpenNI.Player;
              if (player == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // 終端に達したら通知するコールバックを登録する
              player.EndOfFileReached += new EventHandler(player_EndOfFileReached);

              // イメージジェネレータの作成
              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);
              }

              // ヒストグラムバッファの作成
              histogram = new int[depth.DeviceMaxDepth];
        }
        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");
        }