Exemplo n.º 1
0
        /////////// FINISH ME!
        /// <summary>
        /// Get the score of the target to check if it is the correct one
        /// </summary>
        /// <param name="t">The Target</param>
        /// <returns>Score as a percentage, 0 to 100</returns>
        public int GetScore(Target t)
        {
            // 100 is MaxBadScoreDistance
            float score_pos = 1f - Math.Min(1, Distance(t.X, t.Y, _Position.X + _Velocity.X, _Position.Y + _Velocity.Y) / 150f); // score algo with max being 1 for all of them

            // 50 is MaxBadScoreVelocity
            //float vel_x = 1f - Math.Min(1, Math.Abs(t.X - _Position.X) / 50f);
            //float vel_y = 1f - Math.Min(1, Math.Abs(t.Y - _Position.Y) / 50f);

            // 50 is MaxBadScoreSize
            float size_x = 1f - Math.Min(1, Math.Abs(t.SizeX - _Size.X) / 100f);
            float size_y = 1f - Math.Min(1, Math.Abs(t.SizeY - _Size.Y) / 100f);

            float score_size = (size_x + size_y) / 2f;
            //float score_vel = (vel_x + vel_y) / 2f;

            return (int)(((score_pos + score_size) / 2f) * 100f);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Update all the targets
 /// </summary>
 /// <param name="targs">Array of the targets</param>
 public void UpdateTargets(Target[] targs)
 {
     _targets = targs;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Draw a box around a target
 /// </summary>
 /// <param name="t">The target to draw a box around</param>
 /// <param name="bmp">The bitmap to draw to</param>
 /// <param name="col">Color</param>
 public void DrawBox(Target t, ref Bitmap bmp, Color col)
 {
     DrawBox(t.X, t.Y, t.SizeX, t.SizeY, ref bmp, col, false);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Is the target inside of a specific X and Y
 /// </summary>
 /// <param name="targs">Target Array</param>
 /// <param name="x">X</param>
 /// <param name="y">Y</param>
 /// <returns></returns>
 private bool NotInsideOfTarget(ref Target[] targs, int x, int y)
 {
     try
     {
         int res = InRangeOfTarget(ref targs, x, y);
         return (res == -1);
     }
     catch (Exception ex)
     {
         Error(ex.Message);
     }
     return true;
 }
Exemplo n.º 5
0
        ////// This is a bottle neck!!! Speed me up.
        /// <summary>
        /// Checks to see if movement pixels are in range of a target
        /// </summary>
        /// <param name="targs">Target array</param>
        /// <param name="x">X</param>
        /// <param name="y">Y</param>
        /// <returns></returns>
        private int InRangeOfTarget(ref Target[] targs, int x, int y)
        {
            try
            {
                int i = 0;
                foreach (Target t in targs)
                {
                    if (t == null) // we should only get here if there were no targets matched
                        return -1;
                    // Check distance from cornders and that its not near the edge blah blah so on...
                    int X = t.X - _maxjoindistance;
                    int Y = t.Y - _maxjoindistance;
                    int eX = X + t.SizeX + 2 * _maxjoindistance;
                    int eY = Y + t.SizeY + 2 * _maxjoindistance;

                    if (x > X && x < eX &&
                        y > Y && y < eY)
                    {
                        return i;
                    }

                    i++;
                }
            }
            catch (Exception ex)
            {
                Error(ex.Message);
            }
            return -1;
        }
Exemplo n.º 6
0
        public IEnumerable<Target> GetTargets()
        {
            Bitmap cur_img = new Bitmap(_cur_img);
            Bitmap last_img = new Bitmap(_last_img);
            // Data will be copied into here for each X and Y
            byte[,] pixels = new byte[cur_img.Width, cur_img.Height];

            BitmapData curimg = cur_img.LockBits(
                new Rectangle(0, 0, cur_img.Width, cur_img.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData lastimg = last_img.LockBits(
                new Rectangle(0, 0, last_img.Width, last_img.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            Bitmap motion = cur_img;    // derive motion from the image that will be used for the motion pixels then copy the data into it
            motion.UnlockBits(SubtractPixels(curimg, lastimg, ref pixels));
            last_img.UnlockBits(lastimg);   // free it
            motionpic = motion;
            // Pixels now contain where there is movement in x,y
            LinkedList<Target> targs = new LinkedList<Target>();
            for (int y = 0; y < cur_img.Height; y++)    // yes this is messy, look above at the pesudo code for how and what this is doing
                for (int x = 0; x < cur_img.Width; x++)
                {
                    int movement = pixels[x, y];
                    if (movement == 1)
                    {
                        MotionHelper helper = this.GetBoundsFromMotion(ref pixels,
                            new Point(motion.Width, motion.Height),
                            new Point(x, y));

                        Target newtarg = new Target(helper.MinX, helper.MinY,
                            helper.MaxX - helper.MinX,
                            helper.MaxY - helper.MinY);

                        newtarg.Shape = helper.Shape;
                        newtarg.ShapeDetection();

                        float scalex = newtarg.SizeX / _noisereduction;
                        float scaley = newtarg.SizeY / _noisereduction;
                        if (scalex + scaley > 1.75f)
                            targs.AddLast(newtarg);
                        else
                            _BadTargets++;
                    }
                }
            return targs;
        }