mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-18 11:28:51 +08:00
Rendering/hash map changes part 2
This commit is contained in:
parent
a987e6d87c
commit
5d21ecfad3
@ -73,7 +73,6 @@ void BoxChar::PrepareToWrite(vector<BoxChar*>* boxes) {
|
|||||||
if (rtl_rules) {
|
if (rtl_rules) {
|
||||||
ReorderRTLText(boxes);
|
ReorderRTLText(boxes);
|
||||||
}
|
}
|
||||||
tprintf("Rtl = %d ,vertical=%d\n", rtl_rules, vertical_rules);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inserts newline (tab) characters into the vector at newline positions.
|
// Inserts newline (tab) characters into the vector at newline positions.
|
||||||
@ -291,13 +290,19 @@ const int kMaxLineLength = 1024;
|
|||||||
/* static */
|
/* static */
|
||||||
void BoxChar::WriteTesseractBoxFile(const string& filename, int height,
|
void BoxChar::WriteTesseractBoxFile(const string& filename, int height,
|
||||||
const vector<BoxChar*>& boxes) {
|
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;
|
string output;
|
||||||
char buffer[kMaxLineLength];
|
char buffer[kMaxLineLength];
|
||||||
for (int i = 0; i < boxes.size(); ++i) {
|
for (int i = 0; i < boxes.size(); ++i) {
|
||||||
const Box* box = boxes[i]->box_;
|
const Box* box = boxes[i]->box_;
|
||||||
if (box == NULL) {
|
if (box == NULL) {
|
||||||
tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
|
tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
int nbytes =
|
int nbytes =
|
||||||
snprintf(buffer, kMaxLineLength, "%s %d %d %d %d %d\n",
|
snprintf(buffer, kMaxLineLength, "%s %d %d %d %d %d\n",
|
||||||
@ -305,6 +310,7 @@ void BoxChar::WriteTesseractBoxFile(const string& filename, int height,
|
|||||||
box->x + box->w, height - box->y, boxes[i]->page_);
|
box->x + box->w, height - box->y, boxes[i]->page_);
|
||||||
output.append(buffer, nbytes);
|
output.append(buffer, nbytes);
|
||||||
}
|
}
|
||||||
File::WriteStringToFileOrDie(output, filename);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tesseract
|
} // namespace tesseract
|
||||||
|
@ -100,6 +100,9 @@ class BoxChar {
|
|||||||
// is needed to convert to tesseract coordinates.
|
// is needed to convert to tesseract coordinates.
|
||||||
static void WriteTesseractBoxFile(const string& name, int height,
|
static void WriteTesseractBoxFile(const string& name, int height,
|
||||||
const vector<BoxChar*>& boxes);
|
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:
|
private:
|
||||||
string ch_;
|
string ch_;
|
||||||
|
@ -160,13 +160,18 @@ int main(int argc, char *argv[]) {
|
|||||||
// reduce the min samples:
|
// reduce the min samples:
|
||||||
// Config.MinSamples = 0.5 / num_fonts;
|
// Config.MinSamples = 0.5 / num_fonts;
|
||||||
pCharList = CharList;
|
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) {
|
iterate(pCharList) {
|
||||||
//Cluster
|
//Cluster
|
||||||
if (Clusterer)
|
|
||||||
FreeClusterer(Clusterer);
|
|
||||||
CharSample = (LABELEDLIST)first_node(pCharList);
|
CharSample = (LABELEDLIST)first_node(pCharList);
|
||||||
Clusterer =
|
Clusterer =
|
||||||
SetUpForClustering(FeatureDefs, CharSample, PROGRAM_FEATURE_TYPE);
|
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;
|
float SavedMinSamples = Config.MinSamples;
|
||||||
// To disable the tendency to produce a single cluster for all fonts,
|
// To disable the tendency to produce a single cluster for all fonts,
|
||||||
// make MagicSamples an impossible to achieve number:
|
// make MagicSamples an impossible to achieve number:
|
||||||
@ -185,21 +190,21 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
Config.MinSamples = SavedMinSamples;
|
Config.MinSamples = SavedMinSamples;
|
||||||
AddToNormProtosList(&NormProtoList, ProtoList, CharSample->Label);
|
AddToNormProtosList(&NormProtoList, ProtoList, CharSample->Label);
|
||||||
|
freeable_protos.push_back(ProtoList);
|
||||||
|
FreeClusterer(Clusterer);
|
||||||
}
|
}
|
||||||
FreeTrainingSamples(CharList);
|
FreeTrainingSamples(CharList);
|
||||||
if (Clusterer == NULL) { // To avoid a SIGSEGV
|
int desc_index = ShortNameToFeatureType(FeatureDefs, PROGRAM_FEATURE_TYPE);
|
||||||
fprintf(stderr, "Error: NULL clusterer!\n");
|
WriteNormProtos(FLAGS_D.c_str(), NormProtoList,
|
||||||
return 1;
|
FeatureDefs.FeatureDesc[desc_index]);
|
||||||
}
|
|
||||||
WriteNormProtos(FLAGS_D.c_str(), NormProtoList, Clusterer);
|
|
||||||
FreeNormProtoList(NormProtoList);
|
FreeNormProtoList(NormProtoList);
|
||||||
FreeProtoList(&ProtoList);
|
for (int i = 0; i < freeable_protos.size(); ++i) {
|
||||||
FreeClusterer(Clusterer);
|
FreeProtoList(&freeable_protos[i]);
|
||||||
|
}
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
return 0;
|
return 0;
|
||||||
} // main
|
} // main
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
Private Code
|
Private Code
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
@ -211,16 +216,13 @@ int main(int argc, char *argv[]) {
|
|||||||
* of the samples.
|
* of the samples.
|
||||||
* @param Directory directory to place sample files into
|
* @param Directory directory to place sample files into
|
||||||
* @param LabeledProtoList List of labeled protos
|
* @param LabeledProtoList List of labeled protos
|
||||||
* @param Clusterer The CLUSTERER to use
|
* @param feature_desc Description of the features
|
||||||
* @return none
|
* @return none
|
||||||
* @note Exceptions: none
|
* @note Exceptions: none
|
||||||
* @note History: Fri Aug 18 16:17:06 1989, DSJ, Created.
|
* @note History: Fri Aug 18 16:17:06 1989, DSJ, Created.
|
||||||
*/
|
*/
|
||||||
void WriteNormProtos (
|
void WriteNormProtos(const char *Directory, LIST LabeledProtoList,
|
||||||
const char *Directory,
|
const FEATURE_DESC_STRUCT *feature_desc) {
|
||||||
LIST LabeledProtoList,
|
|
||||||
CLUSTERER *Clusterer)
|
|
||||||
{
|
|
||||||
FILE *File;
|
FILE *File;
|
||||||
STRING Filename;
|
STRING Filename;
|
||||||
LABELEDLIST LabeledProto;
|
LABELEDLIST LabeledProto;
|
||||||
@ -235,8 +237,8 @@ void WriteNormProtos (
|
|||||||
Filename += "normproto";
|
Filename += "normproto";
|
||||||
printf ("\nWriting %s ...", Filename.string());
|
printf ("\nWriting %s ...", Filename.string());
|
||||||
File = Efopen (Filename.string(), "wb");
|
File = Efopen (Filename.string(), "wb");
|
||||||
fprintf(File,"%0d\n",Clusterer->SampleSize);
|
fprintf(File, "%0d\n", feature_desc->NumParams);
|
||||||
WriteParamDesc(File,Clusterer->SampleSize,Clusterer->ParamDesc);
|
WriteParamDesc(File, feature_desc->NumParams, feature_desc->ParamDesc);
|
||||||
iterate(LabeledProtoList)
|
iterate(LabeledProtoList)
|
||||||
{
|
{
|
||||||
LabeledProto = (LABELEDLIST) first_node (LabeledProtoList);
|
LabeledProto = (LABELEDLIST) first_node (LabeledProtoList);
|
||||||
@ -251,7 +253,7 @@ void WriteNormProtos (
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fprintf(File, "\n%s %d\n", LabeledProto->Label, N);
|
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);
|
fclose (File);
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ string PangoFontInfo::DescriptionName() const {
|
|||||||
/* static */
|
/* static */
|
||||||
void PangoFontInfo::SoftInitFontConfig() {
|
void PangoFontInfo::SoftInitFontConfig() {
|
||||||
if (fonts_dir_.empty()) {
|
if (fonts_dir_.empty()) {
|
||||||
HardInitFontConfig(FLAGS_fonts_dir, FLAGS_fontconfig_tmpdir);
|
HardInitFontConfig(FLAGS_fonts_dir.c_str(), FLAGS_fontconfig_tmpdir.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user