コード例 #1
0
 public void GetMaxPoint(ref Points p)
 {
     if (p.Y > _maxPoint)
     {
         _maxPoint = (int)p.Y;
     }
 }
コード例 #2
0
 public void GetMaxDepth(Points p)
 {
     if (p.Z > _maxDepth)
     {
         _maxDepth = (int)p.Z;
     }
 }
コード例 #3
0
 public void GetMinPoint(ref Points p)
 {
     if (p.Y < _minPoint)
     {
         _minPoint = (int)p.Y;
     }
 }
コード例 #4
0
 public void GetMinDepth(Points p)
 {
     if (p.Z < _minDepth)
     {
         _minDepth = (int)p.Z;
     }
 }
コード例 #5
0
        public List<Points> GetAvarageDepth(List<Points> depthArray, int avrageCoefficient, int squareSize)
        {
            var bodyDepth = new List<Points>();
            ResetMaximaPoint();

            for (int i = 0; i < depthArray.Count - 1; i = i + avrageCoefficient)
            {
                int depth = (int)((depthArray[i].Z + depthArray[i + 1].Z / 2));
                var p = new Points(depthArray[i].X, depthArray[i].Y, depthArray[i].Z, 0);
                p.Z = depth;

                if (Math.Abs(p.Z - _avarageFullDepth) < _depthBodyDifference)
                {
                    bodyDepth.Add(depthArray[i]);
                }
                else
                {
                    depthArray[i].Z = 0;
                    bodyDepth.Add(depthArray[i]);
                }
            }

            // Get basic squares Body
            GetBodySquare(ref depthArray, squareSize);

            // Remove not proper body squares and get maximas
            RemoveNotProperBodySquares();

            return bodyDepth;
        }
コード例 #6
0
        public static double CalculatePointsDistance(Points p1, Points p2)
        {
            double powX = (p1.X - p2.X) * (p1.X - p2.X);
            double powY = (p1.Y - p2.Y) * (p1.Y - p2.Y);

            return Math.Sqrt(powX + powY);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: macki/GestureRecognition
        private static void Resample(List<Points> points, int sampleNum)
        {
            double Interval = CalculatePathLength(points) / (sampleNum);

            var newPoints = new List<Points>();
            newPoints.Add(points[0]);

            double manageDistance = 0;
            for (int i = 1; i < points.Count; i++)
            {
                double distance = CalculatePointsDistance(points[i - 1], points[i]);
                if ((manageDistance + distance) >= Interval)
                {
                    var newKinectPoint = new Points();
                    newKinectPoint.X = points[i - 1].X + ((Interval - manageDistance) / distance) * (points[i].X - points[i - 1].X);
                    newKinectPoint.Y = points[i - 1].Y + ((Interval - manageDistance) / distance) * (points[i].Y - points[i - 1].Y);

                    newPoints.Add(newKinectPoint);
                    points.Insert(i, newKinectPoint);
                    manageDistance = 0;
                }
                else
                {
                    manageDistance = manageDistance + distance;
                }
            }

            var form = new Forms.AlgorithmsStepForm();
            form.Show();
            form.DrawPoints(newPoints);
        }
コード例 #8
0
ファイル: Points.cs プロジェクト: macki/GestureRecognition
 public Points(Points p)
 {
     this.X = p.X;
     this.Y = p.Y;
     this.Z = p.Z;
     this.MSecTime = p.MSecTime;
 }
コード例 #9
0
        public void DeptyArrayToDepthPoints(List<int> depthArray)
        {
            int yPos = 0;

            for (int i = 0; i < depthArray.Count; i++)
            {
                RecalculatePosition(i, ref yPos);

                var point = new Points(i - yPos * _cameraWidth, yPos, depthArray[i], 0);
            }

            //GetAvarageDepth(depthArray);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: macki/GestureRecognition
        static void Main()
        {
            Console.WriteLine("UnistrokeRecognize");

            var point = new Points(0, 0, 0, 0);
            var point2 = new Points(2, 2, 0, 0);

            var points = new List<Points>();
            for (int i = 0; i < 10; i++)
            {
                points.Add(new Points(i * 20, i * 20, 0, 0));
            }

            var form = new Forms.AlgorithmsStepForm();
            form.Show();
            form.DrawPoints(points);

            Resample(points, 64);

            //var tt2 = new UnistrokeRecognizer();
            //tt2.Recognize()

            Console.ReadKey();
        }
コード例 #11
0
        private List<Points> ReadGesture(XmlTextReader reader)
        {
            string name = reader.GetAttribute("Name");
            var points = new List<Points>(XmlConvert.ToInt32(reader.GetAttribute("NumPts")));

            reader.Read();
            Debug.Assert(reader.LocalName == "Point");

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                var p = new Points();
                p.X = XmlConvert.ToSingle(reader.GetAttribute("X"));
                p.Y = XmlConvert.ToSingle(reader.GetAttribute("Y"));
                //p.Z = XmlConvert.ToSingle(reader.GetAttribute("Z"));
                p.MSecTime = XmlConvert.ToInt64(reader.GetAttribute("T"));
                points.Add(p);
                reader.ReadStartElement("Point");
            }

            // transform
            return points;
        }
コード例 #12
0
        private VideoFrames GetVideoFrameFromBitmap(Bitmap bitmap)
        {
            var videoFrame = new VideoFrames();
            int avarageFullDepth = 0;

            for (int i = 0; i < bitmap.Height; i++)
            {
                for (int j = 0; j < bitmap.Width; j++)
                {
                    var pixel = bitmap.GetPixel(j, i);
                    double v = (pixel.R + pixel.G + pixel.B) / 3;
                    double zDepth = v / 255 * (_maximalDistanceFromCamera - _minimumDistanceFromCamera) + _minimumDistanceFromCamera;

                    var p = new Points(j, i, (int)zDepth, 0);

                    _trackingSystem.GetMaxDepth(p);
                    _trackingSystem.GetMinDepth(p);

                    avarageFullDepth = avarageFullDepth + (int)zDepth;

                    videoFrame.DepthArray.Add(p);
                }
            }

            _trackingSystem.SetAvarageFullDepth(avarageFullDepth / videoFrame.DepthArray.Count);

            return videoFrame;
        }
コード例 #13
0
        private void GesturesForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isMoving)
            {
                _squares[_selectedSquareIndex] = new Rectangle(e.X, e.Y, 20, 20);
               this.Refresh();
               DrawSquare(_squares[_selectedSquareIndex]);
            }
            else
            {

                if (_isDrawing)
                {
                    if (_gestureOption == GestureRecognition.Logic.Enums.GestureFormOption.Record)
                    {
                        GestureInfo.Text = "Recording...";
                    }
                    else if (_gestureOption == GestureRecognition.Logic.Enums.GestureFormOption.Recognize)
                    {
                        GestureInfo.Text = "Recognizing...";
                    }

                    _previousPoint = new Points(e.X, e.Y, 0, (DateTime.Now.Ticks - _tickingCounterStart) / 10000);
                    _newGesture.Points.Add(_previousPoint);

                    Invalidate(new Rectangle(e.X - 2, e.Y - 2, 4, 4));
                }
            }
        }
コード例 #14
0
        private Points CalculateBodyCentroid()
        {
            var centroidPoint = new Points();

            return centroidPoint;
        }
コード例 #15
0
        /// <summary>
        /// Resample point to N - sampleSize
        /// </summary>
        /// <param name="points"></param>
        /// <param name="sampleSize"></param>
        /// <returns></returns>
        protected List<Points> ResamplePoints(List<Points> points, int sampleSize)
        {
            double Interval = MathHelper.CalculatePathLength(points) / (sampleSize);

            var newPoints = new List<Points>();
            newPoints.Add(points[0]);

            double manageDistance = 0;
            for (int i = 1; i < points.Count; i++)
            {
                double distance = MathHelper.CalculatePointsDistance(points[i - 1], points[i]);
                if ((manageDistance + distance) >= Interval)
                {
                    var newPoint = new Points();
                    newPoint.X = points[i - 1].X + ((Interval - manageDistance) / distance) * (points[i].X - points[i - 1].X);
                    newPoint.Y = points[i - 1].Y + ((Interval - manageDistance) / distance) * (points[i].Y - points[i - 1].Y);

                    newPoints.Add(newPoint);
                    points.Insert(i, newPoint);
                    manageDistance = 0;
                }
                else
                {
                    manageDistance = manageDistance + distance;
                }
            }
            return newPoints;
        }
コード例 #16
0
        /// <summary>
        /// Rotate Points accroding to Theta i centroid point
        /// </summary>
        /// <param name="pointsAfterStep_One"></param>
        /// <param name="theta"></param>
        /// <returns></returns>
        protected List<Points> RotateBy(List<Points> pointsAfterStep_One, double theta)
        {
            // optimaze
            var centroid = MathHelper.CalculateCentroid(pointsAfterStep_One);
            var pointsCount = pointsAfterStep_One.Count;
            var cos = Math.Cos(theta);
            var sin = Math.Sin(theta);

            var newPoints = new List<Points>();
            var newPoint = new Points();
            for (int i = 0; i < pointsCount; i++)
            {
                newPoint = new Points();
                newPoint.X = (pointsAfterStep_One[i].X - centroid.X) * cos - (pointsAfterStep_One[i].Y - centroid.Y) * sin + centroid.X;
                newPoint.Y = (pointsAfterStep_One[i].X - centroid.X) * sin + (pointsAfterStep_One[i].Y - centroid.Y) * cos + centroid.Y;
                newPoints.Add(newPoint);
            }
            return newPoints;
        }
コード例 #17
0
        protected List<Points> ScaleTo(List<Points> rotatedPoints, int boundingSize)
        {
            var boundingBox = MathHelper.CalculateBoundingBox(rotatedPoints);

            var newPoints = new List<Points>();
            var newPoint = new Points();
            for (int i = 0; i < rotatedPoints.Count; i++)
            {
                newPoint = new Points();
                newPoint.X = rotatedPoints[i].X * boundingSize / boundingBox.Width;
                newPoint.Y = rotatedPoints[i].Y * boundingSize / boundingBox.Heigth;
                newPoints.Add(newPoint);
            }
            return newPoints;
        }
コード例 #18
0
        /// <summary>
        /// Translate  points to the origin [Points (0,0)]
        /// </summary>
        /// <param name="scaledPoints"></param>
        /// <param name="originPoint"></param>
        /// <returns></returns>
        protected List<Points> TranslateTo(List<Points> scaledPoints, Points originPoint)
        {
            var centroidPoint = MathHelper.CalculateCentroid(scaledPoints);
            var newPoints = new List<Points>();
            Points point = null;

            for (int i = 0; i < scaledPoints.Count; i++)
            {
                point = new Points();
                point.X = scaledPoints[i].X + originPoint.X - centroidPoint.X;
                point.Y = scaledPoints[i].Y + originPoint.Y - centroidPoint.Y;
                newPoints.Add(point);
            }
            return newPoints;
        }