void testtess() { cv::Mat img = imread("phototest.png"); if(img.empty()) { cerr << "noup." << endl; return; } imshow("blah",img); waitKey(1); cout << "photo " << img.size() << endl; int rc = api.Init(tessdata_dir.c_str(), "ara", tesseract::OEM_DEFAULT); if (rc) { cerr << "Could not initialize tesseract.\n"; exit(1); } api.SetPageSegMode(tesseract::PSM_AUTO); printf("Tesseract Open Source OCR Engine v%s with Leptonica\n", tesseract::TessBaseAPI::Version()); printf("Init languages %s\n",api.GetInitLanguagesAsString()); Mat tmp; cvtColor(img, tmp, CV_BGR2GRAY); adaptiveThreshold(tmp, tmp, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 51, 35); imshow("eqhist", tmp); // cvtColor(tmp, out(Rect(0,0,r.width,r.height)), CV_GRAY2BGR); char* cstr = api.TesseractRect(tmp.data, tmp.channels(), tmp.cols*tmp.channels(), 0, 0, tmp.cols, tmp.rows); cout << cstr << endl; delete[] cstr; waitKey(0); }
void TesseractBridge::init() { // int rc = api.Init(tessdata_dir.c_str(), NULL); // if (rc) { // cerr << "Could not initialize tesseract.\n"; // exit(1); // } // api.End(); int rc = api.Init(tessdata_dir.c_str(), "ara", tesseract::OEM_DEFAULT); if (rc) { cerr << "Could not initialize tesseract.\n"; exit(1); } api.SetPageSegMode(tesseract::PSM_AUTO); printf("Tesseract Open Source OCR Engine v%s with Leptonica\n", tesseract::TessBaseAPI::Version()); printf("Init languages %s\n",api.GetInitLanguagesAsString()); // GenericVector<STRING> v; api.GetAvailableLanguagesAsVector(&v); // for (int i = 0; i < v.length(); ++i) { // printf("lang %s\n",v[i].string()); // } }