public static string RecognizeEmail(Image image)
{
var letters = new Dictionary<uint, string>
{
{1288792489, "" },
{1626703122, "@"},
{1769998881, "."},
{1493272944, "_"},
{3197976267, "-"},
{3909147509, "a"},
{376842207, "b"},
{1799116282, "c"},
{2498030206, "d"},
{2745527567, "e"},
{3608642261, "f"},
{3698512107, "g"},
{285210550, "h"},
{2592223230, "i"},
{3549459756, "j"},
{2839448178, "k"},
{2466444227, "l"},
{1337034184, "m"},
{1616237527, "n"},
{2276519761, "o"},
{1450716019, "p"},
{1107090806, "r"},
{3198435235, "s"},
{3016806566, "t"},
{4279155678, "u"},
{2627837479, "v"},
{3402494643, "x"},
{1314130073, "y"},
{3782604024, "z"},
{2465172642, "L"},
{1591944625, "M"},
{2427343186, "0"},
{1230207695, "1"},
{3381667143, "2"},
{3116171335, "3"},
{1264925335, "4"},
{2013810758, "5"},
{4015866205, "6"},
{448374844, "7"},
{3675590149, "8"},
{2806702695, "9"},
};
var answer = "";
var imgs = SplitImage(image, 9, 20);
foreach (var img in imgs)
{
var crc32 = Crc32(img);
if (letters.ContainsKey(crc32))
answer += letters[crc32];
else
{
answer += "?";
img.Save(crc32 + ".png", ImageFormat.Png);
}
}
return answer;
}
public static Image[] SplitImage(Image image, int width, int height)
{
var list = new List<Image>();
using (Bitmap bmpImage = new Bitmap(image))
{
for (int x = 0; x < image.Width / width; x++)
for (int y = 0; y < image.Height / height; y++)
list.Add(bmpImage.Clone(new Rectangle(x * width, y * height, width, height), bmpImage.PixelFormat));
return list.ToArray();
}
}
public static uint Crc32(Image image)
{
using (var m = new MemoryStream())
{
image.Save(m, ImageFormat.Bmp);
var source = m.ToArray();
var crc_table = new uint[256];
uint crc;
for (uint i = 0; i < 256; i++)
{
crc = i;
for (uint j = 0; j < 8; j++) crc = (crc & 1) != 0 ? (crc >> 1) ^ 0xEDB88320 : crc >> 1;
crc_table[i] = crc;
}
crc = 0xFFFFFFFF;
foreach (byte s in source) crc = crc_table[(crc ^ s) & 0xFF] ^ (crc >> 8);
crc ^= 0xFFFFFFFF;
return crc;
}
}