protected void PrepareDigitHash(string digitFilePath, string digitName) { var test = new Bitmap(digitFilePath); //var ms = new MemoryStream(digitImgBytes); var ms = new MemoryStream(); test.Save(ms, System.Drawing.Imaging.ImageFormat.Png); var bytes = ms.ToArray(); var hash = 0; using (var stream = new MemoryStream(bytes)) hash = MurMurHash3.Hash(stream); //DigitHash.Add(hash, digitName); }
protected string RecognizeDigit(Bitmap phoneImg, int startX, int finishX) //string { // Get subImage which corresponds to specified image block var rect = new Rectangle { X = startX, Y = MinY, Width = finishX - startX, Height = MaxY - MinY + 1 }; var img = phoneImg.Clone(rect, phoneImg.PixelFormat); //var ms = new MemoryStream(digitImgBytes); var ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //img.Save(@"C:\result\first.png"); var bytes = ms.ToArray(); var hash = 0; using (var stream = new MemoryStream(bytes)) hash = MurMurHash3.Hash(stream); string result; DigitHash.TryGetValue(hash, out result); return(result); // // Convert subImage to array of bytes // ByteArrayOutputStream baos = new ByteArrayOutputStream(); // ImageIO.write(img, "jpg", baos); //byte[] bytes = baos.toByteArray(); // // Calculate hash of subImage // Long hash = Murmur3.hash_x86_32(bytes, bytes.length, HASH_SEED); //// Return string of digit which corresponds to specified hash //return digitHash.get(hash); }