// Use this for initialization
    void Start()
    {
        // create hand & gesture generators, if we dont have them yet
        OpenNIContext.OpenNode(NodeType.Hands);
        OpenNIContext.OpenNode(NodeType.Gesture);

        // init session manager
        sessionManager = new SessionManager(OpenNIContext.Context, "Click", "RaiseHand");
        sessionManager.SessionStart += new System.EventHandler<PositionEventArgs>(sessionManager_SessionStart);
        sessionManager.SessionEnd += new System.EventHandler(sessionManager_SessionEnd);

        sessionManager.AddListener(broadcaster);
    }
        private void CreateAndRun()
        {
            m_context        = new Context(@"data\openNI.xml");
            m_imageGenerator = new ImageGenerator(m_context);
            m_depthGenerator = new DepthGenerator(m_context);

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

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

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

            PointControl pointControl = new PointControl();

            pointControl.PrimaryPointCreate  += PointControl_PrimaryPointCreate;
            pointControl.PrimaryPointDestroy += PointControl_PrimaryPointDestroy;
            pointControl.PrimaryPointUpdate  += PointControl_PrimaryPointUpdate;

            SwipeDetector swipeDetector = new SwipeDetector();

            swipeDetector.UseSteady   = true;
            swipeDetector.SwipeLeft  += SwipeDetector_SwipeLeft;
            swipeDetector.SwipeRight += SwipeDetector_SwipeRight;

            PointDenoiser denoiser = new PointDenoiser();

            denoiser.AddListener(pointControl);
            denoiser.AddListener(swipeDetector);
            sessionManager.AddListener(denoiser);

            while (m_running)
            {
                m_context.WaitAndUpdateAll();
                sessionManager.Update(m_context);
            }
        }
        // 初期化
        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);
            }

            // NITEのためのセッションマネージャを作成
            sessionManager = new SessionManager(context, "Wave,Click", "RaiseHand");

            // セッションの開始と終了を通知するコールバックを登録する
            sessionManager.SessionStart         += new EventHandler <PositionEventArgs>(sessionManager_SessionStart);
            sessionManager.SessionEnd           += new EventHandler(sessionManager_SessionEnd);
            sessionManager.SessionFocusProgress += new EventHandler <SessionProgressEventArgs>(sessionManager_SessionFocusProgress);

            // Wave(左右運動の検出器)
            swipeDetector = new NITE.SwipeDetector();
            swipeDetector.GeneralSwipe += new EventHandler <DirectionVelocityAngleEventArgs>(swipeDetector_GeneralSwipe);
            swipeDetector.SwipeUp      += new EventHandler <VelocityAngleEventArgs>(swipeDetector_SwipeUp);
            swipeDetector.SwipeDown    += new EventHandler <VelocityAngleEventArgs>(swipeDetector_SwipeDown);
            swipeDetector.SwipeRight   += new EventHandler <VelocityAngleEventArgs>(swipeDetector_SwipeRight);
            swipeDetector.SwipeLeft    += new EventHandler <VelocityAngleEventArgs>(swipeDetector_SwipeLeft);

            // リスナーに追加する
            sessionManager.AddListener(swipeDetector);

            // ジェネレータの動作を開始する
            context.StartGeneratingAll();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            InitializeComponents();

            categories = new List <Category> ();

            // Model that download the information used to build
            // Cast Media Information to be sent to Cast Device.
            mediaListModel = new MediaListModel();
            mediaListModel.MediaListFetched     += MediaListModel_MediaListFetched;
            mediaListModel.FetchMediaListFailed += MediaListModel_FetchMediaListFailed;

            // Combines the steps of connecting to a device,
            // launching (or joining), connecting to a receiver
            // application, and initializing a media control channel
            // if appropriate.
            sessionManager = CastContext.SharedInstance.SessionManager;
            sessionManager.AddListener(this);

            imageFetcher = new ImageFetcher();
        }
        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;
        }
Exemple #6
0
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);



            if (e.OldElement != null || Element == null)
            {
                return;
            }

            try
            {
                SetupChromecastThings();
                SetupUserInterface();
                StartVideoPlayback();
                currentPage = Element;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"\t\t\tERROR: {ex.Message}");
            }

            void StartVideoPlayback()
            {
                var hasConnection = sessionManager.HasConnectedSession;

                if (hasConnection)
                {
                    mLocation = PlaybackLocation.REMOTE;
                    SwitchToRemotePlayback();
                    ClosePage();
                }

                if (mLocation == PlaybackLocation.LOCAL)
                {
                    avp.Play();
                }
            }

            void SetupUserInterface()
            {
                url          = NSUrl.FromString(mediaInfo.SourceURL);
                avp          = new AVPlayer(url);
                avpvc        = new AVPlayerViewController();
                avpvc.Player = avp;
                AddChildViewController(avpvc);
                avpvc.View.Frame            = new CGRect(0, 100, 375, 300);
                avpvc.ShowsPlaybackControls = true;
                View.AddSubview(avpvc.View);

                var castButton = new UICastButton(new CGRect(50, 20, 24, 24));

                View.AddSubview(castButton);
            }

            void SetupChromecastThings()
            {
                //setup Cast session manager
                sessionManager             = CastContext.SharedInstance.SessionManager;
                xamaSessionManagerListener = new XamSessionManagerListener(this);
                sessionManager.AddListener(xamaSessionManagerListener);

                //castMediaController
                castMediaController          = new UIMediaController();
                castMediaController.Delegate = new XamMediaControllerDelegate();
            }
        }
        /// <summary>
        /// Setup builds an XN Context, Session Manager and all the detectors. 
        /// It also adds the callbacks for the SessionManager and adds the listeners on the Broadcaster. 
        /// </summary>
        private void Setup()
        {
            //build the context
            Context = new Context(CONFIG);
            //build session manager
            SeshManager = new SessionManager(Context,"RaiseHand","RaiseHand");
            SeshManager.SetQuickRefocusTimeout(15000);

            //build the detectors
            Pushy = new PushDetector();
            Swipy = new SwipeDetector();
            //setup all the callbacks
            SetupCallbacks();
            SeshManager.SessionStart += SessionStarted;
            //add the flow router to the session
            SeshManager.AddListener(Pushy);
            SeshManager.AddListener(Swipy);
        }
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
              context = new Context(CONFIG_XML_PATH);

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

              // NITEのためのセッションマネージャを作成
              sessionManager = new SessionManager(context, "Wave,Click", "RaiseHand");

              // セッションの開始と終了を通知するコールバックを登録する
              sessionManager.SessionStart += new EventHandler<PositionEventArgs>(sessionManager_SessionStart);
              sessionManager.SessionEnd += new EventHandler(sessionManager_SessionEnd);
              sessionManager.SessionFocusProgress += new EventHandler<SessionProgressEventArgs>(sessionManager_SessionFocusProgress);

              // Push(前後運動の検出器)
              pushDetector = new NITE.PushDetector();
              pushDetector.Push += new EventHandler<VelocityAngleEventArgs>(pushDetector_Push);

              // リスナーに追加する
              sessionManager.AddListener(pushDetector);

              // ジェネレータの動作を開始する
              context.StartGeneratingAll();
        }
        // 初期化
        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);
              }

              // NITEのためのセッションマネージャを作成
              sessionManager = new SessionManager(context,
                              "Wave,Click", "RaiseHand");

              // セッションの開始と終了を通知するコールバックを登録する
              sessionManager.SessionStart += new EventHandler<PositionEventArgs>(sessionManager_SessionStart);
              sessionManager.SessionEnd += new EventHandler(sessionManager_SessionEnd);
              sessionManager.SessionFocusProgress += new EventHandler<SessionProgressEventArgs>(sessionManager_SessionFocusProgress);

              // Wave(左右運動の検出器)
              steadyDetector = new NITE.SteadyDetector();
              steadyDetector.Steady += new EventHandler<SteadyEventArgs>(steadyDetector_Steady);

              // リスナーに追加する
              sessionManager.AddListener(steadyDetector);

              // ジェネレータの動作を開始する
              context.StartGeneratingAll();
        }
Exemple #10
0
    void Start()
    {
        InitializeCharacter ();
        context = new Context (XML_SETUP_FILE);
        sessionManager = new SessionManager(context, "Wave", "RaiseHand");
        depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
        handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator;

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

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

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

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

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

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

        //swipeDetector.SwipeLeft += HandleSwipeDetectorSwipeLeft;

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

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

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

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

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

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

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

        sessionManager.AddListener(pointDenoiser);

        MapOutputMode mapMode = depthGenerator.MapOutputMode;

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

        this.shouldRun = true;

        if (NiteInitializingEvent != null) //notify others that we're done initializing
            NiteInitializingEvent(this, EventArgs.Empty);
    }
        private void CreateAndRun()
        {
            m_context = new Context(@"data\openNI.xml");
            m_imageGenerator = new ImageGenerator(m_context);
            m_depthGenerator = new DepthGenerator(m_context);

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

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

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

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

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

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

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