示例#1
0
        public List<AnalyzedObject> analyzeImage(Bitmap origImage)
        {
            ColorRange redRange = new ColorRange();
            redRange.redMin = 150;
            redRange.redMax = 256;
            redRange.greenMin = 0;
            redRange.greenMax = 80;
            redRange.blueMin = 0;
            redRange.blueMax = 80;

            ColorRange greenRange = new ColorRange();
            greenRange.redMin = 0;
            greenRange.redMax = 50;
            greenRange.greenMin = 120;
            greenRange.greenMax = 256;
            greenRange.blueMin = 50;
            greenRange.blueMax = 180;

            int[,] idMat = new int[origImage.Width, origImage.Height];
            int currId = 0;
            Bitmap segImage = modify(origImage, redRange, greenRange, idMat, ref currId);

            int[] lookup = new int[currId + 1];
            createIdLookup(segImage, idMat, lookup, ref currId);
            fixIds(idMat, segImage.Width, segImage.Height, lookup);

            List<AnalyzedObject> objects = new List<AnalyzedObject>();
            AnalyzedObject[] tmpObj = new AnalyzedObject[currId + 1];
            findObjects(segImage, idMat, tmpObj);

            int count = 1;
            for (int i = 1; i <= currId; ++i)
            {
                if (tmpObj[i] == null) continue;
                if (tmpObj[i].size < 40) continue;

                tmpObj[i].id = count;
                objects.Add(tmpObj[i]);
                ++count;
            }

            //detectObj(segImage, objects);

            //sizeFilter(objects, origImage);
            blackOtherFilter(objects, origImage);
            //blackBoxFilter(objects, origImage);
            //decide(result);

            return objects;
        }
示例#2
0
        public void findObjects(Bitmap im, int[,] idMat, AnalyzedObject[] tmpObj)
        {
            for (int i = 0; i < im.Width; ++i)
            {
                for (int j = 0; j < im.Height; ++j)
                {
                    if (idMat[i, j] == 0) continue;
                    int index = idMat[i, j];
                    if (tmpObj[index] == null)
                    {
                        tmpObj[index] = createInitObj();
                        tmpObj[index].leftTop.x = i;
                        tmpObj[index].leftTop.y = j;
                        tmpObj[index].color = im.GetPixel(i, j);
                    }

                    // set bounding box
                    if (i < tmpObj[index].bBox.topLeft.x) tmpObj[index].bBox.topLeft.x = i;
                    if (i > tmpObj[index].bBox.bottomRight.x) tmpObj[index].bBox.bottomRight.x = i;
                    if (j < tmpObj[index].bBox.topLeft.y) tmpObj[index].bBox.topLeft.y = j;
                    if (j > tmpObj[index].bBox.bottomRight.y) tmpObj[index].bBox.bottomRight.y = j;

                    ++(tmpObj[index].size);
                }
            }
        }
示例#3
0
        static void detectObj(Bitmap im, List<AnalyzedObject> objects)
        {
            bool[,] markMat = new bool[im.Width, im.Height];

            for (int i = 0; i < im.Width; ++i)
            {
                for (int j = 0; j < im.Height; ++j)
                {
                    Color c = im.GetPixel(i, j);
                    if (c.B == 0 && c.R == 0 && c.G == 0)
                    {
                        continue;
                    }

                    // we are on a non white pixel
                    BoundingBox bBox = new BoundingBox();
                    bBox.topLeft.x = 10000;
                    bBox.topLeft.y = 10000;
                    bBox.bottomRight.x = 0;
                    bBox.bottomRight.y = 0;

                    ColorStat cSum = new ColorStat();
                    ColorStat cSum2 = new ColorStat();

                    ObjPoint coordSum = new ObjPoint();
                    int depth = 0;

                    int size = getObj(im, i, j, markMat, depth, c, bBox, cSum, cSum2, coordSum);
                    if (size == 0) continue;

                    AnalyzedObject obj = new AnalyzedObject();
                    obj.decision = true;

                    obj.leftTop.x = i;
                    obj.leftTop.y = j;
                    obj.size = size;
                    obj.color = c;
                    obj.bBox = bBox;

                    cSum.R /= size;
                    cSum.G /= size;
                    cSum.B /= size;

                    cSum2.R = Math.Sqrt(cSum2.R / size - cSum.R * cSum.R);
                    cSum2.G = Math.Sqrt(cSum2.G / size - cSum.G * cSum.G);
                    cSum2.B = Math.Sqrt(cSum2.B / size - cSum.B * cSum.B);

                    obj.colorAv = cSum;
                    obj.colorStdev = cSum2;

                    coordSum.x = (int)(coordSum.x / size);
                    coordSum.y = (int)(coordSum.y / size);
                    obj.centroid = coordSum;

                    objects.Add(obj);

                }
            }
        }
示例#4
0
        public AnalyzedObject createInitObj()
        {
            BoundingBox bBox = new BoundingBox();
            bBox.topLeft.x = 10000;
            bBox.topLeft.y = 10000;
            bBox.bottomRight.x = 0;
            bBox.bottomRight.y = 0;

            AnalyzedObject obj = new AnalyzedObject();
            obj.decision = true;

            //obj.leftTop.x = i;
            //obj.leftTop.y = j;
            //obj.size = size;
            //obj.color = c;
            obj.bBox = bBox;

            return obj;
        }