private void button1_Click(object sender, EventArgs e) { if (pictureBox1.ImageLocation == null) { string message = "Please drag image file to the top frame to continue..."; string caption = "Oops..."; MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result; result = MessageBox.Show(message, caption, buttons); } else { var Ocr = new IronTesseract(); using (var Input = new OcrInput(pictureBox1.ImageLocation)) //show in the window { var Result = Ocr.Read(Input); textBox1.Text = Result.Text; textBox1.ScrollBars = ScrollBars.Both; } using (var Input = new OcrInput(pictureBox1.ImageLocation)) //the text every line without withspace { string text = Ocr.Read(Input).Text; Calculate c = new Calculate(text); c.CalculateLanguage();// calculate the language } } }
public static string OCRcheck(int RectUpperLeftX, int RectUpperLeftY, int RectWith = 140, int RectHigh = 45, string Whitelist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ß! -%/äüöÄÜÖ") { Bitmap src = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height); // Create an empty bitmap with the size of all connected screen Graphics graphics = Graphics.FromImage(src as Image); // Create a new graphics objects that can capture the scree graphics.CopyFromScreen(SystemInformation.VirtualScreen.Left, SystemInformation.VirtualScreen.Top, 0, 0, src.Size); // Screenshot moment → screen content to graphics object FullsizeImage = src; Rectangle cropRect = new Rectangle(RectUpperLeftX, RectUpperLeftY, RectWith, RectHigh); Bitmap cropped = (Bitmap)src.Clone(cropRect, src.PixelFormat); cropped.Save("c:\\temp\\SrcTest.png"); var OCR = new IronTesseract(); OCR.Language = OcrLanguage.GermanFast; //OCR.Configuration.BlackListCharacters = "013456789"; OCR.Configuration.WhiteListCharacters = Whitelist; OCR.Configuration.ReadBarCodes = false; //OCR.Configuration.RenderSearchablePdfsAndHocr = false; string OCRText = OCR.Read(cropped).Text; if (OCRText == null || OCRText == "") { TransformedCropImage = Transform(cropped); TransformedCropImage.Save("c:\\temp\\SrcTestTransform.png"); OCR.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleChar; OCRText = OCR.Read(TransformedCropImage).Text; if (OCRText == "" || OCRText == null) { OCR.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd; Bitmap resizedCropped = new Bitmap(cropped.Width + cropped.Width + cropped.Width, cropped.Height); //creating empty Bitmap - 3times the Width of the cropped Image using (Graphics g = Graphics.FromImage(resizedCropped)) { g.DrawImage(cropped, 0, 0); //Adding Image 1 on pos 0,0 g.DrawImage(cropped, cropped.Width, 0); //Adding Image 2 on pos Image1.Witdh,0 g.DrawImage(cropped, cropped.Width + cropped.Width, 0); } resizedCropped.Save("c:\\temp\\SrcTestresizedCropped.png"); OCRText = OCR.Read(resizedCropped).Text; if (OCRText.Length == 6) { OCRText = OCRText.Substring(0, 2); } else if (OCRText.Length == 3) { OCRText = OCRText.Substring(0, 1); } } } log.Debug("OCR text: " + OCRText); LoopGarbageCollector.ClearGarbageCollector(); return(OCRText); }
private void exportToTextToolStripMenuItem_Click(object sender, EventArgs e) { try { StartExport(); var thread = new Thread(() => { var ocr = new IronTesseract(); ocr.SetLanguage((int)readComboBoxSelected(cbxLanguages)); using (Image img = (Image)picBox.Image?.Clone()) { if (img != null) { OcrInput ocrInput = new OcrInput(img); var text = ocr.Read(ocrInput).Text; txtRes.Invoke(new DisplayResultTextDelegate(DisplayResultText), text); } else { txtRes.Invoke(new DisplayResultTextDelegate(DisplayResultText), string.Empty); } } }); thread.IsBackground = true; thread.Start(); } catch (Exception ex) { EndExport(); MessageBox.Show(ex.Message, "Có lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async void DoAsyncOCR() { var image = Screenshot(Screen.AllScreens[(int)NUDDisplay.Value - 1]); IronTesseract IronOCR = new IronTesseract(); OcrResult Result = await Task.Run(() => IronOCR.Read(image)); var s = trimmer.Replace(Result.Text, " "); s = s.Replace(".", ""); string[] words = s.Split(' '); Console.WriteLine("Comparing Pokemon"); List <string> FoundPKMN = new List <string>(); foreach (var WordFromScreen in words.Where(x => !string.IsNullOrWhiteSpace(x))) { foreach (var PokemonName in PokemonData.getPokemonNames()) { double Simularity = CalculateSimilarity(WordFromScreen, PokemonName); if (Simularity >= (double)Tolerance && !FoundPKMN.Contains(PokemonName)) { FoundPKMN.Add(PokemonName); } } } FoundPKMN.Sort(); FoundPKMN.Reverse(); PrintResults(FoundPKMN); }
public void CaptureScreen() { //screenshot into png //string dir = AppDomain.CurrentDomain.BaseDirectory; Screenshot ps = new Screenshot(); Image i = ps.CaptureScreen(); //png into txt var Ocr = new IronTesseract(); string r = ""; using (var Input = new OcrInput(i)) { //TODO: this Read is having problems!! var Result = Ocr.Read(Input); r = Result.Text; } Console.WriteLine($"Result: {r}"); if (r.Contains("captcha") || r.Contains("Captcha")) { Stop(); Console.WriteLine("\nVerify detected, stopped all timers!"); } else { Console.WriteLine("\nNo Verify detected."); } }
static void ScanImageAndSaveTxt(string path) { var Ocr = new IronTesseract(); Ocr.Configuration.BlackListCharacters = "~`$#^*_}{][|\\@-©<>«="; Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract4; Ocr.Configuration.RenderSearchablePdfsAndHocr = true; Ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto; Ocr.Language = OcrLanguage.GermanBest; // var result = Ocr.Read(@"C:\Users\d4gei\Workspace\ScanAndHoardData\TestData\PXL_20201126_130717460.jpg"); //Console.WriteLine(result.Text); using (var Input = new OcrInput()) { Input.AddImage(path); Input.DeNoise(); //fixes digital noise Input.Deskew(); //fixes rotation and perspective // there are dozens more filters, but most users wont need them IronOcr.OcrResult Result = Ocr.Read(Input); Console.WriteLine(Result.Text); Result.SaveAsTextFile(path + ".txt"); Result.SaveAsHocrFile(path + ".html"); Result.SaveAsSearchablePdf(path + ".pdf"); } }
public BillOfLadingModel Read(IFormFile file) { var result = new BillOfLadingModel(); var ss = new StorageService(); var it = new IronTesseract(); //ss.Upload(file); try { using (var input = new OcrInput()) { input.AddPdf(file.OpenReadStream()); var oRes = it.Read(input); var words = oRes.Words; result.Transporter.BLNumber = words.GetBLNumber(); } } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine(e); } return(result); }
static void Main(string[] args) { Console.WriteLine("Loading files..."); var path = @"C:\Frelancing\ConsoleApp\OCR_Apps\IronOCR\Files\"; List <string> paths = Directory.EnumerateFiles(path, "*.pdf").ToList(); var searchableKeyCv = new List <string>(); foreach (string filePath in paths) { Console.WriteLine("Read File- " + filePath); Console.WriteLine("Start-" + DateTime.Now); var ocr = new IronTesseract(); using (var input = new OcrInput(filePath)) { var result = ocr.Read(input); var text = result.Text; if (text.Contains("React")) { searchableKeyCv.Add("React"); } //if (text.Contains("ETL")) // searchableKeyCv.Add("ETL"); Console.WriteLine("End-" + DateTime.Now); } } Console.WriteLine("Searchable Key Result-"); foreach (var item in searchableKeyCv) { Console.WriteLine(item); } Console.ReadKey(); }
/// <inheritdoc cref="IImageOcrReader"/> /// <summary> /// Reads the text on the given image. /// </summary> /// <param name="fileName">The file name.</param> /// <returns>The read <see cref="string"/>.</returns> /// <seealso cref="IImageOcrReader"/> public string ReadTextOnImage(string fileName) { var ocrHelper = new IronTesseract(); using var input = new OcrInput(fileName); input.Deskew(); input.DeNoise(); var result = ocrHelper.Read(input); return(result.Text); }
private void button2_Click(object sender, EventArgs e) { var Ocr = new IronTesseract(); using (var input = new OcrInput(fileName)) { input.Deskew(); var result = Ocr.Read(input); richTextBox1.Text = result.Text; } }
public static string IronOCR(string imagepath) // Iron_圖片辨識 { var Ocr = new IronTesseract(); using (var Input = new OcrInput(imagepath)) { Input.Deskew(); // use if image not straight Input.DeNoise(); // use if image contains digital noise var Result = Ocr.Read(Input); return(Result.Text); } }
static void Main(string[] args) { var Ocr = new IronTesseract(); using (var Input = new OcrInput()) { Input.AddMultiFrameTiff(@"C:\Users\hrust\Downloads\pic 3.jpg"); var Result = Ocr.Read(Input); Result.SaveAsSearchablePdf("searchable.pdf"); } }
private static ProcessedInvoice ProcessDocument(string path, IronTesseract ocr) { string text = ""; if (System.IO.Path.GetExtension(path) == ".pdf") { PdfReader reader = new PdfReader(path); text = PdfTextExtractor.GetTextFromPage(reader, 1); } else if (System.IO.Path.GetExtension(path) == ".docx") { var doc = DocX.Load(path); Headers h = doc.Headers; text = ""; if (h.Even != null && h.Even.Paragraphs != null) { foreach (Paragraph p in h.Even?.Paragraphs) { text += p.Text; } } if (h.Odd != null && h.Odd.Paragraphs != null) { foreach (Paragraph p in h.Odd?.Paragraphs) { text += p.Text; } } if (h.First != null && h.First.Paragraphs != null) { foreach (Paragraph p in h.First?.Paragraphs) { text += p.Text; } } text += doc.Text; Console.WriteLine(text); } else { text = ocr.Read(path).Text; } return(ProcessInvoice(text, path)); }
private void TranslateFileInnerEngener() { string file = FilePath.Text; // ☜ jpg, gif, tif, pdf, etc. PBOCR.Value = 30; //var Ocr = new IronOcr.AdvancedOcr(); try { //Ocr.CleanBackgroundNoise = true; //Ocr.EnhanceContrast = true; //Ocr.EnhanceResolution = true; //Ocr.Language = IronOcr.o OcrLanguagePack( // Languages.ChineseSimplified.OcrLanguagePack, // Languages.English.OcrLanguagePack //); //PBOCR.Value = 40; //Ocr.Strategy = IronOcr.AdvancedOcr.OcrStrategy.Advanced; //Ocr.ColorSpace = AdvancedOcr.OcrColorSpace.Color; //Ocr.DetectWhiteTextOnDarkBackgrounds = true; //Ocr.InputImageType = AdvancedOcr.InputTypes.AutoDetect; //Ocr.RotateAndStraighten = true; //Ocr.ReadBarCodes = true; //Ocr.ColorDepth = 4; //var testDocument = file; //PBOCR.Value = 45; //var Results = Ocr.Read(testDocument); //PBOCR.Value = 80; //ResultTest.Text = Results.Text; //PBOCR.Value = 90; var Ocr = new IronTesseract(); using (var Input = new OcrInput(file)) { Ocr.Language = OcrLanguage.EnglishBest; //Ocr.AddSecondaryLanguage(OcrLanguage.ChineseSimplified); // Input.Deskew(); // use if image not straight //Input.DeNoise(); // use if image contains digital noise var Result = Ocr.Read(Input); //Console.WriteLine(Result.Text); ResultTest.Text = Result.Text; } } catch (Exception) { ResultTest.Text = "本地引擎在分析是出错,请联系管理员!"; } PBOCR.Value = 100; }
public void ReadScreen(string image) { string result; var cr = new IronTesseract(); using (var input = new OcrInput(Imagepath + $"TeamGold\\{image}")) { input.DeNoise(); result = cr.Read(input).Text; } int index = 0; double gold = 0; char[] tmpGoldValue = result.ToCharArray(); char[] goldValue = new char[5]; foreach (char c in tmpGoldValue) { if (c != ' ') { goldValue[index] = c; index++; } } if (double.TryParse(goldValue[0].ToString() + goldValue[1].ToString(), out double resultV)) { gold += resultV; } if (double.TryParse(goldValue[3].ToString(), out double resultV2)) { gold += resultV2 / 10; } if (image == "GoldBlueTeam.png") { GoldBlue = gold; } else if (image == "GoldRedTeam.png") { GoldRed = gold; } }
public static string ConvertImgToText(Bitmap bt) { var Ocr = new IronTesseract(); // Fast Dictionary Ocr.Language = OcrLanguage.EnglishFast; // Latest Engine Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5; //AI OCR only without font analysis //Ocr.Configuration.EngineMode = TesseractEngineMode.LstmOnly; //Turn off unneeded options Ocr.Configuration.ReadBarCodes = false; Ocr.Configuration.RenderSearchablePdfsAndHocr = false; // Assume text is laid out neatly in an orthagonal document Ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto; using (var Input = new OcrInput(bt)) { var Result = Ocr.Read(Input); return(Result.Text); } }
private void btnTransform_Click(object sender, EventArgs e) { btnTransform.Enabled = false; var Ocr = new IronTesseract(); // Если выбран русский язык switch (cbLanguage.SelectedIndex) { case 0: Ocr.Language = OcrLanguage.EnglishBest; break; case 1: Ocr.Language = OcrLanguage.RussianBest; break; } using (var Input = new OcrInput(pbPic.Image)) { // Если изображение неровное if (chbAlign.Checked) { Input.Deskew(); } // Очистка шума if (chbNoise.Checked) { Input.DeNoise(); } var Result = Ocr.Read(Input); tbText.Text = Result.Text; } btnTransform.Enabled = true; }
private void readAndShow() { try { OcrResult res = Ocr.Read(getScreenImage()); string ocrText = res.Text; HSV hsv = new HSV(ocrText, 0, 0, 0, 0); button1.ForeColor = Color.LimeGreen; panel1.BackColor = Color.FromArgb(hsv.R, hsv.G, hsv.B); } catch (Exception) { panel1.BackColor = Color.Black; button1.ForeColor = Color.OrangeRed; return; } }
private async void Form1_Load(object sender, EventArgs e) { Aletorio = oRandom.Next(0, 9999); //MessageBox.Show(Aletorio.ToString()); //string urlCaptcha = "https://e-consultaruc.sunat.gob.pe/cl-ti-itmrconsmulruc/captcha?accion=image"; string urlCaptcha = string.Format("https://e-consultaruc.sunat.gob.pe/cl-ti-itmrconsruc/captcha?accion=image&nmagic={0}", Aletorio); try { HttpResponseMessage response = await client.GetAsync(urlCaptcha); response.EnsureSuccessStatusCode(); Stream oStream = await response.Content.ReadAsStreamAsync(); //byte[] oMemoryStream = await response.Content.ReadAsByteArrayAsync(); Image oImage = Image.FromStream(oStream); var oCr = new IronTesseract(); using (var Input = new OcrInput(oImage)) { var Results = oCr.Read(Input); txtCaptcha.Text = Results.Text.Trim(); } pbImagen.Image = oImage; //var OcrEngine = new TesseractEngine("","eng", EngineMode.Default); //var img = Pix.LoadFromMemory(oMemoryStream); //var res = OcrEngine.Process(img); //txtCaptcha.Text = res.GetText(); } catch (HttpRequestException ex) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", ex.Message); } }
private void performReadAndSave() { try { OcrResult res = Ocr.Read(getScreenImage()); string ocrText = res.Text; int x = currentCell.ColumnIndex + 1; int y = 16 - currentCell.RowIndex; labelCol.Text = "X: " + x; labelRow.Text = "Y: " + y; HSV hsv = new HSV(ocrText, x, y, Gain, Value); label26.ForeColor = Color.LimeGreen; label26.Text = "OK"; label1.Text = hsv.H.ToString("N3"); label2.Text = hsv.S.ToString("N3"); label3.Text = hsv.V.ToString("N2"); label25.Text = hsv.R.ToString(); label24.Text = hsv.G.ToString(); label23.Text = hsv.B.ToString(); HSVSerializer.registerHSV(hsv); panel3.BackColor = Color.FromArgb(hsv.R, hsv.G, hsv.B); if (ForcedH || ForcedS || ForcedV) { double h = ForcedH ? (double)numericUpDownH.Value : hsv.H; double s = ForcedS ? (double)numericUpDownS.Value : hsv.S; double v = ForcedV ? (double)numericUpDownV.Value : hsv.V; table.Rows[16 - hsv.Y].Cells[hsv.X - 1].Style.BackColor = HSV.ColorFromHSV(h, s, v); } else { table.Rows[16 - hsv.Y].Cells[hsv.X - 1].Style.BackColor = Color.FromArgb(hsv.R, hsv.G, hsv.B); } table_SelectionChanged(null, null); } catch (Exception) { label26.ForeColor = Color.Red; label26.Text = "Failed"; label1.Text = label2.Text = label3.Text = label25.Text = label24.Text = label23.Text = "???"; panel3.BackColor = Color.Transparent; return; } //string R = ocrText.Substring(30, 6).Replace('.', ','); //string G = ocrText.Substring(40, 6).Replace('.', ','); //string B = ocrText.Substring(50, 6).Replace('.', ','); //double r = Math.Round(double.Parse(R), 3); //double g = Math.Round(double.Parse(G), 3); //double b = Math.Round(double.Parse(B), 3); //label25.Text = "R: " + R; //label24.Text = "G: " + G; //label23.Text = "B: " + B; }