tesseract  4.00.00dev
apiexample_test.cc File Reference
#include "gtest/gtest.h"
#include "baseapi.h"
#include "leptonica/allheaders.h"
#include <iostream>
#include <string>
#include <fstream>
#include <locale>

Go to the source code of this file.

Functions

 TEST (TesseractTest, ApiExample)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

This program reads in a text file consisting of feature samples from a training page in the following format:

   FontName UTF8-char-str xmin ymin xmax ymax page-number
    NumberOfFeatureTypes(N)
      FeatureTypeName1 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      FeatureTypeName2 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      ...
      FeatureTypeNameN NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
   FontName CharName ...

The result of this program is a binary inttemp file used by the OCR engine.

Parameters
argcnumber of command line arguments
argvarray of command line arguments
Returns
none
Note
Exceptions: none
History: Fri Aug 18 08:56:17 1989, DSJ, Created.
History: Mon May 18 1998, Christy Russson, Revistion started.

Definition at line 53 of file apiexample_test.cc.

53  {
54  ::testing::InitGoogleTest(&argc, argv);
55  return RUN_ALL_TESTS();
56 }

◆ TEST()

TEST ( TesseractTest  ,
ApiExample   
)

Definition at line 24 of file apiexample_test.cc.

25 {
26  char *outText;
27  std::locale loc("C"); // You can also use "" for the default system locale
28  std::ifstream file("../testing/phototest.txt");
29  file.imbue(loc); // Use it for file input
30  std::string gtText((std::istreambuf_iterator<char>(file)),
31  std::istreambuf_iterator<char>());
32 
34  // Initialize tesseract-ocr with English, without specifying tessdata path
35  ASSERT_FALSE(api->Init(nullptr, "eng")) << "Could not initialize tesseract.";
36 
37  // Open input image with leptonica library
38  Pix *image = pixRead("../testing/phototest.tif");
39  ASSERT_TRUE(image != nullptr) << "Failed to read test image.";
40  api->SetImage(image);
41  // Get OCR result
42  outText = api->GetUTF8Text();
43 
44  ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth";
45 
46  // Destroy used object and release memory
47  api->End();
48  delete [] outText;
49  pixDestroy(&image);
50 
51 }
struct TessBaseAPI TessBaseAPI
Definition: capi.h:83
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_non_debug_params)
Definition: baseapi.cpp:332
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:561