2011-06-01 101 views
2

我正在嘗試使用Tesseract開放源代碼來查看我是否可以編譯和識別iPhone上的英文字符。我能夠這樣做。現在,我嘗試包括「ita.traineddata」內tessdata和改變Tesseract以外的其他語言iOS

tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], // Path to tessdata-no ending /. 
      "eng");             // ISO 639-3 string or NULL. 

tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], // Path to tessdata-no ending /. 
      "ita");             // ISO 639-3 string or NULL. 

,但我得到這個錯誤: Error openning data file /var/mobile/Applications/A37DB8B7-2272-4F80-9836-0034CEB56CC5/Documents/tessdata/ita.traineddata

我缺少什麼,如何會這樣如何處理?

+0

該文件是否存在? – 2011-06-01 01:21:20

+1

是的,我確實有這個文件。 – renderman47 2011-06-01 21:34:40

+0

如果你有答覆plz分享 – 2014-01-29 12:26:25

回答

1

首先將tessdata添加到您的項目/項目名稱文件夾中,然後(重要)轉到目標/構建階段/複製束資源並將tessdata文件夾添加爲REFERENCE!

,然後初始化的正方體是這樣的:

// Set up the tessdata path. This is included in the application bundle 
// but is copied to the Documents directory on the first run. 
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil; 

NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"]; 
NSFileManager *fileManager = [NSFileManager defaultManager]; 
// If the expected store doesn't exist, copy the default store. 
if (![fileManager fileExistsAtPath:dataPath]) { 
    // get the path to the app bundle (with the tessdata dir) 
    NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; 
    NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"]; 
    if (tessdataPath) { 
     [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL]; 
    } 
}  
setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1); 
// init the tesseract engine. 
tesseract = new tesseract::TessBaseAPI();  
tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "ita"); 

注:正方體初始化自己與英語爲默認值,一旦我刪除整個文件夾tessdata,它仍然沒有eng.traineddata文件的工作,這就是爲什麼它適用於英語但不適用於意大利語培訓數據,您的tessdata文件夾未正確初始化。

+0

嘗試過,但這不工作,你能指導我一點。 – 2014-01-29 12:27:34