예제 #1
0
 public Point3D[] ConvertProjectiveToRealWorld(Point3D[] projectivePoints)
 {
     Point3D[] realWorld = new Point3D[projectivePoints.Length];
     UInt32 status = OpenNIImporter.xnConvertProjectiveToRealWorld(this.InternalObject, (uint)projectivePoints.Length, projectivePoints, realWorld);
     WrapperUtils.CheckStatus(status);
     return realWorld;
 }
예제 #2
0
 public Point3D[] ConvertRealWorldToProjective(Point3D[] realWorldPoints)
 {
     Point3D[] projective = new Point3D[realWorldPoints.Length];
     UInt32 status = OpenNIImporter.xnConvertRealWorldToProjective(this.InternalObject, (uint)realWorldPoints.Length, realWorldPoints, projective);
     WrapperUtils.CheckStatus(status);
     return projective;
 }
예제 #3
0
        public Point3D ConvertProjectiveToRealWorld(Point3D projectivePoint)
        {
            Point3D[] projectivePoints = new Point3D[1];
            projectivePoints[0] = projectivePoint;

            return ConvertProjectiveToRealWorld(projectivePoints)[0];
        }
예제 #4
0
        public Point3D ConvertRealWorldToProjective(Point3D realWorldPoint)
        {
            Point3D[] realWorldPoints = new Point3D[1];
            realWorldPoints[0] = realWorldPoint;

            return ConvertRealWorldToProjective(realWorldPoints)[0];
        }
예제 #5
0
파일: Pose.cs 프로젝트: cignoir/KinecTh
 public Pose(Dictionary<SkeletonJoint, SkeletonJointPosition> skeleton)
 {
     this.skeleton = skeleton;
     this.head = this.skeleton[SkeletonJoint.Head].position;
     this.neck = this.skeleton[SkeletonJoint.Neck].position;
     this.rightHand = this.skeleton[SkeletonJoint.RightHand].position;
     this.rightElbow = this.skeleton[SkeletonJoint.RightElbow].position;
     this.rightShoulder = this.skeleton[SkeletonJoint.RightShoulder].position;
     this.leftHand = this.skeleton[SkeletonJoint.LeftHand].position;
     this.leftElbow = this.skeleton[SkeletonJoint.LeftElbow].position;
     this.leftShoulder = this.skeleton[SkeletonJoint.LeftShoulder].position;
     this.torso = this.skeleton[SkeletonJoint.Torso].position;
     this.fulcrum = new Fulcrum(this.rightShoulder.X, this.rightShoulder.Y, this.rightShoulder.Z);
 }
예제 #6
0
        protected override void CheckStatus()
        {
            //If starttime = -1 then iniate values.
            xn.Point3D lastPosition = _traceHistory.Values[_traceHistory.Values.Count - 1];
            float lastTime = _traceHistory.Keys[_traceHistory.Values.Count - 1];
            if (_startTime == -1)
            {
                _startPoint = lastPosition;
                _startTime = lastTime;
                return;
            }

            float xMove = lastPosition.X - _startPoint.X;
            float yMove = lastPosition.Y - _startPoint.Y;
            float zMove = lastPosition.Z - _startPoint.Z;
            float timeRunning = lastTime - _startTime;

            bool keepTracking = false;
            keepTracking = System.Math.Abs(xMove) <= _treshHold;
            if (keepTracking) keepTracking = System.Math.Abs(yMove) <= _treshHold;
            if (keepTracking) keepTracking = System.Math.Abs(zMove) <= _treshHold;

            if (!keepTracking)
            {
                //Reset time and point
                _startPoint = lastPosition;
                _startTime = lastTime;
            }
            if (keepTracking)
            {
                //Kept still long enough so this is a still getsure.
                if (timeRunning > _timeToHold)
                {
                    StillGestureRecognized(this, new StillGestureRecognisedEventArgs(Gestures.Still, _startPoint, timeRunning));
                    //Reset time and point
                    _startPoint = lastPosition;
                    _startTime = lastTime;
                }
            }
        }
예제 #7
0
 public void Update(Point3D kinectPoint)
 {
     this.X = kinectPoint.X;
     this.Y = kinectPoint.Y;
     this.Z = kinectPoint.Z;
 }
예제 #8
0
 public BindablePoint(Point3D kinectPoint)
 {
     this.Update(kinectPoint);
 }
예제 #9
0
 void MyBox_PrimaryPointCreate(ref HandPointContext context, ref Point3D ptFocus)
 {
     flowRouter.SetActive(steadyDetector);
 }
예제 #10
0
 private void InternalGestureRecognized(IntPtr hNode, string strGesture, ref Point3D idPosition, ref Point3D endPosition, IntPtr pCookie)
 {
     if (this.gestureRecognizedEvent != null)
         this.gestureRecognizedEvent(this, strGesture, ref idPosition, ref endPosition);
 }
예제 #11
0
 private void ResetVerticalValues()
 {
     _verticalSwipeDetecting = false;
     _verticalStartPoint = new xn.Point3D();
     _verticalStartTime = 0;
 }
예제 #12
0
        private unsafe void ReaderThread()
        {
            DepthMetaData depthMD = new DepthMetaData();

            while (this.shouldRun)
            {
                try
                {
                    this.context.WaitOneUpdateAll(this.depth);
                }
                catch (Exception)
                {
                }

                this.depth.GetMetaData(depthMD);

                CalcHist(depthMD);
                MinX = mouseStartX > mouseEndX ? mouseEndX : mouseStartX;
                MaxX = mouseStartX < mouseEndX ? mouseEndX : mouseStartX;
                MinY = mouseStartY > mouseEndY ? mouseEndY : mouseStartY;
                MaxY = mouseStartY < mouseEndY ? mouseEndY : mouseStartY;

                    lock (this)
                    {
                        Rectangle rect = new Rectangle(0, 0, this.bitmap.Width, this.bitmap.Height);
                        BitmapData data = this.bitmap.LockBits(rect, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);


                        if (this.shouldDrawPixels)
                        {
                            ushort* pDepth = (ushort*)this.depth.GetDepthMapPtr().ToPointer();
                            ushort* pLabels = (ushort*)this.userGenerator.GetUserPixels(0).SceneMapPtr.ToPointer();
                            if (this.finishPick) this.avgDepth = 0;
                            // set pixels
                            for (int y = 0; y < depthMD.YRes; ++y)
                                {
                                    byte* pDest = (byte*)data.Scan0.ToPointer() + y * data.Stride;
                                    for (int x = 0; x < depthMD.XRes; ++x, ++pDepth, ++pLabels, pDest += 3)
                                    {
                                        pDest[0] = pDest[1] = pDest[2] = 0;

                                        ushort label = *pLabels;
                                        if (this.shouldDrawBackground || *pLabels != 0)
                                        {
                                            Color labelColor = Color.White;
                                            if (label != 0)
                                            {
                                                labelColor = colors[label % ncolors];
                                            }

                                            byte pixel = (byte)this.histogram[*pDepth];
                                            pDest[0] = (byte)(pixel * (labelColor.B / 256.0));
                                            pDest[1] = (byte)(pixel * (labelColor.G / 256.0));
                                            pDest[2] = (byte)(pixel * (labelColor.R / 256.0));
                                        }

                                        //WTF
                                        if (this.finishPick)
                                            if (x < MinX || x > MaxX || y < MinY || y > MaxY)
                                                if (MaxX!=MinX)
                                            {
                                                pDest[0] = pDest[1] = pDest[2] = 0;
                                            }
                                        if (this.finishPick)
                                            if (x > MinX && x < MaxX && y > MinY && y < MaxY)
                                            { if (*pDepth > maxSelectedDepth) maxSelectedDepth = *pDepth; this.avgDepth += *pDepth; }
                                    }
                                }


                        }

                        this.bitmap.UnlockBits(data);
                        if (this.finishPick)
                            if (MaxX != MinX)
                        {
                            this.avgDepth = this.avgDepth / ((MaxX - MinX) * (MaxY - MinY));
                            Point3D CenterOfSelected = new Point3D((mouseStartX + mouseEndX) / 2, (mouseStartY + mouseEndY) / 2, maxSelectedDepth);
                            this.depth.ConvertRealWorldToProjective(CenterOfSelected);
                            Console.Out.WriteLine("avg depth of selected region = " + avgDepth+" Max = " + CenterOfSelected.Z);
                        }
                        if (this.SaveBitmap) {
                            String path = Directory.GetCurrentDirectory() + "\\Captured.jpg";
                            try { this.bitmap.Save(path); }
                            catch (Exception e) { Console.Out.WriteLine(e.ToString()); }
                            avgSelectedDepth = avgDepth;
                            Console.Out.WriteLine("Depth of selected = " + avgSelectedDepth);
                            this.SaveBitmap = false;
                        }

                    Graphics g;
                    if (!this.ChangeDisplay)
                    {
                        g = Graphics.FromImage(this.bitmap);
                        //Console.Out.WriteLine("Dynamic Background");
                    }
                    else
                    {
                        String filepath = Directory.GetCurrentDirectory() + "\\Captured.jpg";
                        try 
                        {
                            this.Selected =new Bitmap(filepath);
                        }
                        
                        catch (Exception e) { Console.Out.WriteLine(e.ToString()); }
                        g = Graphics.FromImage(this.Selected);
                        //Console.Out.WriteLine("Static Background");
                    }
                    //g.DrawString("Center of Selected", new Font("Arial", 10), new SolidBrush(Color.Gold), CenterOfSelected.X, CenterOfSelected.Y);
                    //Draw Region
                    if (this.shouldPickRegion) DrawRegion(g);

                    uint[] users = this.userGenerator.GetUsers();
                    foreach (uint user in users)
                    {
                        Point3D com = this.userGenerator.GetCoM(user);

                        com = this.depth.ConvertRealWorldToProjective(com);
                        if (this.shouldPrintID)
                        {

                            if (com.Z > userMaxDepth)
                            {
                                userMaxDepth = (int)com.Z;
                            }                            
                            string label = "";
                            if (!this.shouldPrintState)
                                label += user;
                            else if (this.skeletonCapbility.IsTracking(user))
                                label += user + " - Tracking";
                            else if (this.skeletonCapbility.IsCalibrating(user))
                                label += user + " - Calibrating...";
                            else
                                label += user + " - Looking for pose";
                            //Console.Out.WriteLine("Catch u at " + com.Z + " within " + (avgDepth - DistanceThresold) + " and " + (avgDepth + DistanceThresold));
                            //Console.Out.WriteLine(avgSelectedDepth);
                            label += " Depth = " + com.Z;
                            if (com.Z < avgSelectedDepth - DistanceThresold || com.Z > avgSelectedDepth + DistanceThresold)
                                label += " TOO FAR";
                            else
                                ;//Console.Out.WriteLine("Catch u at " + com.Z + " within " + (avgSelectedDepth - DistanceThresold) + " and " + (avgSelectedDepth + DistanceThresold));
                            g.DrawString(label, new Font("Arial", 10), new SolidBrush(anticolors[user % ncolors]), com.X, com.Y);

                        }

                        if (this.shouldDrawSkeleton && this.skeletonCapbility.IsTracking(user))
                            //                        if (this.skeletonCapbility.IsTracking(user))
                            if ((com.Z > avgSelectedDepth - DistanceThresold && com.Z < avgSelectedDepth + DistanceThresold) && avgSelectedDepth != 0)
                            DrawSkeleton(g, anticolors[user % ncolors], user);

                    }
                    g.Dispose();
                }

                this.Invalidate();
            }
        }
예제 #13
0
 void SessionStarted(ref Point3D point)
 {
     Console.WriteLine("Session Started");
 }
예제 #14
0
 public static extern XnStatus xnConvertRealWorldToProjective(XnNodeHandle hInstance, XnUInt32 nCount, Point3D[] aRealWorld, [In][Out] Point3D[] aProjective);
예제 #15
0
 public Plane3D(Point3D normal, Point3D point)
 {
     this.vNormal = normal;
     this.ptPoint = point;
 }
예제 #16
0
 public static extern XnStatus xnStartTracking(XnNodeHandle hInstance, ref Point3D pPosition);
예제 #17
0
 private void SessionManager_SessionStart(ref Point3D position)
 {
     // update the state
     Dispatcher.BeginInvoke(() => { State = SessionState.Running; });
 }
예제 #18
0
 private void PointControl_PrimaryPointCreate(ref HandPointContext context, ref Point3D ptfocus)
 {
     System.Windows.Media.Media3D.Point3D? point = PointFromContext(context);
     Dispatcher.BeginInvoke(() => { Point = point; });
 }
예제 #19
0
 private void SessionStarted(ref Point3D point)
 {
     Console.WriteLine("{0} ", CurrentContext.CurrentState.ToString());
     Console.WriteLine(Flowy.ToString());
 }
예제 #20
0
 void gg_GestureRecognized(ProductionNode node, string strGesture, ref Point3D idPosition, ref Point3D endPosition)
 {
     //throw new NotImplementedException();
 }
예제 #21
0
 private void InternalHandUpdate(IntPtr hNode, UserID id, ref Point3D position, float fTime, IntPtr pCookie)
 {
     if (this.handUpdateEvent != null)
         this.handUpdateEvent(this, id, ref position, fTime);
 }
예제 #22
0
 public void StartTracking(ref Point3D position)
 {
     UInt32 status = OpenNIImporter.xnStartTracking(this.InternalObject, ref position);
     WrapperUtils.CheckStatus(status);
 }
예제 #23
0
 private Point TransformToScreenPos(Point3D p,int width,int height)
 {
     Point re=new Point(0,0);
     float tmpX = p.X;
     float tmpY = p.Y;
     if (tmpX < SelectedMinX || tmpY < SelectedMinY) return re;
     if (tmpX > SelectedMaxX || tmpY > SelectedMaxY) return re;
     tmpX = tmpX - SelectedMinX; tmpY = tmpY - SelectedMinY;
     tmpX = tmpX / (SelectedMaxX - SelectedMinX) * width;
     tmpY = tmpY / (SelectedMaxY - SelectedMinY) * height;
     re.X = (int)tmpX;
     re.Y = (int)tmpY;
     if (flipped) { re.X = width - re.X;}
     return re;
 }
예제 #24
0
 public static extern Point3D xnCreatePlane3D(Point3D ptPoint, Point3D vNormal);
예제 #25
0
 protected override void CheckStatus()
 {
     //Get the last postion and time
     xn.Point3D lastPosition = _traceHistory.Values[_traceHistory.Values.Count - 1];
     float lastTime = _traceHistory.Keys[_traceHistory.Values.Count - 1];
     //Initiate horizontal swipe if needed
     if (!_horizontalSwipeDetecting && _traceHistory.Values.Count >= 2)
     {
         _horizontalSwipeDetecting = true;
         _horizontalStartPoint = _previousPoint;
         _horizontalStartTime = _previousTime;
         //Detect if the swip is lefdt or rigth
         if (lastPosition.X > _horizontalStartPoint.X) _horizontalSwipeDirection = Gestures.SwipeLeft;
         else _horizontalSwipeDirection = Gestures.SwipeRight;
     }
     //Initiate vertical swipe if needed
     if (!_verticalSwipeDetecting && _traceHistory.Values.Count >= 2)
     {
         _verticalSwipeDetecting = true;
         _verticalStartPoint = _previousPoint;
         _verticalStartTime = _previousTime;
         //Detect if the swip is up or down
         if (lastPosition.Y > _verticalStartPoint.Y) _verticalSwipeDirection = Gestures.SwipeDown;
         else _verticalSwipeDirection = Gestures.SwipeUp;
     }
     else
     {
         //Check if the detecting swipe is still valid
         switch (_horizontalSwipeDirection)
         {
             case Gestures.SwipeLeft:
                 if (lastPosition.X < _previousPoint.X)
                 {
                     float change = lastPosition.X - _horizontalStartPoint.X;
                     float duration = lastTime - _horizontalStartTime;
                     //Check if the swip is completed.
                     //This is true if the treshold is passed.
                     CheckSwipeCompleted(lastPosition, duration, change, Gestures.SwipeLeft);
                 }
                 else
                 {
                     //ResetHorizontalValues();
                 }
                 break;
             case Gestures.SwipeRight:
                 if (_previousPoint.X < lastPosition.X)
                 {
                     float change = _horizontalStartPoint.X - lastPosition.X;
                     float duration = lastTime - _horizontalStartTime;
                     //Check if the swip is completed.
                     //This is true if the treshold is passed.
                     CheckSwipeCompleted(lastPosition, duration, change, Gestures.SwipeRight);
                 }
                 else
                 {
                     //ResetHorizontalValues();
                 }
                 break;
         }
         switch (_verticalSwipeDirection)
         {
             case Gestures.SwipeUp:
                 if (_previousPoint.Y < lastPosition.Y)
                 {
                     float change = lastPosition.Y - _verticalStartPoint.Y;
                     float duration = lastTime - _verticalStartTime;
                     //Check if the swip is completed.
                     //This is true if the treshold is passed.
                     CheckSwipeCompleted(lastPosition, duration, change, Gestures.SwipeUp);
                 }
                 else
                 {
                     //ResetVerticalValues();
                 }
                 break;
             case Gestures.SwipeDown:
                 if (_previousPoint.Y < lastPosition.Y)
                 {
                     float change = _verticalStartPoint.Y - lastPosition.Y;
                     float duration = lastTime - _verticalStartTime;
                     //Check if the swip is completed.
                     //This is true if the treshold is passed.
                     CheckSwipeCompleted(lastPosition, duration, change, Gestures.SwipeDown);
                 }
                 else
                 {
                     //ResetVerticalValues();
                 }
                 break;
         }
     }
     _previousPoint = lastPosition;
     _previousTime = lastTime;
 }
예제 #26
0
 public static extern XnStatus xnGetUserCoM(XnNodeHandle hInstance, XnUserID user, out Point3D pCoM);
예제 #27
0
 private void InternalGestureProgress(IntPtr hNode, string strGesture, ref Point3D position, float progress, IntPtr pCookie)
 {
     if (this.gestureProgressEvent != null)
         this.gestureProgressEvent(this, strGesture, ref position, progress);
 }
예제 #28
0
 public Point3D GetCoM(UserID id)
 {
     Point3D com = new Point3D();
     UInt32 status = OpenNIImporter.xnGetUserCoM(this.InternalObject, id, out com);
     WrapperUtils.CheckStatus(status);
     return com;
 }
예제 #29
0
 private void ResetHorizontalValues()
 {
     _horizontalSwipeDetecting = false;
     _horizontalStartPoint = new xn.Point3D();
     _horizontalStartTime = 0;
 }