Esempio n. 1
0
        public static CharBitmapProperty characterExtraction(ref Bitmap input, Range xrange, Range yrange)
        {
            int x0 = xrange.Item1;
            int x1 = xrange.Item2;
            int y0 = yrange.Item1;
            int y1 = yrange.Item2;

            // TODO: 'b', 'd' , 'f' are taller than normal number char
            //       If number digits are at the same line as 'b', 'd', 'f',
            //       their bitmap would have one more line of bits.
            //       Try to ignore this line by post processing the y0 line.
            while (true)
            {
                bool all0 = true;
                for (int i = x0; i < x1; i++)
                {
                    if (rgb2gray(input.GetPixel(i, y0)) != 0)
                    {
                        all0 = false;
                        break;
                    }
                }
                if (all0)
                {
                    y0 = y0 + 1;
                }
                else {
                    break;
                }
            }

            int xm = (x1 + x0) / 2;
            int ym = (y1 + y0) / 2;

            //
            //  00 01
            //  10 11
            //
            int score00 = 0;
            int score01 = 0;
            int score10 = 0;
            int score11 = 0;

            for (int x = x0; x < xm; x++)
            {
                for (int y = y0; y < ym; y++)
                {
                    score00 += rgb2gray(input.GetPixel(x, y));
                }
            }
            for (int x = xm; x < x1; x++)
            {
                for (int y = y0; y < ym; y++)
                {
                    score01 += rgb2gray(input.GetPixel(x, y));
                }
            }
            for (int x = x0; x < xm; x++)
            {
                for (int y = ym; y < y1; y++)
                {
                    score10 += rgb2gray(input.GetPixel(x, y));
                }
            }
            for (int x = xm; x < x1; x++)
            {
                for (int y = ym; y < y1; y++)
                {
                    score11 += rgb2gray(input.GetPixel(x, y));
                }
            }

            score00 = score00 / ((xm - x0) * (ym - y0));
            score01 = score01 / ((x1 - xm) * (ym - y0));
            score10 = score10 / ((xm - x0) * (y1 - ym));
            score11 = score11 / ((x1 - xm) * (y1 - ym));

            // debug
            // dumpBitmap(ref input, xrange, yrange);

            int total = score00 + score01 + score10 + score11;
            int[] tempA = { total, score00, score01, score10, score11 };

            CharBitmapProperty t = new CharBitmapProperty(tempA);
            // Console.WriteLine(t.ToString());

            return t;
        }
Esempio n. 2
0
        // TODO:
        public char charRecognition(CharBitmapProperty t)
        {
            char result = '?';
            int best_score = int.MaxValue;
            for (int i = 0; i < myDB.Count; i++)
            {
                CharBitmapProperty tmp = t - myDB[i].Item1;
                int theScore = tmp.magnitude();

                if (theScore < best_score)
                {
                    result = myDB[i].Item2;
                    best_score = theScore;
                }
            }
            return result;
        }