Ejemplo n.º 1
0
        public static string Recognize(string path)
        {
            var bytes        = File.ReadAllBytes(path);
            var source_image = System.Drawing.Bitmap.FromStream(new MemoryStream(bytes));
            //var image = Invert((Bitmap)source_image);
            var image       = source_image;
            var tmpFilename = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".ppm");

            try
            {
                PNM.WritePNM(tmpFilename, image);
                var process = Process.Start(new ProcessStartInfo(@"p:\Tools\gOcr\gocr049.exe", "-f XML " + tmpFilename)
                {
                    UseShellExecute = false, RedirectStandardOutput = true
                });
                var output = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                return(output);
            }
            finally
            {
                if (File.Exists(tmpFilename))
                {
                    File.Delete(tmpFilename);
                }
            }
        }