Problems with Tesseract (C++) interacting with Objective-C

325 views
Skip to first unread message

Rafael Ruiz Muñoz

unread,
Dec 1, 2014, 9:41:17 AM12/1/14
to tesser...@googlegroups.com

I'm trying to develop a X-platform tool with Tesseract, but I'm having problems.

My Tesseract's API works fine, for example, the next code compiled in C++ does work:

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
putenv("TESSDATA_PREFIX=/Users/rafaelruizmunoz/Desktop");
api->Init(NULL, "eng");
api->SetPageSegMode(tesseract::PSM_SINGLE_LINE);
api->SetVariable("tessedit_char_whitelist", "0123456789/");
Pix *image = pixRead("/Users/rafaelruizmunoz/Desktop/6a00d8341bfb1653ef0192acb84130970d.jpg");
api->SetImage(image);

so, no problem.

Now, I try to implement it for iPhone. From the iPhone I'm passing the path where I'm going to store images to then load them with Tesseract (I can't pass them from Mat to PIX):

string nameFile = "/tempTime" + to_string(i) + to_string(j) + ".jpg";
string cPathString = folder + nameFile;
const char* cPath = cPathString.c_str();

filenameVector.push_back(cPath);
imwrite(cPath, date);

The image is saved sucessfully (imwrite = 1).

But then when I load it as:

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();;
api->Init(resourcePath.c_str(), "eng");
api->SetPageSegMode(tesseract::PSM_SINGLE_LINE);
api->SetVariable("tessedit_char_whitelist", "0123456789/");
Pix *image = pixRead(filenameVector.at(i).c_str());

the image is NULL, and the errors are:

Error in pixReadStreamJpeg: function not present

Error in pixReadStream: jpeg: no pix returned

Error in pixRead: pix not read

Error in pixGetDimensions: pix not defined

Error in pixGetColormap: pix not defined

Error in pixClone: pixs not defined

Error in pixGetDepth: pix not defined

Error in pixGetWpl: pix not defined

Error in pixGetYRes: pix not defined

Please call SetImage before attempting recognition.

I'm pretty sure that the file still exists, because if I do:

Mat matInserted = imread(filenameVector.at(i).c_str());

the matInserted is my image (seen it from debug).

What is going wrong? Thanks.

Oliver Nicolini

unread,
Dec 1, 2014, 3:41:20 PM12/1/14
to tesser...@googlegroups.com
Actually IOS has a pretty strong sandBox thus if you want to save some images you should do it in some allowed directory.
In this example is the Document directory that is used:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];


Then in order to retrieve the path of the image (if you don't save it) you need to do:

NSString* filePath = [[NSBundle mainBundle] pathForResource:@“your_file_name" ofType:@“jpg”];


I managed to save and retrieve images successfully using this technique.

Cheers,

Oliver Nicolini


--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To post to this group, send email to tesser...@googlegroups.com.
Visit this group at http://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/6ddb3ed9-d91d-4daf-801e-1397b944ccee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages