Skip to content

Commit f3dc156

Browse files
authored
updated version of apiexample_test
1 parent 7b409a1 commit f3dc156

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

unittest/apiexample_test.cc

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////
2-
// File: apiexample.cpp
2+
// File: apiexample_test.cc
33
// Description: Api Example for Tesseract.
44
// Author: ShreeDevi Kumar
55
//
@@ -23,30 +23,36 @@
2323

2424
TEST(TesseractTest, ApiExample)
2525
{
26-
const char* imagefile = "../testing/phototest.tif";
27-
const char* groundtruth = "testfiles/phototest.txt";
2826
char *outText;
29-
std::locale loc("en_US.UTF-8");
30-
std::ifstream file(groundtruth);
31-
file.imbue(loc);
27+
std::locale loc("en_US.UTF-8"); // You can also use "" for the default system locale
28+
std::ifstream file("testfiles/phototest.txt");
29+
file.imbue(loc); // Use it for file input
3230
std::string gtText((std::istreambuf_iterator<char>(file)),
3331
std::istreambuf_iterator<char>());
32+
3433
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
34+
// Initialize tesseract-ocr with English, without specifying tessdata path
3535
if (api->Init(NULL, "eng")) {
3636
fprintf(stderr, "Could not initialize tesseract.\n");
3737
exit(1);
3838
}
39-
Pix *image = pixRead(imagefile);
39+
40+
// Open input image with leptonica library
41+
Pix *image = pixRead("../testing/phototest.tif");
4042
api->SetImage(image);
41-
api->SetPageSegMode(tesseract::PSM_AUTO_OSD);
43+
// Get OCR result
4244
outText = api->GetUTF8Text();
43-
ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth";
45+
46+
ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth";
47+
48+
// Destroy used object and release memory
4449
api->End();
4550
delete [] outText;
4651
pixDestroy(&image);
52+
4753
}
4854

4955
int main(int argc, char **argv) {
5056
::testing::InitGoogleTest(&argc, argv);
5157
return RUN_ALL_TESTS();
52-
}
58+
}

0 commit comments

Comments
 (0)