ShapeDetection() public method

public ShapeDetection ( ) : void
return void
Exemplo n.º 1
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;
        }