Skip to content

Commit

Permalink
Rendering/hash map changes part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
theraysmith committed Nov 7, 2016
1 parent a987e6d commit 5d21ecf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
12 changes: 9 additions & 3 deletions training/boxchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void BoxChar::PrepareToWrite(vector<BoxChar*>* boxes) {
if (rtl_rules) {
ReorderRTLText(boxes);
}
tprintf("Rtl = %d ,vertical=%d\n", rtl_rules, vertical_rules);
}

// Inserts newline (tab) characters into the vector at newline positions.
Expand Down Expand Up @@ -291,20 +290,27 @@ const int kMaxLineLength = 1024;
/* static */
void BoxChar::WriteTesseractBoxFile(const string& filename, int height,
const vector<BoxChar*>& boxes) {
string output = GetTesseractBoxStr(height, boxes);
File::WriteStringToFileOrDie(output, filename);
}

/* static */
string BoxChar::GetTesseractBoxStr(int height, const vector<BoxChar*>& boxes) {
string output;
char buffer[kMaxLineLength];
for (int i = 0; i < boxes.size(); ++i) {
const Box* box = boxes[i]->box_;
if (box == NULL) {
tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
return;
return "";
}
int nbytes =
snprintf(buffer, kMaxLineLength, "%s %d %d %d %d %d\n",
boxes[i]->ch_.c_str(), box->x, height - box->y - box->h,
box->x + box->w, height - box->y, boxes[i]->page_);
output.append(buffer, nbytes);
}
File::WriteStringToFileOrDie(output, filename);
return output;
}

} // namespace tesseract
3 changes: 3 additions & 0 deletions training/boxchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class BoxChar {
// is needed to convert to tesseract coordinates.
static void WriteTesseractBoxFile(const string& name, int height,
const vector<BoxChar*>& boxes);
// Gets the tesseract box file as a string from the vector of boxes.
// The image height is needed to convert to tesseract coordinates.
static string GetTesseractBoxStr(int height, const vector<BoxChar*>& boxes);

private:
string ch_;
Expand Down
40 changes: 21 additions & 19 deletions training/cntraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,18 @@ int main(int argc, char *argv[]) {
// reduce the min samples:
// Config.MinSamples = 0.5 / num_fonts;
pCharList = CharList;
// The norm protos will count the source protos, so we keep them here in
// freeable_protos, so they can be freed later.
GenericVector<LIST> freeable_protos;
iterate(pCharList) {
//Cluster
if (Clusterer)
FreeClusterer(Clusterer);
CharSample = (LABELEDLIST)first_node(pCharList);
Clusterer =
SetUpForClustering(FeatureDefs, CharSample, PROGRAM_FEATURE_TYPE);
if (Clusterer == NULL) { // To avoid a SIGSEGV
fprintf(stderr, "Error: NULL clusterer!\n");
return 1;
}
float SavedMinSamples = Config.MinSamples;
// To disable the tendency to produce a single cluster for all fonts,
// make MagicSamples an impossible to achieve number:
Expand All @@ -185,21 +190,21 @@ int main(int argc, char *argv[]) {
}
Config.MinSamples = SavedMinSamples;
AddToNormProtosList(&NormProtoList, ProtoList, CharSample->Label);
freeable_protos.push_back(ProtoList);
FreeClusterer(Clusterer);
}
FreeTrainingSamples(CharList);
if (Clusterer == NULL) { // To avoid a SIGSEGV
fprintf(stderr, "Error: NULL clusterer!\n");
return 1;
}
WriteNormProtos(FLAGS_D.c_str(), NormProtoList, Clusterer);
int desc_index = ShortNameToFeatureType(FeatureDefs, PROGRAM_FEATURE_TYPE);
WriteNormProtos(FLAGS_D.c_str(), NormProtoList,
FeatureDefs.FeatureDesc[desc_index]);
FreeNormProtoList(NormProtoList);
FreeProtoList(&ProtoList);
FreeClusterer(Clusterer);
for (int i = 0; i < freeable_protos.size(); ++i) {
FreeProtoList(&freeable_protos[i]);
}
printf ("\n");
return 0;
} // main


/*----------------------------------------------------------------------------
Private Code
----------------------------------------------------------------------------*/
Expand All @@ -211,16 +216,13 @@ int main(int argc, char *argv[]) {
* of the samples.
* @param Directory directory to place sample files into
* @param LabeledProtoList List of labeled protos
* @param Clusterer The CLUSTERER to use
* @param feature_desc Description of the features
* @return none
* @note Exceptions: none
* @note History: Fri Aug 18 16:17:06 1989, DSJ, Created.
*/
void WriteNormProtos (
const char *Directory,
LIST LabeledProtoList,
CLUSTERER *Clusterer)
{
void WriteNormProtos(const char *Directory, LIST LabeledProtoList,
const FEATURE_DESC_STRUCT *feature_desc) {
FILE *File;
STRING Filename;
LABELEDLIST LabeledProto;
Expand All @@ -235,8 +237,8 @@ void WriteNormProtos (
Filename += "normproto";
printf ("\nWriting %s ...", Filename.string());
File = Efopen (Filename.string(), "wb");
fprintf(File,"%0d\n",Clusterer->SampleSize);
WriteParamDesc(File,Clusterer->SampleSize,Clusterer->ParamDesc);
fprintf(File, "%0d\n", feature_desc->NumParams);
WriteParamDesc(File, feature_desc->NumParams, feature_desc->ParamDesc);
iterate(LabeledProtoList)
{
LabeledProto = (LABELEDLIST) first_node (LabeledProtoList);
Expand All @@ -251,7 +253,7 @@ void WriteNormProtos (
exit(1);
}
fprintf(File, "\n%s %d\n", LabeledProto->Label, N);
WriteProtos(File, Clusterer->SampleSize, LabeledProto->List, true, false);
WriteProtos(File, feature_desc->NumParams, LabeledProto->List, true, false);
}
fclose (File);

Expand Down
2 changes: 1 addition & 1 deletion training/pango_font_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ string PangoFontInfo::DescriptionName() const {
/* static */
void PangoFontInfo::SoftInitFontConfig() {
if (fonts_dir_.empty()) {
HardInitFontConfig(FLAGS_fonts_dir, FLAGS_fontconfig_tmpdir);
HardInitFontConfig(FLAGS_fonts_dir.c_str(), FLAGS_fontconfig_tmpdir.c_str());
}
}

Expand Down

0 comments on commit 5d21ecf

Please sign in to comment.