As CharNormClassifier, but operates on a TrainingSample and outputs to a GenericVector of ShapeRating without conversion to classes.
| 1371 | // As CharNormClassifier, but operates on a TrainingSample and outputs to |
| 1372 | // a GenericVector of ShapeRating without conversion to classes. |
| 1373 | int Classify::CharNormTrainingSample(bool pruner_only, |
| 1374 | int keep_this, |
| 1375 | const TrainingSample& sample, |
| 1376 | GenericVector<UnicharRating>* results) { |
| 1377 | results->clear(); |
| 1378 | ADAPT_RESULTS* adapt_results = new ADAPT_RESULTS(); |
| 1379 | adapt_results->Initialize(); |
| 1380 | // Compute the bounding box of the features. |
| 1381 | int num_features = sample.num_features(); |
| 1382 | // Only the top and bottom of the blob_box are used by MasterMatcher, so |
| 1383 | // fabricate right and left using top and bottom. |
| 1384 | TBOX blob_box(sample.geo_feature(GeoBottom), sample.geo_feature(GeoBottom), |
| 1385 | sample.geo_feature(GeoTop), sample.geo_feature(GeoTop)); |
| 1386 | // Compute the char_norm_array from the saved cn_feature. |
| 1387 | FEATURE norm_feature = sample.GetCNFeature(); |
| 1388 | uinT8* char_norm_array = new uinT8[unicharset.size()]; |
| 1389 | int num_pruner_classes = MAX(unicharset.size(), |
| 1390 | PreTrainedTemplates->NumClasses); |
| 1391 | uinT8* pruner_norm_array = new uinT8[num_pruner_classes]; |
| 1392 | adapt_results->BlobLength = |
| 1393 | static_cast<int>(ActualOutlineLength(norm_feature) * 20 + 0.5); |
| 1394 | ComputeCharNormArrays(norm_feature, PreTrainedTemplates, char_norm_array, |
| 1395 | pruner_norm_array); |
| 1396 | |
| 1397 | PruneClasses(PreTrainedTemplates, num_features, keep_this, sample.features(), |
| 1398 | pruner_norm_array, |
| 1399 | shape_table_ != NULL ? &shapetable_cutoffs_[0] : CharNormCutoffs, |
| 1400 | &adapt_results->CPResults); |
| 1401 | delete [] pruner_norm_array; |
| 1402 | if (keep_this >= 0) { |
| 1403 | adapt_results->CPResults[0].Class = keep_this; |
| 1404 | adapt_results->CPResults.truncate(1); |
| 1405 | } |
| 1406 | if (pruner_only) { |
| 1407 | // Convert pruner results to output format. |
| 1408 | for (int i = 0; i < adapt_results->CPResults.size(); ++i) { |
| 1409 | int class_id = adapt_results->CPResults[i].Class; |
| 1410 | results->push_back( |
| 1411 | UnicharRating(class_id, 1.0f - adapt_results->CPResults[i].Rating)); |
| 1412 | } |
| 1413 | } else { |
| 1414 | MasterMatcher(PreTrainedTemplates, num_features, sample.features(), |
| 1415 | char_norm_array, |
| 1416 | NULL, matcher_debug_flags, |
| 1417 | classify_integer_matcher_multiplier, |
| 1418 | blob_box, adapt_results->CPResults, adapt_results); |
| 1419 | // Convert master matcher results to output format. |
| 1420 | for (int i = 0; i < adapt_results->match.size(); i++) { |
| 1421 | results->push_back(adapt_results->match[i]); |
| 1422 | } |
| 1423 | results->sort(&UnicharRating::SortDescendingRating); |
| 1424 | } |
| 1425 | delete [] char_norm_array; |
| 1426 | delete adapt_results; |
| 1427 | return num_features; |
| 1428 | } /* CharNormTrainingSample */ |
| 1429 | |
| 1430 |
no test coverage detected