반응형
using System;
using Tesseract;

namespace OCRDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of the Tesseract OCR engine
            using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
            {
                // Load the image to be processed
                using (var img = Pix.LoadFromFile(@"./image.png"))
                {
                    // Set the page segmentation mode to automatic
                    engine.SetVariable("tessedit_pageseg_mode", "auto");

                    // Perform OCR on the image
                    using (var page = engine.Process(img))
                    {
                        // Get the recognized text
                        var text = page.GetText();

                        // Get the bounding boxes of the recognized characters
                        var boxes = page.GetWords();

                        // Print the recognized text and the position of each character
                        Console.WriteLine($"Recognized text: {text}");
                        foreach (var box in boxes)
                        {
                            Console.WriteLine($"Character: {box.Text}, Position: ({box.Left},{box.Top})");
                        }
                    }
                }
            }
        }
    }
}
반응형

+ Recent posts