模式识别之ocr---文字识别Tesseract-OCR 进行文字识别 VS2010

近日做铸件文字识别的项目,需要识别铸件上的字符和数字,找到开源的识别库Tesseract,下面简单记录下怎么使用。

 

首先在项目主页http://code.google.com/p/tesseract-ocr/ 下载库和相应的字库。由于本人使用的是VS2010,其lib和include等库使用的VS2008进行编译的,所以一直出错。用VS2010的同学可以在这里下载编译好的VS2010的相应的库。

然后进行配置,和其他库的配置类似,include lib dll。

 

 

  1. #include "allheaders.h"  
  2. #include "baseapi.h"  
  3. #include "strngs.h"  
  4. #include <cv.h>  
  5. #include <highgui.h>  
  6. #include <iostream>  
  7. using namespace cv;  
  8. using namespace std;  
  9.   
  10. int _tmain(int argc, _TCHAR* argv[])  
  11. {  
  12.         char *image_path="zj.jpg";  
  13.     tesseract::TessBaseAPI  api;  
  14.     api.Init(NULL,"eng",tesseract::OEM_DEFAULT);  
  15.   
  16.     api.SetPageSegMode(tesseract::PSM_AUTO);  
  17.   
  18.     FILE* fin = fopen(image_path, "rb");  
  19.     if (fin == NULL) {  
  20.         printf("Cannot open input file: %s\n", image_path);  
  21.         exit(2);  
  22.     }  
  23.     fclose(fin);  
  24.   
  25.     PIX   *pixs;  
  26.     if ((pixs = pixRead(image_path)) == NULL) {  
  27.         printf("Unsupported image type.\n");  
  28.         exit(3);  
  29.     }  
  30.     pixDestroy(&pixs);  
  31.   
  32.     STRING text_out;  
  33.     if (!api.ProcessPages(image_path, NULL, 0, &text_out)) {  
  34.         printf("Error during processing.\n");  
  35.     }  
  36.   
  37.     cout<<"识别结果为:"<<text_out.string();  
  38.            
  39.          return 0;  
  40. }  

 

http://blog.csdn.net/lanbing510/article/details/28696833

posted @ 2014-10-22 20:11  midu  阅读(894)  评论(0编辑  收藏  举报