Share via

Help with c # programming

jg555 1 Reputation point
2021-03-15T02:00:27.25+00:00

Hello, I need help with converting an image to text. I' am using c #.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


2 answers

Sort by: Most helpful
  1. Amin Dodin 1 Reputation point
    2021-03-16T15:44:18.277+00:00

    In general (Like cheong00 mentioned), the source files could either contain text or contain images of text. There is a solution that can handle both types of source files, which is the LEADTOOLS Document Converter SDK Libraries. (Disclaimer: I am a LEADTOOLS employee).

    The following code converts many types of input files and images to text, and automatically invoked OCR if needed:

    private void ConvertToText(string inputFileName)
    {
       var options = new LoadDocumentOptions();
       using (var document = DocumentFactory.LoadFromFile(inputFileName, options))
       {
          using (DocumentConverter documentConverter = new DocumentConverter())
          {
             Leadtools.Ocr.IOcrEngine ocrEngine = Leadtools.Ocr.OcrEngineManager.CreateEngine(Leadtools.Ocr.OcrEngineType.LEAD);
             ocrEngine.Startup(null, null, null, ocrEnginePath);
             documentConverter.SetOcrEngineInstance(ocrEngine, false);
             var outFile = inputFileName + "_converted.txt";
             var format = Leadtools.Document.Writer.DocumentFormat.Text;
             var jobData = DocumentConverterJobs.CreateJobData(document, outFile, format);
             jobData.JobName = "conversion job";
             var job = documentConverter.Jobs.CreateJob(jobData);
             documentConverter.Jobs.RunJob(job);
             MessageBox.Show(job.Errors.Count.ToString() + " " + outFile);
          }
       }
    }
    

    If you would like to try LEADTOOLS, you can download the free evaluation from this page

    Was this answer helpful?

    0 comments No comments

  2. cheong00 3,491 Reputation points Volunteer Moderator
    2021-03-15T04:19:06.127+00:00

    Unless you're processing images that have original text embedded (say, PS/AI/CDX/etc.), you'll need to employ some OCR technologies to deduce what are the text on the image.

    If you're developing for UWP, you may also consider classes from the Windows.Media.Ocr namespace.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.