internal List<ConnectedPixel> GetConnectedPixel(Bitmap bitmap, Dictionary<short, List<PixelPoint>> dicPixelPointConncected)
 {
     byte[] numArray;
       int num;
       int num1;
       ImageLabeling.GetRgbArrayFromImage(bitmap, out numArray, out num, out num1);
       List<ConnectedPixel> connectedPixels = new List<ConnectedPixel>();
       short width = (short)(bitmap.Width * 3);
       CharacterPixel characterPixel = new CharacterPixel();
       CharacterInfo characterInfo = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Bold));
       CharacterInfo characterInfo1 = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Normal));
       characterPixel.m_characterInfo.RemoveAll((CharacterInfo x) => (x == characterInfo ? false : x != characterInfo1));
       foreach (KeyValuePair<short, List<PixelPoint>> keyValuePair in dicPixelPointConncected)
       {
     if (keyValuePair.Value.Count <= 4000)
     {
       keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.YCor.CompareTo(sObject2.YCor));
       PixelPoint pixelPoint = keyValuePair.Value.FirstOrDefault<PixelPoint>();
       int yCor = pixelPoint.YCor;
       pixelPoint = keyValuePair.Value.LastOrDefault<PixelPoint>();
       int yCor1 = pixelPoint.YCor;
       keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.XCor.CompareTo(sObject2.XCor));
       pixelPoint = keyValuePair.Value.FirstOrDefault<PixelPoint>();
       int xCor = pixelPoint.XCor;
       pixelPoint = keyValuePair.Value.LastOrDefault<PixelPoint>();
       int xCor1 = pixelPoint.XCor;
       pixelPoint = keyValuePair.Value.First<PixelPoint>();
       int yCor2 = pixelPoint.YCor * width; // was short why?
       pixelPoint = keyValuePair.Value.First<PixelPoint>();
       int xCor2 = yCor2 + pixelPoint.XCor * 3;
       pixelPoint = keyValuePair.Value.First<PixelPoint>();
       int num2 = xCor2 + pixelPoint.YCor * num1;
       short num3 = (short)(xCor1 - xCor + 1);
       short num4 = (short)(yCor1 - yCor + 1);
       ConnectedPixel connectedPixel = new ConnectedPixel()
       {
     m_pixelCoordinate = new bool[num3, num4]
       };
       PxColor pxColor = new PxColor()
       {
     R = numArray[num2 + 2],
     G = numArray[num2 + 1],
     B = numArray[num2]
       };
       connectedPixel.m_color = pxColor;
       connectedPixel.m_height = num4;
       connectedPixel.m_width = num3;
       connectedPixel.m_topYCor = (short)yCor;
       connectedPixel.m_bottomYCor = (short)yCor1;
       connectedPixel.m_leftXCor = (short)xCor;
       connectedPixel.m_rightXCor = (short)xCor1;
       ConnectedPixel connectedPixel1 = connectedPixel;
       ConnectedCoordinate.CheckSpecialSeperatedDotCharacter(connectedPixel1, connectedPixels, characterInfo, characterInfo1, keyValuePair);
       ConnectedCoordinate.GetbackgroundColor(connectedPixel1, ref numArray, width, num1);
       connectedPixels.Add(connectedPixel1);
     }
       }
       return connectedPixels;
 }
        internal List <ConnectedPixel> GetConnectedPixel(Bitmap bitmap, Dictionary <short, List <PixelPoint> > dicPixelPointConncected)
        {
            byte[] numArray;
            int    num;
            int    num1;

            ImageLabeling.GetRgbArrayFromImage(bitmap, out numArray, out num, out num1);
            List <ConnectedPixel> connectedPixels = new List <ConnectedPixel>();
            short          width          = (short)(bitmap.Width * 3);
            CharacterPixel characterPixel = new CharacterPixel();
            CharacterInfo  characterInfo  = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Bold));
            CharacterInfo  characterInfo1 = characterPixel.m_characterInfo.Find((CharacterInfo x) => (x.CharacterDirection != Direction.Horizontal || x.Character != 'i' ? false : x.m_fontWeight == FontWeight.Normal));

            characterPixel.m_characterInfo.RemoveAll((CharacterInfo x) => (x == characterInfo ? false : x != characterInfo1));
            foreach (KeyValuePair <short, List <PixelPoint> > keyValuePair in dicPixelPointConncected)
            {
                if (keyValuePair.Value.Count <= 4000)
                {
                    keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.YCor.CompareTo(sObject2.YCor));
                    PixelPoint pixelPoint = keyValuePair.Value.FirstOrDefault <PixelPoint>();
                    int        yCor       = pixelPoint.YCor;
                    pixelPoint = keyValuePair.Value.LastOrDefault <PixelPoint>();
                    int yCor1 = pixelPoint.YCor;
                    keyValuePair.Value.Sort((PixelPoint sObject1, PixelPoint sObject2) => sObject1.XCor.CompareTo(sObject2.XCor));
                    pixelPoint = keyValuePair.Value.FirstOrDefault <PixelPoint>();
                    int xCor = pixelPoint.XCor;
                    pixelPoint = keyValuePair.Value.LastOrDefault <PixelPoint>();
                    int xCor1 = pixelPoint.XCor;
                    pixelPoint = keyValuePair.Value.First <PixelPoint>();
                    int yCor2 = pixelPoint.YCor * width; // was short why?
                    pixelPoint = keyValuePair.Value.First <PixelPoint>();
                    int xCor2 = yCor2 + pixelPoint.XCor * 3;
                    pixelPoint = keyValuePair.Value.First <PixelPoint>();
                    int            num2           = xCor2 + pixelPoint.YCor * num1;
                    short          num3           = (short)(xCor1 - xCor + 1);
                    short          num4           = (short)(yCor1 - yCor + 1);
                    ConnectedPixel connectedPixel = new ConnectedPixel()
                    {
                        m_pixelCoordinate = new bool[num3, num4]
                    };
                    PxColor pxColor = new PxColor()
                    {
                        R = numArray[num2 + 2],
                        G = numArray[num2 + 1],
                        B = numArray[num2]
                    };
                    connectedPixel.m_color      = pxColor;
                    connectedPixel.m_height     = num4;
                    connectedPixel.m_width      = num3;
                    connectedPixel.m_topYCor    = (short)yCor;
                    connectedPixel.m_bottomYCor = (short)yCor1;
                    connectedPixel.m_leftXCor   = (short)xCor;
                    connectedPixel.m_rightXCor  = (short)xCor1;
                    ConnectedPixel connectedPixel1 = connectedPixel;
                    ConnectedCoordinate.CheckSpecialSeperatedDotCharacter(connectedPixel1, connectedPixels, characterInfo, characterInfo1, keyValuePair);
                    ConnectedCoordinate.GetbackgroundColor(connectedPixel1, ref numArray, width, num1);
                    connectedPixels.Add(connectedPixel1);
                }
            }
            return(connectedPixels);
        }
Example #3
0
        internal Dictionary <short, List <PixelPoint> > GetImageLabel(Bitmap bitmap)
        {
            byte[] numArray;
            int    num;
            int    num1;
            short  i;
            short  j;
            short  num2;

            ImageLabeling.GetRgbArrayFromImage(bitmap, out numArray, out num, out num1);
            List <PixelPoint> pixelPoints = new List <PixelPoint>()
            {
                new PixelPoint(-1, -1),
                new PixelPoint(0, -1),
                new PixelPoint(1, -1),
                new PixelPoint(-1, 0),
                new PixelPoint(1, 0),
                new PixelPoint(-1, 1),
                new PixelPoint(0, 1),
                new PixelPoint(1, 1)
            };
            List <PixelPoint> pixelPoints1 = pixelPoints;
            short             width        = (short)(bitmap.Width * 3);

            short[,] numArray1 = new short[bitmap.Width, bitmap.Height];
            short num3 = 1;
            Dictionary <short, List <short> > nums = new Dictionary <short, List <short> >();

            for (i = 1; i < bitmap.Height - 1; i = (short)(i + 1))
            {
                for (j = 3; j < bitmap.Width - 3; j = (short)(j + 1))
                {
                    List <short> nums1     = new List <short>();
                    int          num4      = i * width + j * 3 + i * num1;
                    byte[]       numArray2 = new byte[] { numArray[num4 + 2], numArray[num4 + 1], numArray[num4] };
                    byte[]       numArray3 = numArray2;
                    PxColor      pxColor   = new PxColor()
                    {
                        R = numArray3[0],
                        G = numArray3[1],
                        B = numArray3[2]
                    };
                    num2 = 32767;
                    List <PixelPoint> .Enumerator enumerator = pixelPoints1.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        PixelPoint current = enumerator.Current;
                        short      yCor    = (short)(current.YCor + i);
                        short      xCor    = (short)(current.XCor + j);
                        int        num5    = yCor * width + xCor * 3 + yCor * num1;
                        numArray2 = new byte[] { numArray[num5 + 2], numArray[num5 + 1], numArray[num5] };
                        byte[] numArray4 = numArray2;
                        if ((numArray3[0] != numArray4[0] || numArray3[1] != numArray4[1] ? false : numArray3[2] == numArray4[2]))
                        {
                            if ((numArray1[xCor, yCor] == 0 ? false : !nums1.Contains(numArray1[xCor, yCor])))
                            {
                                num2 = Math.Min(num2, numArray1[xCor, yCor]);
                                nums1.Add(numArray1[xCor, yCor]);
                            }
                        }
                    }
                    if (num2 == 32767)
                    {
                        short num6 = num3;
                        num3 = (short)(num6 + 1);
                        num2 = num6;
                    }
                    numArray1[j, i] = num2;
                    if (!nums.ContainsKey(num2))
                    {
                        nums.Add(num2, new List <short>());
                    }
                    foreach (short num7 in nums1)
                    {
                        if (!nums[num2].Contains(num7))
                        {
                            nums[num2].Add(num7);
                        }
                        if (!nums.ContainsKey(num7))
                        {
                            nums.Add(num7, new List <short>());
                        }
                        if (!nums[num7].Contains(num2))
                        {
                            nums[num7].Add(num2);
                        }
                    }
                }
            }
            Dictionary <short, short> nums2 = ImageLabeling.RecordEquailance(nums, num3);

            nums.Clear();
            Dictionary <short, List <PixelPoint> > nums3 = new Dictionary <short, List <PixelPoint> >();

            for (i = 0; i < bitmap.Height; i = (short)(i + 1))
            {
                for (j = 0; j < bitmap.Width; j = (short)(j + 1))
                {
                    num2 = (nums2.ContainsKey(numArray1[j, i]) ? nums2[numArray1[j, i]] : numArray1[j, i]);
                    if (!nums3.ContainsKey(num2))
                    {
                        nums3.Add(num2, new List <PixelPoint>());
                    }
                    nums3[num2].Add(new PixelPoint(j, i));
                }
            }
            return(nums3);
        }
 internal Dictionary<short, List<PixelPoint>> GetImageLabel(Bitmap bitmap)
 {
     byte[] numArray;
       int num;
       int num1;
       short i;
       short j;
       short num2;
       ImageLabeling.GetRgbArrayFromImage(bitmap, out numArray, out num, out num1);
       List<PixelPoint> pixelPoints = new List<PixelPoint>()
     {
         new PixelPoint(-1, -1),
         new PixelPoint(0, -1),
         new PixelPoint(1, -1),
         new PixelPoint(-1, 0),
         new PixelPoint(1, 0),
         new PixelPoint(-1, 1),
         new PixelPoint(0, 1),
         new PixelPoint(1, 1)
     };
       List<PixelPoint> pixelPoints1 = pixelPoints;
       short width = (short)(bitmap.Width * 3);
       short[,] numArray1 = new short[bitmap.Width, bitmap.Height];
       short num3 = 1;
       Dictionary<short, List<short>> nums = new Dictionary<short, List<short>>();
       for (i = 1; i < bitmap.Height - 1; i = (short)(i + 1))
       {
     for (j = 3; j < bitmap.Width - 3; j = (short)(j + 1))
     {
       List<short> nums1 = new List<short>();
       int num4 = i * width + j * 3 + i * num1;
       byte[] numArray2 = new byte[] { numArray[num4 + 2], numArray[num4 + 1], numArray[num4] };
       byte[] numArray3 = numArray2;
       PxColor pxColor = new PxColor()
       {
     R = numArray3[0],
     G = numArray3[1],
     B = numArray3[2]
       };
       num2 = 32767;
       List<PixelPoint>.Enumerator enumerator = pixelPoints1.GetEnumerator();
       while (enumerator.MoveNext())
       {
     PixelPoint current = enumerator.Current;
     short yCor = (short)(current.YCor + i);
     short xCor = (short)(current.XCor + j);
     int num5 = yCor * width + xCor * 3 + yCor * num1;
     numArray2 = new byte[] { numArray[num5 + 2], numArray[num5 + 1], numArray[num5] };
     byte[] numArray4 = numArray2;
     if ((numArray3[0] != numArray4[0] || numArray3[1] != numArray4[1] ? false : numArray3[2] == numArray4[2]))
     {
       if ((numArray1[xCor, yCor] == 0 ? false : !nums1.Contains(numArray1[xCor, yCor])))
       {
         num2 = Math.Min(num2, numArray1[xCor, yCor]);
         nums1.Add(numArray1[xCor, yCor]);
       }
     }
       }
       if (num2 == 32767)
       {
     short num6 = num3;
     num3 = (short)(num6 + 1);
     num2 = num6;
       }
       numArray1[j, i] = num2;
       if (!nums.ContainsKey(num2))
       {
     nums.Add(num2, new List<short>());
       }
       foreach (short num7 in nums1)
       {
     if (!nums[num2].Contains(num7))
     {
       nums[num2].Add(num7);
     }
     if (!nums.ContainsKey(num7))
     {
       nums.Add(num7, new List<short>());
     }
     if (!nums[num7].Contains(num2))
     {
       nums[num7].Add(num2);
     }
       }
     }
       }
       Dictionary<short, short> nums2 = ImageLabeling.RecordEquailance(nums, num3);
       nums.Clear();
       Dictionary<short, List<PixelPoint>> nums3 = new Dictionary<short, List<PixelPoint>>();
       for (i = 0; i < bitmap.Height; i = (short)(i + 1))
       {
     for (j = 0; j < bitmap.Width; j = (short)(j + 1))
     {
       num2 = (nums2.ContainsKey(numArray1[j, i]) ? nums2[numArray1[j, i]] : numArray1[j, i]);
       if (!nums3.ContainsKey(num2))
       {
     nums3.Add(num2, new List<PixelPoint>());
       }
       nums3[num2].Add(new PixelPoint(j, i));
     }
       }
       return nums3;
 }