Classifies the given [training] sample, writing to results. See ShapeClassifier for a full description.
| 42 | /// Classifies the given [training] sample, writing to results. |
| 43 | /// See ShapeClassifier for a full description. |
| 44 | int CubeClassifier::UnicharClassifySample( |
| 45 | const TrainingSample& sample, Pix* page_pix, int debug, |
| 46 | UNICHAR_ID keep_this, GenericVector<UnicharRating>* results) { |
| 47 | results->clear(); |
| 48 | if (page_pix == NULL) return 0; |
| 49 | |
| 50 | ASSERT_HOST(cube_cntxt_ != NULL); |
| 51 | const TBOX& char_box = sample.bounding_box(); |
| 52 | CubeObject* cube_obj = new tesseract::CubeObject( |
| 53 | cube_cntxt_, page_pix, char_box.left(), |
| 54 | pixGetHeight(page_pix) - char_box.top(), |
| 55 | char_box.width(), char_box.height()); |
| 56 | CharAltList* alt_list = cube_obj->RecognizeChar(); |
| 57 | if (alt_list != NULL) { |
| 58 | alt_list->Sort(); |
| 59 | CharSet* char_set = cube_cntxt_->CharacterSet(); |
| 60 | for (int i = 0; i < alt_list->AltCount(); ++i) { |
| 61 | // Convert cube representation to a shape_id. |
| 62 | int alt_id = alt_list->Alt(i); |
| 63 | int unichar_id = char_set->UnicharID(char_set->ClassString(alt_id)); |
| 64 | if (unichar_id >= 0) |
| 65 | results->push_back(UnicharRating(unichar_id, alt_list->AltProb(i))); |
| 66 | } |
| 67 | delete alt_list; |
| 68 | } |
| 69 | delete cube_obj; |
| 70 | return results->size(); |
| 71 | } |
| 72 | |
| 73 | /** Provides access to the ShapeTable that this classifier works with. */ |
| 74 | const ShapeTable* CubeClassifier::GetShapeTable() const { |
nothing calls this directly
no test coverage detected