Exemple #1
0
        private void performOCR(FileInfo imageFile)
        {
            try
            {
                OCRHelper.PerformOCR(imageFile.FullName, Path.Combine(outputFolder, imageFile.Name + (hocr ? ".html" : ".txt")), curLangCode, selectedPSM, hocr);
            }
            catch
            {
                // Sets the UI culture to the selected language.
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedUILanguage);

                this.statusForm.TextBox.BeginInvoke(new UpdateStatusEvent(this.WorkerUpdate), new Object[] { "\t** " + Properties.Resources.Cannotprocess + imageFile.Name + " **" });
            }
        }
Exemple #2
0
        private void performOCR(FileInfo imageFile)
        {
            try
            {
                string outputFilename = imageFile.FullName.Substring(inputFolder.Length + 1);
                OCRHelper.PerformOCR(imageFile.FullName, Path.Combine(outputFolder, outputFilename + "." + outputFormat.Replace("+", string.Empty)), curLangCode, selectedPSM, outputFormat);
            }
            catch
            {
                // Sets the UI culture to the selected language.
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedUILanguage);

                this.statusForm.TextBox.BeginInvoke(new UpdateStatusEvent(this.WorkerUpdate), new Object[] { "\t** " + Properties.Resources.Cannotprocess + imageFile.Name + " **" });
            }
        }
Exemple #3
0
        private void AutoOCR()
        {
            FileInfo imageFile;

            try
            {
                imageFile = new FileInfo(queue.Dequeue());
                if (imageFile == null || !imageFile.Exists)
                {
                    return;
                }
            }
            catch
            {
                return;
            }

            this.statusForm.TextBox.BeginInvoke(new UpdateStatusEvent(this.WorkerUpdate), new Object[] { imageFile.FullName });

            if (curLangCode == null)
            {
                this.statusForm.TextBox.BeginInvoke(new UpdateStatusEvent(this.WorkerUpdate), new Object[] { "\t** " + Properties.Resources.selectLanguage + " **" });
                //queue.Clear();
                return;
            }

            try
            {
                OCRHelper.PerformOCR(imageFile.FullName, Path.Combine(outputFolder, imageFile.Name + (hocr ? ".html" : ".txt")), curLangCode, selectedPSM, hocr);
            }
            catch
            {
                // Sets the UI culture to the selected language.
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedUILanguage);

                this.statusForm.TextBox.BeginInvoke(new UpdateStatusEvent(this.WorkerUpdate), new Object[] { "\t** " + Properties.Resources.Cannotprocess + imageFile.Name + " **" });
            }
        }
Exemple #4
0
        void PerformOCR(string[] args)
        {
            if (args[0] == "-?" || args[0] == "-help" || args.Length == 1 || args.Length >= 8)
            {
                Console.WriteLine("Usage: vietocr imagefile outputfile [-l lang] [-psm pagesegmode] [hocr]");
                return;
            }

            string outputFormat = "txt";

            foreach (string arg in args)
            {
                if ("hocr" == arg)
                {
                    outputFormat = "hocr";
                }
                else if ("pdf" == arg)
                {
                    outputFormat = "pdf";
                }
                else if ("txt+" == arg)
                {
                    outputFormat = "txt+";
                }
            }

            FileInfo imageFile  = new FileInfo(args[0]);
            FileInfo outputFile = new FileInfo(args[1] + "." + outputFormat.Replace("+", string.Empty));

            if (!imageFile.Exists)
            {
                Console.WriteLine("Input file does not exist.");
                return;
            }

            string curLangCode = "eng"; //default language
            string psm         = "3";   // or alternatively, "Auto"; // 3 - Fully automatic page segmentation, but no OSD (default)

            if ((args.Length == 4) || (args.Length == 5))
            {
                if (args[2].Equals("-l"))
                {
                    curLangCode = args[3];
                }
                else if (args[2].Equals("-psm"))
                {
                    psm = args[3];
                }
            }
            else if ((args.Length == 6) || (args.Length == 7))
            {
                curLangCode = args[3];
                psm         = args[5];
                try
                {
                    Int16.Parse(psm);
                }
                catch
                {
                    Console.WriteLine("Invalid input value.");
                    return;
                }
            }

            try
            {
                OCRHelper.PerformOCR(imageFile.FullName, outputFile.FullName, curLangCode, psm, outputFormat);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }
        }
Exemple #5
0
        void PerformOCR(string[] args)
        {
            if (args[0] == "-?" || args[0] == "-help" || args.Length == 1 || args.Length >= 8)
            {
                Console.WriteLine("Usage: vietocr imagefile outputfile [-l lang] [-psm pagesegmode] [hocr]");
                return;
            }

            bool hocr = false;

            foreach (string arg in args)
            {
                if ("hocr" == arg)
                {
                    hocr = true;
                }
            }
            FileInfo imageFile  = new FileInfo(args[0]);
            FileInfo outputFile = new FileInfo(args[1] + (hocr ? ".html" : ".txt"));

            if (!imageFile.Exists)
            {
                Console.WriteLine("Input file does not exist.");
                return;
            }

            string curLangCode = "eng"; //default language
            string psm         = "3";   // or alternatively, "Auto"; // 3 - Fully automatic page segmentation, but no OSD (default)

            if ((args.Length == 4 && !hocr) || (args.Length == 5 && hocr))
            {
                if (args[2].Equals("-l"))
                {
                    curLangCode = args[3];
                }
                else if (args[2].Equals("-psm"))
                {
                    psm = args[3];
                }
            }
            else if ((args.Length == 6 && !hocr) || (args.Length == 7 && hocr))
            {
                curLangCode = args[3];
                psm         = args[5];
                try
                {
                    Int16.Parse(psm);
                }
                catch
                {
                    Console.WriteLine("Invalid input value.");
                    return;
                }
            }

            try
            {
                OCRHelper.PerformOCR(imageFile.FullName, outputFile.FullName, curLangCode, psm, hocr);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }
        }