Skip to content

Commit

Permalink
updated version of apiexample_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreeshrii authored Aug 19, 2017
1 parent 7b409a1 commit f3dc156
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions unittest/apiexample_test.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////
// File: apiexample.cpp
// File: apiexample_test.cc
// Description: Api Example for Tesseract.
// Author: ShreeDevi Kumar
//
Expand All @@ -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<char>(file)),
std::istreambuf_iterator<char>());

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();
}
}

0 comments on commit f3dc156

Please sign in to comment.