Beispiel #1
0
 private void DisplayGeoNodes(PXCMGesture gesture)
 {
     if (form.GetGeoNodeState())
     {
         gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, nodes[0]);
         gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_SECONDARY, nodes[1]);
         //gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_ELBOW_PRIMARY, out nodes[0][nodes.Length-1]);
         //gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_ELBOW_SECONDARY, out nodes[1][nodes.Length-1]);
         form.DisplayGeoNodes(nodes);
     }
     else
     {
         form.DisplayGeoNodes(null);
     }
 }
        public override void OnImage(PXCMImage image)
        {
            #region 攝影機影像顯示
            //Debug.WriteLine("收到影像,格式 : " + image.imageInfo.format);
            PXCMSession session = QuerySession();
            Bitmap      bitmapimage;
            image.QueryBitmap(session, out bitmapimage);
            BitmapSource source = ToWpfBitmap(bitmapimage);
            if (image.imageInfo.format == PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH)
            {
                MainWindow.mainwin.ProcessDepthImage(source);
            }
            else if (image.imageInfo.format == PXCMImage.ColorFormat.COLOR_FORMAT_RGB24)
            {
                MainWindow.mainwin.ProcessColorImage(source);
            }
            image.Dispose();
            #endregion

            PXCMGesture gesture = QueryGesture();
            if (gesture != null)
            {
                PXCMGesture.GeoNode node;
                //PXCMGesture.GeoNode[] nodes = new PXCMGesture.GeoNode[11];
                gesture.QueryNodeData(0, NeedNode(), out node);
                //gesture.QueryNodeData(0, NeedNodes(), nodes);
                ProcessNode(node);
                //ProcessNodes(nodes);
            }
        }
Beispiel #3
0
        public override bool OnNewFrame()
        {
            PXCMGesture gesture = QueryGesture();

            PXCMGesture.GeoNode ndata;
            pxcmStatus          sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata);
            uint sx;
            uint sy;

            QueryImageSize(PXCMImage.ImageType.IMAGE_TYPE_DEPTH, out sx, out sy);
            xx = sx;
            yy = sy;
            if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("HAND_MIDDLE:" + ndata.positionImage.x.ToString() + "," + ndata.positionImage.y.ToString() + " Openess:" + ndata.openness.ToString());
            }

            float x = ndata.positionImage.x;
            float y = ndata.positionImage.y;

            z = ndata.positionWorld.z;

            position = new Vector2(MyGraphics.screenRect.Width / 2 - (x / xx - 0.5f) * MyGraphics.screenRect.Width * 1.5f,
                                   MyGraphics.screenRect.Height / 2 + (y / yy - 0.5f) * MyGraphics.screenRect.Height * 1.5f);
            opennes   = ndata.openness;
            openState = ndata.opennessState;
            //return (++nframes < 50000);
            return(start);
        }
Beispiel #4
0
        public override bool OnNewFrame()
        {
            PXCMGesture gesture = QueryGesture();

            PXCMGesture.GeoNode ndata;
            pxcmStatus          sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata);

            if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                _lastDirection = _DetectGesture(ndata.positionImage.x, ndata.positionImage.y);
                if (_lastDirection != MovingDirection.Undefined)
                {
                    _sender.UpdateGesture(_lastDirection);
                }

                //Console.WriteLine("node HAND_MIDDLE ({0},{1})", ndata.positionImage.x, ndata.positionImage.y);
            }

            return(++_nframes < 50000);
        }
Beispiel #5
0
        public override bool AcquireFrame(bool wait)
        {
            PXCMGesture gesture = QueryGesture();

            PXCMGesture.GeoNode ndata;
            pxcmStatus          sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata);

            if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                if ((ndata.positionImage.x >= 0) && (ndata.positionImage.x <= 320))
                {
                    geoNodeParams.nodeX = ndata.positionImage.x;
                }
                if ((ndata.positionImage.y >= 0) && (ndata.positionImage.y <= 240))
                {
                    geoNodeParams.nodeY = ndata.positionImage.y;
                }
                geoNodeParams.opennes = ndata.openness;
            }
            return(base.AcquireFrame(wait));
        }
 private void DisplayGeoNodes(PXCMGesture gesture)
 {
     if (form.GetGeoNodeState())
     {
         gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, nodes[0]);
         gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_SECONDARY, nodes[1]);
         gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_ELBOW_PRIMARY, out nodes[0][nodes.Length-1]);
         gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_ELBOW_SECONDARY, out nodes[1][nodes.Length-1]);
         form.DisplayGeoNodes(nodes);
     }
     else
     {
         form.DisplayGeoNodes(null);
     }
 }
Beispiel #7
0
        public void Start()
        {
            //create session
            PXCMSession session;
            pxcmStatus  status = PXCMSession.CreateInstance(out session);

            if (IsError(status))
            {
                OnError(CamEvent.FAILED_TO_CREATE_SDK_SESSION);
                return;
            }

            //create gesture-module
            PXCMBase gestureBase;

            status = session.CreateImpl(PXCMGesture.CUID, out gestureBase);
            if (IsError(status))
            {
                OnError(CamEvent.FAILED_TO_LOAD_GESTURE_RECOGNITION);
                session.Dispose();
                return;
            }

            //create gesture-profile
            PXCMGesture gesture = (PXCMGesture)gestureBase;

            PXCMGesture.ProfileInfo profileInfo;
            status = gesture.QueryProfile(0, out profileInfo);
            profileInfo.activationDistance = 70;

            //setup gesture-capture
            UtilMCapture capture = new UtilMCapture(session);

            status = capture.LocateStreams(ref profileInfo.inputs);
            if (IsError(status))
            {
                OnError(CamEvent.FAILED_TO_LOCATE_CAPTURE_MODULE);
                gesture.Dispose();
                capture.Dispose();
                session.Dispose();
                return;
            }

            status = gesture.SetProfile(ref profileInfo);
            status = gesture.SubscribeAlert(this.OnAlertHandler);
            status = gesture.SubscribeGesture(100, this.OnGesureHandler);

            //start capture of frames
            bool device_lost = false;

            PXCMImage[] images = new PXCMImage[PXCMCapture.VideoStream.STREAM_LIMIT];
            PXCMScheduler.SyncPoint[] syncPoints = new PXCMScheduler.SyncPoint[2];

            while (_tracking)
            {
                status = capture.ReadStreamAsync(images, out syncPoints[0]);
                if (IsError(status))
                {
                    if (status == pxcmStatus.PXCM_STATUS_DEVICE_LOST)
                    {
                        if (!device_lost)
                        {
                            OnError(CamEvent.DEVICE_DISCONNECTED);
                        }
                        device_lost = true;
                        continue;
                    }
                    OnError(CamEvent.DEVICE_FAILED);
                    break;
                }
                if (device_lost)
                {
                    OnNotify(CamEvent.DEVICE_RECONNECTED);
                    device_lost = false;
                }

                status = gesture.ProcessImageAsync(images, out syncPoints[1]);
                if (IsError(status))
                {
                    break;
                }

                PXCMScheduler.SyncPoint.SynchronizeEx(syncPoints);
                if (syncPoints[0].Synchronize(0) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    PXCMGesture.GeoNode data;
                    status = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out data);
                    if (!IsError(status))
                    {
                        if (ShapeHelper.IsPointInsideRect(data.positionImage.x, data.positionImage.y, Constants.FoVWindow))
                        {
                            //adjust the point to field-of-view window
                            Point cameraPoint = new Point(data.positionImage.x - Constants.FoVWindow.X, data.positionImage.y - Constants.FoVWindow.Y);
                            //cameraPoint = ShapeHelper.RotatePoint(cameraPoint, Constants.FoVCenter, Constants.RotationAngle);
                            OnMovement(cameraPoint);

                            if (data.opennessState != _previousOpenness)
                            {
                                OnOpenClose(data.opennessState, data.openness);
                                _previousOpenness = data.opennessState;
                            }
                        }
                        else
                        {
                            OnNotify(CamEvent.HOVERING_OUTSIDE);
                        }
                    }
                }

                foreach (PXCMScheduler.SyncPoint p in syncPoints)
                {
                    if (p != null)
                    {
                        p.Dispose();
                    }
                }
                foreach (PXCMImage img in images)
                {
                    if (img != null)
                    {
                        img.Dispose();
                    }
                }
            }

            if (gesture != null)
            {
                gesture.Dispose();
            }
            if (capture != null)
            {
                capture.Dispose();
            }
            if (session != null)
            {
                session.Dispose();
            }
        }
        public override bool OnNewFrame()
        {
            float       x, y;
            PXCMGesture gesture = QueryGesture();

            PXCMGesture.GeoNode ndata;
            pxcmStatus          sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata);

            if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("node HAND_MIDDLE ({0},{1},{2},{3},{4})", ndata.positionImage.x, ndata.positionImage.y, ndata.confidence, ndata.openness, ndata.opennessState);
                x = ndata.positionImage.x;
                if (x > 260)
                {
                    x = 260;
                }
                if (x < 40)
                {
                    x = 40;
                }
                x = x - 40;
                //////////////////////////////////////////////////
                x = 220 - x;
                if (ndata.opennessState == PXCMGesture.GeoNode.Openness.LABEL_CLOSE)
                {
                    Game.Update1((float)(x - 110) / 110, 1, 1);
                }

                //

                /*
                 * }
                 * sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata);
                 * if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                 * {
                 * Console.WriteLine("node HAND_MIDDLE ({0},{1},{2},{3},{4})", ndata.positionImage.x, ndata.positionImage.y, ndata.confidence, ndata.openness, ndata.opennessState);
                 * //*/
                int state;
                if (ndata.opennessState == PXCMGesture.GeoNode.Openness.LABEL_OPEN)
                {
                    state = 0;
                }
                else
                {
                    state = 1;
                }

                //  Game.Update((float)Program.game.Width * (160 - ndata.positionImage.x) / 160, (float)Program.game.Height * (ndata.positionImage.y - 100) / 100, state, 0);

                x = ndata.positionImage.x;
                y = ndata.positionImage.y;
                ////////////////////////////////////////////////
                ///////////////Smoothing of coordinate nad removing data outside less presice rang//////////////
                if (x > 260)
                {
                    x = 260;
                }
                if (x < 40)
                {
                    x = 40;
                }
                if (y > 200)
                {
                    y = 200;
                }
                if (y < 20)
                {
                    y = 20;
                }

                x = x - 40;
                y = y - 20;
                //////////////////////////////////////////////////
                x = 220 - x;
                if (Game.gd.Gamestate != 0)
                {
                    Game.Update(Program.game.Width * x / 220, Program.game.Height * y / 180, state, 0);
                }
            }
            PXCMImage img = QueryImage(PXCMImage.ImageType.IMAGE_TYPE_COLOR);

            if (img != null)
            {
                img.QueryBitmap(QuerySession(), out bmp);
            }
            if (bmp != null)
            {
                Main.camerapre = GetTexture(Main.GrDev, bmp);
            }
            bmp = null;

            img = QueryImage(PXCMImage.ImageType.IMAGE_TYPE_DEPTH);
            if (img != null)
            {
                img.QueryBitmap(QuerySession(), out bmp);
            }
            if (bmp != null)
            {
                Main.camerapre1 = GetTexture(Main.GrDev, bmp);
            }

            bmp = null;

            img = QueryImage(PXCMImage.ImageType.IMAGE_TYPE_MASK);
            if (img != null)
            {
                img.QueryBitmap(QuerySession(), out bmp);
            }
            if (bmp != null)
            {
                Main.camerapre2 = GetTexture(Main.GrDev, bmp);
            }



            return(loop);
        }