Kaip ištraukti tekstą iš vaizdo C#

Atlikti Optical Character Recognition (OCR) vaizdą yra sudėtinga užduotis. Šioje temoje žingsnis po žingsnio paaiškinama, kaip greitai ir lengvai išgauti tekstą iš vaizdo C#. Naudodami Aspose.OCR for .NET galite tiesiog per kelis veiksmus nuskaityti simbolius iš vaizdo C#.

Veiksmai, kaip ištraukti tekstą iš vaizdo C#

  1. Naudokite Aspose.OCR for .NET NuGet paketą
  2. Pirmiausia įtraukite Aspose.OCR namespace nuorodą
  3. Naudokite SetLicense metodą, kad pritaikytumėte Aspose licenciją
  4. Sukurkite AsposeOcr Class egzemplioriaus objektą
  5. Naudokite RecognizeImage metodą, kad ištrauktumėte tekstą iš vaizdo, taikydami OCR
  6. Išsaugokite ištrauktą tekstą į tekstinį failą naudodami FileStream ir StreamWriter klases

Aukščiau pateikti veiksmai rodo, kad skaityti simbolius iš vaizdo C# yra labai lengva. Aukščiau nurodytų veiksmų kodas pateiktas žemiau.

Kodas, skirtas ištraukti tekstą iš vaizdo C#

using System;
using System.IO;
//Add Aspose.OCR for .NET package reference
//Use following namespaces to Extract Text from Image
using Aspose.OCR;
namespace ExtractTextFromImage
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before extracting text from image
//using Aspose.OCR for .NET
Aspose.OCR.License AsposeOCRLicense = new Aspose.OCR.License();
AsposeOCRLicense.SetLicense(@"c:\asposelicense\license.lic");
//Create an instance of AsposeOcr class before you can apply
//OCR on an image to extract the text from it
AsposeOcr ExtractTextFromImage = new AsposeOcr();
//Read image using RecognizeImage method on which OCR need to be applied for text extraction
string TextExtractedFromImage = ExtractTextFromImage.RecognizeImage("ExampleOCRImageToExtractText.jpg");
//Save extracted text to a text file using File Stream and StreamWriter
//classes of System.IO
FileStream FStream = new FileStream("ExtractTextFromImageUsingOCR.txt", FileMode.Create);
StreamWriter SWriter = new StreamWriter(FStream);
//Write extracted text to the file
SWriter.WriteLine(TextExtractedFromImage);
SWriter.Flush();
//Close FileStream and StreamWriter bojects
SWriter.Close();
FStream.Close();
}
}
}

Metodas yra vienodas bet kokio tipo .NET programoms, jei naudojate C# kalbą. Nesvarbu, ar norite išgauti visą tekstą iš vaizdo, ar perskaityti tekstą eilutė po eilutės, Aspose.OCR for .NET gali padėti tai padaryti.

 Latviski