MCPcopy Create free account
hub / github.com/creatale/node-dv / SetupMasterShapes

Method SetupMasterShapes

deps/tesseract/classify/mastertrainer.cpp:269–305  ·  view source on GitHub ↗

Sets up the master_shapes_ table, which tells which fonts should stay together until they get to a leaf node classifier.

Source from the content-addressed store, hash-verified

267// Sets up the master_shapes_ table, which tells which fonts should stay
268// together until they get to a leaf node classifier.
269void MasterTrainer::SetupMasterShapes() {
270 tprintf("Building master shape table\n");
271 int num_fonts = samples_.NumFonts();
272
273 ShapeTable char_shapes_begin_fragment(samples_.unicharset());
274 ShapeTable char_shapes_end_fragment(samples_.unicharset());
275 ShapeTable char_shapes(samples_.unicharset());
276 for (int c = 0; c < samples_.charsetsize(); ++c) {
277 ShapeTable shapes(samples_.unicharset());
278 for (int f = 0; f < num_fonts; ++f) {
279 if (samples_.NumClassSamples(f, c, true) > 0)
280 shapes.AddShape(c, f);
281 }
282 ClusterShapes(kMinClusteredShapes, 1, kFontMergeDistance, &shapes);
283
284 const CHAR_FRAGMENT *fragment = samples_.unicharset().get_fragment(c);
285
286 if (fragment == NULL)
287 char_shapes.AppendMasterShapes(shapes, NULL);
288 else if (fragment->is_beginning())
289 char_shapes_begin_fragment.AppendMasterShapes(shapes, NULL);
290 else if (fragment->is_ending())
291 char_shapes_end_fragment.AppendMasterShapes(shapes, NULL);
292 else
293 char_shapes.AppendMasterShapes(shapes, NULL);
294 }
295 ClusterShapes(kMinClusteredShapes, kMaxUnicharsPerCluster,
296 kFontMergeDistance, &char_shapes_begin_fragment);
297 char_shapes.AppendMasterShapes(char_shapes_begin_fragment, NULL);
298 ClusterShapes(kMinClusteredShapes, kMaxUnicharsPerCluster,
299 kFontMergeDistance, &char_shapes_end_fragment);
300 char_shapes.AppendMasterShapes(char_shapes_end_fragment, NULL);
301 ClusterShapes(kMinClusteredShapes, kMaxUnicharsPerCluster,
302 kFontMergeDistance, &char_shapes);
303 master_shapes_.AppendMasterShapes(char_shapes, NULL);
304 tprintf("Master shape_table:%s\n", master_shapes_.SummaryStr().string());
305}
306
307// Adds the junk_samples_ to the main samples_ set. Junk samples are initially
308// fragments and n-grams (all incorrectly segmented characters).

Callers

nothing calls this directly

Calls 10

charsetsizeMethod · 0.80
NumClassSamplesMethod · 0.80
AddShapeMethod · 0.80
get_fragmentMethod · 0.80
AppendMasterShapesMethod · 0.80
is_beginningMethod · 0.80
is_endingMethod · 0.80
SummaryStrMethod · 0.80
NumFontsMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected