转载自:http://blog.csdn.net/eternity1118_
OpenCV的Tesseract使用
Mac端的Tesseract使用
Tesseract的安装
Mac上的Tesseract安装很方便,直接利用brew来安装:
brew update
brew install tesseract
或者下载源码进行编译安装:
Github地址
Tesseract的使用
#include <tesseract/baseapi.h>
tesseract::TessBaseAPI tessearct_api;
const char *languagePath = "/usr/local/Cellar/tesseract/3.04.01_2/share/tessdata";
const char *languageType = "chi_sim";
int nRet = tessearct_api.Init(languagePath, languageType,tesseract::OEM_DEFAULT);
if (nRet != 0) {
printf("初始化字库失败!");
return -1;
}
tessearct_api.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
tessearct_api.SetImage(seg_image.data, seg_image.cols, seg_image.rows, 1, seg_image.cols);
string out = string(tessearct_api.GetUTF8Text());
cout<<"the out result :"<<out<<endl;
iOS端的Tesseract使用
Tesseract的安装
利用CocoaPods来安装,命令如下:
brew update
pod search tesseractocrios
这时会出现如下:
![tesseract-ios搜索信息](https://img-blog.csdn.net/20160918171846688)
继续键入命令:
touch Podfile
vi Podfile
这时,将上图中‘pod 'TesseractOCRiOS', '~> 4.0.0'’copy到Podfile中,保存退出,然后:
pod install
ok,这时打开项目目录下生成的后缀名为.xcworkspace的工程即可。
Tesseract的使用
#import "TesseractOCR/G8Tesseract.h"
-(void)recognizeWithTesseract: (UIImage *)image{
G8RecognitionOperation *operation = [[G8RecognitionOperation alloc] initWithLanguage:@"chi_sim"];
operation.tesseract.engineMode = G8OCREngineModeTesseractOnly;
operation.tesseract.pageSegmentationMode = G8PageSegmentationModeAutoOnly;
operation.delegate = self;
operation.recognitionCompleteBlock = ^(G8Tesseract *tesseract) {
NSString *recognizedText = tesseract.recognizedText;
NSLog(@"%@", recognizedText);
self.text.text = recognizedText;
};
}
- (void)progressImageRecognitionForTesseract:(G8Tesseract *)tesseract {
NSLog(@"progress: %lu", (unsigned long)tesseract.progress);
}