C#调用开源图像识别类库tessnet2
来源:互联网 发布:老电视如何看网络电视 编辑:程序博客网 时间:2024/06/06 08:57
转自:http://blog.csdn.net/agai001/article/details/7352815
本人在做比价蜘蛛的时候用到:京东商城的单品价格是图片形式,所以需要识别。
首先下载tessnet2_32.dll及相关语言包,将dll加入引用
- private tessnet2.Tesseract ocr = new tessnet2.Tesseract();//声明一个OCR类
- //程序开始的时候,初始化OCR
- ocr.SetVariable("tessedit_char_whitelist", "0123456789."); //设置识别变量,当前只能识别数字。
- ocr.Init(@"D:\tessdata", "eng", false); //应用当前语言包。注,Tessnet2是支持多国语的。语言包下载链接:http://code.google.com/p/tesseract-ocr/downloads/list
- //下边这个函数是将网络上的图片识别成字符串,传入图片的超链接,输出字符串
- public string Bmp2Str(string bmpurl)
- {
- //http://www.newwhy.com/2010/0910/13708.html
- string s = "0";
- WebClient wc = new WebClient();
- try
- {
- byte[] oimg = wc.DownloadData(bmpurl);//将要识别的图像下载下来
- MemoryStream ms = new MemoryStream(oimg);
- Bitmap image = new Bitmap(ms);
- //为了提高识别率,所以对图片进行简单的处理
- image = BlackAndWhite(image, 0.8);//黑白处理,这个函数看下边
- image = new Bitmap(image, image.Width * 3, image.Height * 3);//放大三倍
- Monitor.Enter(this);//因为是多线程,所以用到了Monitor。
- System.Collections.Generic.List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);//执行识别操作
- foreach (tessnet2.Word word in result) //遍历识别结果。
- s = s + word.Text;
- Monitor.Exit(this);
- if (s.Length > 2)
- s = s.Substring(2, s.Length - 2);
- }
- catch
- {
- s = "0";
- }
- finally
- {
- wc.Dispose();
- }
- return s;
- //Console.WriteLine("{0} : {1}", word.Confidence, word.Text);
- }
- //黑白处理的函数,网上查的。
- public static Bitmap BlackAndWhite(Bitmap bitmap, Double hsb)
- {
- if (bitmap == null)
- {
- return null;
- }
- int width = bitmap.Width;
- int height = bitmap.Height;
- try
- {
- Bitmap bmpReturn = new Bitmap(width, height, PixelFormat.Format1bppIndexed);
- BitmapData srcBits = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
- BitmapData targetBits = bmpReturn.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);
- unsafe
- {
- byte* pSrcBits = (byte*)srcBits.Scan0.ToPointer();
- for (int h = 0; h < height; h++)
- {
- byte[] scan = new byte[(width + 7) / 8];
- for (int w = 0; w < width; w++)
- {
- int r, g, b;
- r = pSrcBits[2];
- g = pSrcBits[1];
- b = pSrcBits[0];
- if (GetBrightness(r, g, b) >= hsb) scan[w / 8] |= (byte)(0x80 >> (w % 8));
- pSrcBits += 3;
- }
- Marshal.Copy(scan, 0, (IntPtr)((int)targetBits.Scan0 + targetBits.Stride * h), scan.Length);
- pSrcBits += srcBits.Stride - width * 3;
- }
- bmpReturn.UnlockBits(targetBits);
- bitmap.UnlockBits(srcBits);
- return bmpReturn;
- }
- }
- catch
- {
- return null;
- }
- }
0 0
- C#调用开源图像识别类库tessnet2
- C# tessnet2.Tesseract识别图片验证码内容
- 图像识别四大图像库
- C# 调用Google语音识别
- 调用OCR识别图像中的文字
- Imagga 图像识别技术API调用方法
- android_图像识别库
- C#识别图像中线的条数
- 下面介绍一个开源的OCR引擎Tesseract2。值得庆幸的是虽然是开源的但是它的识别率较高,并不比其他引擎差劲。网上介绍Tessnet2也是当时时间排名第三的识别引擎,只是后来慢慢不维护了,目前是G
- 各种识别 库 图形 图像 识别
- C#调用百度语音识别API
- 人脸识别图像库
- 人脸识别图像库
- 人脸识别图像库
- 人脸识别图像库
- c#调用c++程序(DLL方法,以及opencv,运行开源的人脸识别seetaface)
- paip.验证码识别---图像处理类库
- C# 验证识别类
- Mina、Netty、Twisted一起学(一):实现简单的TCP服务器
- 关于struts1最近学习到的东西
- ExpandableListView 默认打开 点击不可收回
- hdoj.1194 Beat the Spread! 20140815
- Oracle中授权问题,导出表结构、数据
- C#调用开源图像识别类库tessnet2
- 怎样培养独挡一面的能力 .
- ARC指南3 - @property
- jQuery学习笔记之十一------动画效果
- Artificial Neural Networks && FileStorage of OpenCV
- String.format函数使用方法介绍
- 【序列化】小结,逐步完善中
- Unity3D项目程序加密1——在Unity3D里使用自己的dll
- Hdu 2795 Billboard 单点更新,区间最值