下面是一些代码
- 创建一个目录
- 使用 MagickNet 将 PDF 转换为单独的 BMP 图像并将其存储在文件夹中 (ImagePath)
- 然后它使用 TessNet2 扫描该文件夹中的每个图像以解析出信息
我似乎无法获得扫描 ImagePath 文件夹的 foreach 循环。有什么帮助吗?
现在的错误在'foreach'语句上,它说“无法将类型'char'转换为'System.Drawing.Image'”
static void Main(string[] args)
{
string ImagePath = exePath + "\\Images";
if (!Directory.Exists(ImagePath))
{
Directory.CreateDirectory(ImagePath);
}
MagickReadSettings settings = new MagickReadSettings();
settings.Density = new MagickGeometry(300, 300);
using (MagickImageCollection images = new MagickImageCollection())
{
images.Read(@"D:\Test\ABStest.pdf",settings);
int page = 1;
foreach (MagickImage image in images)
{
image.Write(ImagePath + "\\ABS" + page + ".bmp");
page++;
}
}
foreach (Image item in ImagePath)
{
using (Bitmap bmp = new Bitmap(item))
{
tessnet2.Tesseract tessocr = new tessnet2.Tesseract();
tessocr.Init(@"C:\Users\Matt Taylor\Documents\Visual Studio 2012\Projects\TessNet2\TessNet2\bin\Debug\tessdata", "eng", false);
tessocr.GetThresholdedImage(bmp, Rectangle.Empty).Save("c:\\temp\\" + Guid.NewGuid().ToString() + ".bmp");
// Tessdata directory must be in the directory than this exe
Console.WriteLine("Multithread version");
ocr.DoOCRMultiThred(bmp, "eng");
//Console.WriteLine("Normal version");
//ocr.DoOCRNormal(bmp, "eng");
}
}
}