12#include <allheaders.h>
19 TestEncodeDecodeBoth(
"eng",
"The quick brown 'fox' jumps over: the lazy dog!");
23 TestEncodeDecodeBoth(
"kan",
"ಫ್ರಬ್ರವರಿ ತತ್ವಾಂಶಗಳೆಂದರೆ ಮತ್ತು ಜೊತೆಗೆ ಕ್ರಮವನ್ನು");
27 TestEncodeDecodeBoth(
"kor",
"이는 것으로 다시 넣을 수는 있지만 선택의 의미는");
36 std::string kTestStr =
"The quick brown 'fox' jumps over: the lazy dog!";
37 std::vector<int> deu_labels;
40 std::string badly_decoded = fra_trainer.
DecodeLabels(deu_labels);
41 std::string bad_str(&badly_decoded[0], badly_decoded.length());
42 LOG(
INFO) <<
"bad_str fra=" << bad_str <<
"\n";
45 std::vector<int> fra_labels;
48 std::vector<int> mapping =
50 std::vector<int> mapped_fra_labels(fra_labels.size(), -1);
51 for (
unsigned i = 0;
i < fra_labels.size(); ++
i) {
52 mapped_fra_labels[
i] = mapping[fra_labels[
i]];
53 EXPECT_NE(-1, mapped_fra_labels[
i]) <<
"i=" <<
i <<
", ch=" << kTestStr[
i];
55 <<
"i=" <<
i <<
", ch=" << kTestStr[
i] <<
" has deu label=" << deu_labels[
i]
56 <<
", but mapped to " << mapped_fra_labels[
i];
59 std::string decoded = deu_trainer.
DecodeLabels(mapped_fra_labels);
60 std::string ok_str(&decoded[0], decoded.length());
61 LOG(
INFO) <<
"ok_str deu=" << ok_str <<
"\n";
73 std::string fra_data =
file::JoinPath(TESSDATA_DIR
"_best",
"fra.traineddata");
75 LOG(
INFO) <<
"Load " << fra_data <<
"\n";
77 std::string model_path =
file::JoinPath(FLAGS_test_tmpdir,
"fra.lstm");
79 LOG(
INFO) <<
"Extract " << model_path <<
"\n";
82 LOG(
INFO) <<
"Checkpoint load for " << model_path <<
" and " << fra_data <<
"\n";
83 std::string deu_data =
file::JoinPath(FLAGS_test_tmpdir,
"deu.traineddata");
85 LOG(
INFO) <<
"Save " << deu_data <<
"\n";
90 Image src_pix = pixRead(TestingNameToPath(
"phototest.tif").c_str());
94 std::string truth_text;
#define EXPECT_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
std::string TestDataNameToPath(const std::string &name)
TEST_F(EuroText, FastLatinOCR)
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const std::vector< std::string > *vars_vec, const std::vector< std::string > *vars_values, bool set_only_non_debug_params)
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
bool ExtractToFile(const char *filename)
bool Init(const char *data_file_name)
const UnicharCompress & GetRecoder() const
std::string DecodeLabels(const std::vector< int > &labels)
const UNICHARSET & GetUnicharset() const
bool EncodeString(const std::string &str, std::vector< int > *labels) const
bool InitCharSet(const std::string &traineddata_path)
bool SaveTraineddata(const char *filename)
bool TryLoadingCheckpoint(const char *filename, const char *old_traineddata)
std::vector< int > MapRecoder(const UNICHARSET &old_chset, const UnicharCompress &old_recoder) const
static std::string JoinPath(const std::string &s1, const std::string &s2)
static bool GetContents(const std::string &filename, std::string *out, int)