Exemplo n.º 1
0
        internal string Run()
        {
            var fileName = @"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe";

            var img = Image.FromFile(targetLocation);
            var bmp = new Bitmap(img);

            StringBuilder sb = new StringBuilder();

            for (int j = 0; j < bmp.Height; j++)
            {
                var val = 0x0;
                for (int i = 0; i < bmp.Width; i++)
                {
                    var isBlack = SplitFile.Calculate(bmp.GetPixel(i, j));
                    if (isBlack)
                    {
                        val |= (isBlack ? 1 : 0);
                        val  = val << 1;
                    }
                }
                sb.Append(val.ToString("x4"));
            }

            var findValue = FindHashText(sb.ToString());

            if (findValue == null)
            {
                var p = Process.Start(new ProcessStartInfo(fileName, string.Format("{0} stdout -l chi_sim -psm 10", targetLocation))
                {
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    StandardOutputEncoding = Encoding.UTF8
                });

                var value = p.StandardOutput.ReadToEnd().Trim();
                p.WaitForExit();
                var newValue = new DicValue {
                    HashText = sb.ToString(), Location = targetLocation, Value = value
                };
                Insert(newValue);
                DbDictionary[newValue.HashText] = newValue.Value;
                Console.WriteLine(newValue.Value);
                return(value);
            }
            Console.WriteLine(findValue);
            return(findValue);
        }
Exemplo n.º 2
0
        internal void Insert(DicValue value)
        {
            try
            {
                var findValue = Context.Values.Find(value.HashText);

                if (findValue == null)
                {
                    Context.Values.Add(value);
                    Context.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }
        }