在文件夹中的foreach位图 [英] Foreach bitmap in folder
问题描述
所以下面是使用TessNet的OCR工具来扫描该文件夹中的每个位图和处理OCR信息到列表与LT一些code; tessnet2.Word>结果
。但我似乎无法得到的foreach的工作权利。
我收到以下错误 foreach语句无法在类型System.IO.DirectoryInfo'变量工作,因为System.IO.DirectoryInfo'不包含'的GetEnumerator'一个公共定义
DirectoryInfo的diBMP =新的DirectoryInfo(C:\\\\ \\\\温度骨形成蛋白); 的foreach(BMP位在diBMP)
{
使用(tessnet2.Tesseract tessocr =新tessnet2.Tesseract())
{ tessocr.Init(@C:\\用户\\马特·泰勒\\文档\\ Visual Studio 2012中\\项目\\ TessNet2 \\ TessNet2 \\ BIN \\调试\\ tessdata,工程,FALSE); tessocr.GetThresholdedImage(BMP,System.Drawing.Rectangle.Empty).Save:(C \\\\ \\\\温度+ Guid.NewGuid()的ToString()+.BMP)。
Console.WriteLine(普通版);
清单< tessnet2.Word>结果= ocr.DoOCRNormal(BMP,工程); CheckANDCorrectPDForientation(结果,pdfFiles);
}
}
它看起来像你想
的foreach(字符串s在Directory.EnumerateFiles(目录,* .BMP))
{
使用(BMP位图=新位图(S))
{
// code在这里
}
}
您的错误是因为foreach循环必须具备的东西通过循环,的DirectoryInfo
只会给你有关的目录信息
So below is some code that uses TessNet's OCR tool to scans each bitmap in the folder and processes the OCR information into List<tessnet2.Word> result
. But I can't seem to get the foreach to work right.
I get the following error foreach statement cannot operate on variables of type 'System.IO.DirectoryInfo' because 'System.IO.DirectoryInfo' does not contain a public definition for 'GetEnumerator'
DirectoryInfo diBMP = new DirectoryInfo("c:\\temp\\bmps");
foreach (Bitmap bmp in diBMP)
{
using (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, System.Drawing.Rectangle.Empty).Save("c:\\temp\\" + Guid.NewGuid().ToString() + ".bmp");
Console.WriteLine("Normal version");
List<tessnet2.Word> result = ocr.DoOCRNormal(bmp, "eng");
CheckANDCorrectPDForientation(result, pdfFiles);
}
}
It looks like you want
foreach(string s in Directory.EnumerateFiles(dir, "*.bmp"))
{
using(Bitmap bmp = new Bitmap(s))
{
//code here
}
}
Your error is because a foreach loop must have something to loop through, DirectoryInfo
will just give you information about the directory
这篇关于在文件夹中的foreach位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!