public ActionResult UploadFile(HttpPostedFileBase file) { try { var Ocr = new AutoOcr(); string extension = Path.GetExtension(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/App_Data/Files"), file.FileName)); string filepath = Path.Combine(Server.MapPath("~/App_Data/Files"), file.FileName); if (extension == ".jpg" || extension == ".png") { var Result = Ocr.Read(filepath); WritingContentsToFile(file, Result.Text); // ViewBag.message = Result.Text; } if (extension == ".pdf") { var Results = Ocr.ReadPdf(filepath); var Barcodes = Results.Barcodes; var Text = Results.Text; WritingContentsToFile(file, Results.Text); } return(View("Index")); }catch (Exception e) { return(null); } }
public string GetEpisodeText(Bitmap bmp) { var Ocr = new AutoOcr(); var Result = Ocr.Read(bmp); return(Result.Text); }
public override string ReadText() { var ocrReader = new AutoOcr(); var Result = ocrReader.Read(AppSettingsReader.ImagePath); return(Result.Text); }
private void extractText(object sender, EventArgs e) { var ocr = new AutoOcr(); result_text.Text = ocr.Read(image).ToString(); //axAcroPDF1.Dispose(); }
public static string ParseFile(string anyFilePath) { var Ocr = new AutoOcr(); var Result = Ocr.Read(anyFilePath); return(Result.Text); }
public void SaveSelection(bool showCursor) { Point curPos = new Point(Cursor.Position.X - CurrentTopLeft.X, Cursor.Position.Y - CurrentTopLeft.Y); Size curSize = new Size(); curSize.Height = Cursor.Current.Size.Height; curSize.Width = Cursor.Current.Size.Width; ScreenPath = ""; if (!ScreenShot.saveToClipboard) { saveFileDialog1.DefaultExt = "jpg"; saveFileDialog1.Filter = "jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|tiff files (*.tiff)|*.tiff|png files (*.png)|*.png"; saveFileDialog1.Title = "Save screenshot to..."; saveFileDialog1.ShowDialog(); ScreenPath = saveFileDialog1.FileName; } if (ScreenPath != "" || ScreenShot.saveToClipboard) { //Allow 250 milliseconds for the screen to repaint itself (we don't want to include this form in the capture) System.Threading.Thread.Sleep(250); Point StartPoint = new Point(CurrentTopLeft.X, CurrentTopLeft.Y); Rectangle bounds = new Rectangle(CurrentTopLeft.X, CurrentTopLeft.Y, CurrentBottomRight.X - CurrentTopLeft.X, CurrentBottomRight.Y - CurrentTopLeft.Y); string fi = ""; if (ScreenPath != "") { fi = new FileInfo(ScreenPath).Extension; } ScreenShot.CaptureImage(showCursor, curSize, curPos, StartPoint, Point.Empty, bounds, ScreenPath, fi); if (ScreenShot.saveToClipboard) { MessageBox.Show("Area saved to clipboard", "ScreenScapping", MessageBoxButtons.OK); } else { var Ocr = new AutoOcr(); var Result = Ocr.Read(ScreenPath); MessageBox.Show(Result.Text); // MessageBox.Show("Area saved to file", "ScreenScapping", MessageBoxButtons.OK); } this.InstanceRef.Show(); this.Close(); } else { MessageBox.Show("File save cancelled", "ScreenScapping", MessageBoxButtons.OK); this.InstanceRef.Show(); this.Close(); } }
/// <summary> /// Handles the Click event of the ConvertToText button control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnConvertToText_Click(object sender, EventArgs e) { try { lblStatus.Text = string.Empty; rtcText.Text = string.Empty; //// https://www.cmarix.com/git/DotNet/OCR-ImageToText-Example/Sample_1.tiff AutoOcr autoOcr = new AutoOcr(); Image inputImage = this.GetImageFromURI(tbInputURL.Text); string inputFileName = this.GetFileNameURI(tbInputURL.Text); var result = autoOcr.Read(inputImage); if (result != null) { lblStatus.Text = "Sucess : File name -" + inputFileName; rtcText.Text = result.Text; } else { lblStatus.Text = "Error : Sorry!! we are not getting any response from the library..."; } } catch (Exception ex) { lblStatus.Text = "Error : " + ex.Message; } }
public IActionResult Index([FromForm] IronOcr model) { var Ocr = new AutoOcr(); var Result = Ocr.Read(model.Image.FileName); return(Ok()); }
private void scanButton_Click(object sender, EventArgs e) { AutoOcr ocr = new AutoOcr(); var result = ocr.Read(inputImageTextbox.Text); outputTextbox.Text = result.ToString(); }
private void btnText_Click(object sender, EventArgs e) { var orc = new AutoOcr(); var result = orc.Read(pictureBox1.Image); richTextBox1.Text = result.Text; }
public List <File> GetFilesInfo(List <string> Files, string folderPath) { var Ocr = new AutoOcr(); int i = 0; System.IO.StreamWriter errorLog = new System.IO.StreamWriter("error.txt", true); var fileList = new List <File>(); foreach (var file in Files) { try { File theFile = new File(); var Result = Ocr.Read(folderPath + @"\" + file.ToString()); theFile.Id = Files.IndexOf(file); theFile.FileName = file.ToString(); theFile.OCRData = Result.Text; fileList.Add(theFile); } catch (Exception ex) { errorLog.WriteLine(ex); } i++; } return(fileList); }
public void cropImage_ConvertMulti(List <OCRModel.Position> CropPos, List <string> imagePath, string name, List <int> formID, int totalpage) { OCRModel imgpath = new OCRModel(); OCRModel obj = new OCRModel(); var CropRes = new List <OCRModel.CropResult>(); int i = 0; string croppath = ""; Bitmap croppedImage; for (int j = 1; j <= totalpage; j++) { i = 0; for (i = 0; i < CropPos.Count; i++) { if (j == CropPos[i].page) { j--; // Here we capture the resource - image file. using (var originalImage = new Bitmap(imagePath[j])) { //Set Position {x1,y1,width,height} Rectangle crop = new Rectangle(CropPos[i].pos_X1, CropPos[i].pos_Y1, CropPos[i].pos_width, CropPos[i].pos_height); // Here we capture another resource. croppedImage = originalImage.Clone(crop, originalImage.PixelFormat); }// Here we release the original resource - bitmap in memory and file on disk. // At this point the file on disk already free - you can record to the same path. //croppedImage.Save(@"C:\Users\kazarboys\Source\Repos\How-to-use-tesseract-ocr-4.0-with-csharp\tesseract-master.1153\samples\crop.jpg", ImageFormat.Jpeg); croppath = Path.Combine(Server.MapPath("~/Images/Crop"), name + "" + formID[j] + "_crop_" + i + ".jpg"); croppedImage.Save(croppath, ImageFormat.Jpeg); var Ocr = new AutoOcr(); var OcrResult = Ocr.Read(croppath); Console.WriteLine(OcrResult.Text); //string Crop_Text = OcrResult.Text.Replace("\r\n", "\\r\\n"); CropRes.Add(new OCRModel.CropResult { FormID_Key = formID[j], Crop_Imgpath = croppath.ToString(), Crop_Text = OcrResult.ToString().Replace("\r\n", "\\r\\n") }); // It is desirable release this resource too. croppedImage.Dispose(); j++; } } } //Insert CropImage to DB imgpath.InsertCropResult(CropRes); }
public void SaveSelection(bool showCursor) { try { Point curPos = new Point(Cursor.Position.X - CurrentTopLeft.X, Cursor.Position.Y - CurrentTopLeft.Y); Size curSize = new Size(); curSize.Height = Cursor.Current.Size.Height; curSize.Width = Cursor.Current.Size.Width; ScreenPath = ""; saveFileDialog1.DefaultExt = "png"; saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp|jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|tiff files (*.tiff)|*.tiff|png files (*.png)|*.png"; saveFileDialog1.Title = "Save screenshot to..."; if (saveSCreenShot) { saveFileDialog1.ShowDialog(); ScreenPath = saveFileDialog1.FileName; } else { ScreenPath = "Temp.png"; } Point StartPoint = new Point(CurrentTopLeft.X, CurrentTopLeft.Y); Rectangle bounds = new Rectangle(CurrentTopLeft.X, CurrentTopLeft.Y, CurrentBottomRight.X - CurrentTopLeft.X, CurrentBottomRight.Y - CurrentTopLeft.Y); string fi = ""; if (ScreenPath != "") { fi = new FileInfo(ScreenPath).Extension; } ScreenShot.CaptureImage(showCursor, curSize, curPos, StartPoint, Point.Empty, bounds, ScreenPath, fi); //MessageBox.Show("Area saved to file", "ScreenCapture", MessageBoxButtons.OK); AutoOcr OCR = new AutoOcr() { ReadBarCodes = false }; var Results = OCR.Read("Temp.png"); //MessageBox.Show(Results.Text); //Clipboard.SetText(Results.Text, TextDataFormat.Text); ReadTextPanel rtp = new ReadTextPanel(); rtp.setText(Results.Text); rtp.Show(); this.InstanceRef.Show(); this.Close(); } catch (Exception) { this.InstanceRef.Show(); this.Close(); } }
public MainForm() { InitializeComponent(); _ocr = new AutoOcr(); // 强制初始化OCR var img = new Bitmap(1, 1); _ocr.Read(img); }
private void Button_Click(object sender, RoutedEventArgs e) { AutoOcr OCR = new AutoOcr() { ReadBarCodes = false }; var Results = OCR.Read(@"C:\Users\mdani\Documents\SharedScreenshot.jpg"); MessageBox.Show(Results.Text); }
public ImageToText(string path) { if (File.Exists(path) == false) { throw new FileNotFoundException(); } _min = 1 - _accuracy; _max = 1 + _accuracy; _bitmap = new Bitmap(path); _ocr = new AutoOcr(); }
/// <summary> /// function recognize text from image /// </summary> /// <param name="bitmap"></param> /// <returns></returns> public static string Recognize(int Xmin, int Ymin, int Xmax, int Ymax) { Bitmap bmpScreenshot = Screenshot(Xmin, Ymin, Xmax, Ymax); bmpScreenshot = ExtractText(bmpScreenshot); var Ocr = new AutoOcr(); string outString = Ocr.Read(bmpScreenshot).ToString(); outString = outString.ToLower(); return(outString); }
private void Process_Button_Click(object sender, RoutedEventArgs e) { string str_Selected_Language; if (path_File == null || path_File == "" || cmb_SelectLanguage.SelectedIndex == 0) { MessageBox.Show(" File or Langauge not selected "); } else { ComboBoxItem Selected_Language = (ComboBoxItem)cmb_SelectLanguage.SelectedItem; str_Selected_Language = Selected_Language.Content.ToString(); //Duration duration = new Duration(TimeSpan.FromSeconds(20)); //DoubleAnimation doubleanimation = new DoubleAnimation(150.0, duration); //PBar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); switch (str_Selected_Language) { case "Hebrew": { var Ocr_Hebrew = new AdvancedOcr() { CleanBackgroundNoise = true, EnhanceContrast = true, EnhanceResolution = true, Language = IronOcr.Languages.Hebrew.OcrLanguagePack, //Language = IronOcr.Languages.English.OcrLanguagePack, Strategy = IronOcr.AdvancedOcr.OcrStrategy.Advanced, ColorSpace = AdvancedOcr.OcrColorSpace.Color, DetectWhiteTextOnDarkBackgrounds = true, InputImageType = AdvancedOcr.InputTypes.AutoDetect, RotateAndStraighten = false, ReadBarCodes = false, ColorDepth = 4 }; var Result = Ocr_Hebrew.Read(path_File); txtBigText.TextAlignment = TextAlignment.Right; cls_PhoneNum.ProgressBar(PBar); txtBigText.Text = Result.Text; } break; case "English": { var Ocr_English = new AutoOcr() { Language = IronOcr.Languages.English.OcrLanguagePack, }; var Result = Ocr_English.Read(path_File); txtBigText.TextAlignment = TextAlignment.Left; txtBigText.Text = Result.Text; } break; } cls_PhoneNum.text = txtBigText.Text; txtPhones.Text = cls_PhoneNum.Digits(txtBigText.Text); } }
public Task <Shop.OcrResult> Process(string file) { var ocr = new AutoOcr(); var result = ocr.Read(file); var ocrResult = new Shop.OcrResult() { Areas = Enumerable.Empty <Shop.OcrArea>(), Texts = result.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) }; return(Task.FromResult(ocrResult)); }
public static void Example4() { //International Languages - Arabic Example var Ocr = new AutoOcr() { Language = IronOcr.Languages.Arabic.OcrLanguagePack }; var Results = Ocr.Read("img/arabic.gif"); Console.WriteLine("{0} Characters of Arabic Read", Results.Text.Length); // Note that the .Net Console can not yet display Arabic characters... they all print as question marks. }
private void bwExtractText_DoWork(object sender, DoWorkEventArgs e) { bwExtractText.ReportProgress(0); var Orc = new AutoOcr(); bwExtractText.ReportProgress(50); textFromImage = Orc.Read(snipImage).Text; bwExtractText.ReportProgress(90, textFromImage); if (string.IsNullOrWhiteSpace(textFromImage)) { textFromImage = "Can't read anything"; } bwExtractText.ReportProgress(100); }
private void processOCR() { IronOcr.Languages.IOcrLanguagePack languages = new IronOcr.Languages.MultiLanguage( IronOcr.Languages.English.OcrLanguagePack, IronOcr.Languages.French.OcrLanguagePack ); var Ocr = new AutoOcr() { Language = languages, ReadBarCodes = false }; while (this.startProcessing) { if (this.imageFeed != null) { OcrResult Results; if (this.btnTextColour.BackColor == Control.DefaultBackColor) { Results = Ocr.Read(this.imageFeed); } else { Bitmap processed = ScreenProcessingHelper.filterColour(this.imageFeed, this.btnTextColour.BackColor); Results = Ocr.Read(processed); } Debug.WriteLine(Results.Text); if (Results.Text.Count() > 0) { string translation = Vikings.Translate.GoogleTranslate.Translate(Results.Text, "auto", "English"); try { this.ocrLabel.Invoke((MethodInvoker) delegate { this.ocrLabel.ForeColor = Color.FromArgb(this.ocrCover.BackColor.ToArgb() ^ 0xffffff); // inverts this.ocrLabel.Text = translation; this.ocrLabel.Font = new Font(Results.FontName, (float)(Results.FontSize / 3), FontStyle.Bold, GraphicsUnit.Pixel); this.ocrLabel.Visible = true; }); } catch { } } Application.DoEvents(); } Thread.Sleep(1000); } }
public static void Example1() { // AutoOcr automatically detects input image properties and makes // an educated best guess at the optimal OCR settings. AutoOcr Ocr = new AutoOcr() { ReadBarCodes = false }; var Results = Ocr.Read("img/Screenshot.png"); Console.WriteLine(Results.Text); // Check accuracy Accuracy.Compare(Results, "txt/Example1.txt"); }
public string getImage() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { AutoOcr OCR = new AutoOcr() { ReadBarCodes = false }; var Carte = Path.Combine(LogoFolder, "harmonie.png"); var Results = OCR.Read(Carte); Console.WriteLine(Results.Text); } return("Incompatible"); }
static void Main(string[] args) { Run(); AutoOcr ocr = new AutoOcr(); string testImage = @"C:/Users/Ben/Desktop/Programming/Examples/C#/TypeRacer cheat/TypeRacer cheat/bin/Debug/Hey.png"; Image image = Image.FromFile(testImage); Console.WriteLine("Reading image..."); var Results = ocr.Read(image); Console.WriteLine("OCR OUTPUT: {0}", Results.Text); Console.ReadKey(); }
public static void Example3() { //Crop Areas - Scanning only part of an Image var Ocr = new AutoOcr(); var Area = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 }; var Results = Ocr.Read("img/ComSci.Png", Area); Console.WriteLine(Results.Text); // Check accuracy Accuracy.Compare(Results, "txt/Example3.txt"); }
public string ReadImage(Bitmap bitmap) { try { AutoOcr ocr = new AutoOcr() { Language = IronOcr.Languages.Turkish.OcrLanguagePack }; OcrResult result = ocr.Read(bitmap); return(result.Text); } catch (Exception ex) { return(ex.Message); } }
protected override void Run() { //Insert Step logic here Image img = Image; _numericOutput = NumericInput * img.SizeX * img.SizeY; AutoOcr OCR = new AutoOcr() { ReadBarCodes = false }; OcrResult Results = OCR.Read("C:\\Users\\inovakomerfaruk\\Desktop\\Image.bmp"); _OcrResult = Results.Text; }
protected void Upload(object sender, EventArgs e) { if (FileUpload1.HasFile) { string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName); if (fileName != "") { FileUpload1.SaveAs(Server.MapPath("~/images/") + fileName); } var Ocr = new AutoOcr(); string Result = Ocr.Read(@Server.MapPath("~/Images/") + fileName).Text; string sonuc = ""; foreach (char c in Result) { if (Char.IsNumber(c)) { sonuc += c; } } //isbn -> sonuc SqlCommand komut2 = new SqlCommand("Select ISBN From KullaniciKitap WHERE KullaniciAdi=@p1 AND ISBN=@a1", bgl.baglanti()); komut2.Parameters.AddWithValue("@p1", Session["kullanici"].ToString()); komut2.Parameters.AddWithValue("@a1", sonuc); SqlDataReader dr2 = komut2.ExecuteReader(); if (dr2.Read()) { //eşleşme var SqlCommand komutguncelle = new SqlCommand("Update Kutuphane SET KitapAdet=1 WHERE ISBN=@p1", bgl.baglanti()); komutguncelle.Parameters.AddWithValue("@p1", sonuc); komutguncelle.ExecuteNonQuery(); bgl.baglanti().Close(); SqlCommand kullaniciguncelle = new SqlCommand("Delete From KullaniciKitap WHERE ISBN=@p1", bgl.baglanti()); kullaniciguncelle.Parameters.AddWithValue("@p1", sonuc); kullaniciguncelle.ExecuteNonQuery(); bgl.baglanti().Close(); MessageBox.Show("Iade İşlemi Tamamlandı!", "Bilgilendirme Penceresi"); Response.Redirect("KitapTeslim.aspx"); } else { MessageBox.Show("Iade İşlemi Tamamlanamadı. Sisteme yüklenen veriler eşleşmiyor!", "Bilgilendirme Penceresi"); Response.Redirect("KitapTeslim.aspx"); } } }
public MainWindow() { InitializeComponent(); UpdateTimer = new System.Timers.Timer(33.3); UpdateTimer.Elapsed += UpdateTimer_Elapsed; UpdateTimer.Start(); LeftXIntegerUpDown.Value = leftX; TopYIntegerUpDown.Value = topY; RightXIntegerUpDown.Value = rightX; BottomYIntegerUpDown.Value = bottomY; ocr = new AutoOcr(); //ocr.Language = IronOcr.Languages.Japanese.OcrLanguagePack; ocr.Language = IronOcr.Languages.English.OcrLanguagePack; bitmap = new Bitmap(rightX - leftX, bottomY - topY, System.Drawing.Imaging.PixelFormat.Format32bppArgb); }