OpenCV+Tesseract进行OCR学习(二)文字识别

xiaoxiao2021-02-28  64

转载自:http://blog.csdn.net/eternity1118_

OpenCV的Tesseract使用

OpenCV的Tesseract使用 Mac端的Tesseract使用iOS端的Tesseract使用

Mac端的Tesseract使用

Tesseract的安装  Mac上的Tesseract安装很方便,直接利用brew来安装:

brew update brew install tesseract 12 12

或者下载源码进行编译安装:  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; 12345678910111213141516 12345678910111213141516

iOS端的Tesseract使用

Tesseract的安装  利用CocoaPods来安装,命令如下:

brew update pod search tesseractocrios 12 12

这时会出现如下: 

继续键入命令:

touch Podfile vi Podfile 这时,将上图中‘pod 'TesseractOCRiOS', '~> 4.0.0'copy到Podfile中,保存退出,然后: pod install 1234 1234

ok,这时打开项目目录下生成的后缀名为.xcworkspace的工程即可。

Tesseract的使用

#import "TesseractOCR/G8Tesseract.h" //recognize image with tesseract -(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; }; // self.imageView.image = operation.tesseract.thresholdedImage; } //print the progress infos - (void)progressImageRecognitionForTesseract:(G8Tesseract *)tesseract { NSLog(@"progress: %lu", (unsigned long)tesseract.progress); }
转载请注明原文地址: https://www.6miu.com/read-81221.html

最新回复(0)