Ejemplo n.º 1
0
        public List<TableObject>AssignVideoBitmap(List<TableObject> objects, Bitmap videoBitmap)
        {
            Bitmap localbitmap = new Bitmap(videoBitmap);
            foreach (TableObject obj in objects.Where(obj => obj.CenterDefined))
            {
                //Calculate the position of the Color-Coords
                obj.Center = PositionMapper.GetColorCoordinatesfromDepth(obj.Center, true,
                                                                         SettingsManager.RecognitionSet.TableDistance - obj.Height);
                //Cut out an extract of the videoImage
                Bitmap extract = new Bitmap(obj.Radius + SettingsManager.RecognitionSet.ObjectVideoBitmapEnlargement, obj.Radius + SettingsManager.RecognitionSet.ObjectVideoBitmapEnlargement);

                //Create area rectangle
                int width = 0, height = 0;
                SettingsManager.KinectSet.GetVideoResolution(out width, out height);

                TRectangle area = new TRectangle(obj.Center.ColorX, obj.Center.ColorY, obj.Radius + SettingsManager.RecognitionSet.ObjectVideoBitmapEnlargement, true,
                                                 new TRectangle(0, 0, width-1, height-1));

                //Copy Color pixels
                for (int x = area.X; x < area.X2; x++)
                {
                    for (int y = area.Y; y < area.Y2; y++)
                    {
                        Color col = localbitmap.GetPixel(x, y);
                        extract.SetPixel(x - area.X, y - area.Y, col);
                    }
                }

                //Assign bitmap
                obj.ExtractedBitmap = extract;
            }

            return objects;
        }
Ejemplo n.º 2
0
 public TRectangle(int X, int Y, int Width, int Height, bool CutIntoBound, TRectangle bounds)
 {
     this.X = X;
     this.Y = Y;
     this.X2 = X + Width;
     this.Y2 = Y + Height;
     if (CutIntoBound)
         CutIntoBounds(bounds.X, bounds.Y, bounds.X2, bounds.Y2);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculates the neigbour-values for a given
        /// </summary>
        /// <param name="boolmap"></param>
        /// <param name="area"></param>
        /// <param name="neigbourmap"></param>
        /// <param name="ImageWidth"></param>
        /// <param name="ImageHeight"></param>
        private static void CalculateNeigbourValues(bool[,] boolmap, TRectangle area, ref int[,,] neigbourmap, int ImageWidth, int ImageHeight)
        {
            //For every Point in the given Area
            for (int x = area.X; x <= area.X2; x++)
            {
                for (int y = area.Y; y <= area.Y2; y++)
                {
                    bool work = true;
                    int rectangleSize = 0;
                    while (work)
                    {
                        //Expand the rectangle
                        if (rectangleSize > 0)
                            rectangleSize += SettingsManager.RecognitionSet.ObjectRecognitionRectIncrease;
                        else
                            rectangleSize = SettingsManager.RecognitionSet.ObjectMinimalRadius;

                        TRectangle workrectancle = new TRectangle(x, y, rectangleSize, true, new TRectangle(0, 0, ImageWidth-1, ImageHeight-1));

                        //Count the neigbours
                        int true_n = 0;
                        int false_n = 0;

                        for (int xn = workrectancle.X; xn <= workrectancle.X2; xn++)
                        {
                            for (int yn = workrectancle.Y; yn <= workrectancle.Y2; yn++)
                            {
                                if (boolmap[xn, yn])
                                    true_n++;
                                else
                                    false_n++;
                            }
                        }

                        //Calculate the percentage of false-neigbours
                        double false_percentage = (100/(true_n + false_n))*false_n;
                        false_percentage = false_percentage / 100.0;

                        //break if the percentage is reached or the maximal object size is reached (or a fixed programmed value - for
                        if (false_percentage >= SettingsManager.RecognitionSet.ObjectRecognitionNeighbourcountThreshold ||
                            workrectancle.Width >= SettingsManager.RecognitionSet.ObjectMaximalRadius )
                        {
                            work = false;
                            //write the values to the array
                            neigbourmap[x, y, 0] = true_n;
                            neigbourmap[x, y, 1] = workrectancle.Width; // == Height

                            //Special case: object is too small (not enought neigbours with the lowest rectangle size) --> don't save values
                            if (rectangleSize == SettingsManager.RecognitionSet.ObjectMinimalRadius)
                                neigbourmap[x, y, 0] = 0;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public TRectangle(int CenterX, int CenterY, int side, bool CutIntoBound, TRectangle bounds)
        {
            this.X = (int) Math.Round((double) (CenterX - side/2));
            this.Y = (int) Math.Round((double) (CenterY - side/2));

            this.X2  = (int) Math.Round((double)(CenterX + side/2));
            this.Y2 = (int) Math.Round((double)(CenterY + side/2));

            if (CutIntoBound)
                CutIntoBounds(bounds.X, bounds.Y, bounds.X2, bounds.Y2);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets all neigbourvalues around a given point (in "his" rectangle) to zero
        /// </summary>
        /// <param name="neigbourmap"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="point"></param>
        private void SetPointsToZero(ref int[,,] neigbourmap, int width, int height, ObjectPoint point)
        {
            //Create Rectangle for point
            TRectangle workrectancle = new TRectangle(point.X, point.Y, point.RectSize, true,
                                                      new TRectangle(0, 0, width-1, height-1));

            //Set every neigbourvalue to 0
            for (int x = workrectancle.X; x <= workrectancle.X2; x++)
            {
                for (int y = workrectancle.Y; y <= workrectancle.Y2; y++)
                {
                    neigbourmap[x, y, 0] = 0;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a neighbourmap - an int[x,y,n] array, where the int stores the count of the whitepixel-neighbours of the object (n=0) and the size of the circle/rect used 
        /// to count these neighbours (n=1). The circle/rect is scaled up until a defined percentage of the pixels is false, meaning no part of the object. the neigbourmap is only created around true rasterpoints to be eficcent
        /// </summary>
        /// <param name="boolmap">The boolmap</param>
        /// <param name="image">Depth Image</param>
        /// <param name="rasterpoints">The calculated Rasterpoints</param>
        /// <returns></returns>
        private static int[,,] CreateNeighbourMap(bool[,] boolmap, DepthImage image, List<TPoint> rasterpoints)
        {
            int[,,] neighbourmap = new int[image.Width,image.Height,2];

            //Do this for each region arount the true rasterpoints
            foreach (TPoint rasterpoint in rasterpoints)
            {
                //calculate the area: the Gridsize after the points Position
                int xmin = rasterpoint.DepthX;
                int ymin = rasterpoint.DepthY;

                int xmax = rasterpoint.DepthX + SettingsManager.RecognitionSet.ObjectRecognitionGridSpacing;
                if (xmax >= image.Width)
                    xmax = image.Width - 1;

                int ymax = rasterpoint.DepthY + SettingsManager.RecognitionSet.ObjectRecognitionGridSpacing;
                if (ymax >= image.Height)
                    ymax = image.Height - 1;

                TRectangle area = new TRectangle(xmin, ymin, xmax, ymax);

                //Now calculate the values for every point in the area
                CalculateNeigbourValues(boolmap, area, ref neighbourmap, image.Width, image.Height);
            }

            return neighbourmap;
        }