帮我用c#写一个程序,识别当前文件夹里面的图像,然后把文字保存到txt文件
时间: 2024-02-11 21:09:24 浏览: 25
好的,以下是一个简单的C#程序,可以实现您的需求:
```csharp
using System;
using System.IO;
using Tesseract;
namespace ImageToText
{
class Program
{
static void Main(string[] args)
{
string folderPath = @"C:\your\folder\path"; // 替换为您的文件夹路径
string outputPath = @"C:\your\output\path\output.txt"; // 替换为您的输出文件路径
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
{
var files = Directory.GetFiles(folderPath, "*.jpg"); // 替换为您需要识别的图像格式
foreach (var file in files)
{
using (var img = Pix.LoadFromFile(file))
{
using (var page = engine.Process(img))
{
var text = page.GetText();
File.AppendAllText(outputPath, text);
}
}
}
}
Console.WriteLine("识别完成!");
}
}
}
```
这个程序使用了Tesseract OCR库来识别图像中的文字,并将识别结果保存到指定的输出文件中。请注意,您需要在程序中设置文件夹路径和输出文件路径,以及根据您的需求修改图像格式和语言。
希望这个程序对您有所帮助!