diff --git a/unittest/apiexample_test.cc b/unittest/apiexample_test.cc index a9724b861e..00b0301707 100644 --- a/unittest/apiexample_test.cc +++ b/unittest/apiexample_test.cc @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////// -// File: apiexample.cpp +// File: apiexample_test.cc // Description: Api Example for Tesseract. // Author: ShreeDevi Kumar // @@ -23,30 +23,36 @@ TEST(TesseractTest, ApiExample) { - const char* imagefile = "../testing/phototest.tif"; - const char* groundtruth = "testfiles/phototest.txt"; char *outText; - std::locale loc("en_US.UTF-8"); - std::ifstream file(groundtruth); - file.imbue(loc); + std::locale loc("en_US.UTF-8"); // You can also use "" for the default system locale + std::ifstream file("testfiles/phototest.txt"); + file.imbue(loc); // Use it for file input std::string gtText((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); + // Initialize tesseract-ocr with English, without specifying tessdata path if (api->Init(NULL, "eng")) { fprintf(stderr, "Could not initialize tesseract.\n"); exit(1); } - Pix *image = pixRead(imagefile); + + // Open input image with leptonica library + Pix *image = pixRead("../testing/phototest.tif"); api->SetImage(image); - api->SetPageSegMode(tesseract::PSM_AUTO_OSD); + // Get OCR result outText = api->GetUTF8Text(); - ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth"; + + ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth"; + + // Destroy used object and release memory api->End(); delete [] outText; pixDestroy(&image); + } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +}