Recognize the specified pix as one line returning the recognized
| 50 | |
| 51 | // Recognize the specified pix as one line returning the recognized |
| 52 | bool CubeLineObject::Process() { |
| 53 | // do nothing if pix had already been processed |
| 54 | if (processed_) { |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | // validate data |
| 59 | if (line_pix_ == NULL || cntxt_ == NULL) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | // create a CharSamp |
| 64 | CharSamp *char_samp = CubeUtils::CharSampleFromPix(line_pix_, 0, 0, |
| 65 | line_pix_->w, |
| 66 | line_pix_->h); |
| 67 | if (char_samp == NULL) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | // compute connected components. |
| 72 | int con_comp_cnt = 0; |
| 73 | ConComp **con_comps = char_samp->FindConComps(&con_comp_cnt, |
| 74 | cntxt_->Params()->MinConCompSize()); |
| 75 | // no longer need char_samp, delete it |
| 76 | delete char_samp; |
| 77 | // no connected components, bail out |
| 78 | if (con_comp_cnt <= 0 || con_comps == NULL) { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | // sort connected components based on reading order |
| 83 | bool rtl = (cntxt_->ReadingOrder() == tesseract::CubeRecoContext::R2L); |
| 84 | qsort(con_comps, con_comp_cnt, sizeof(*con_comps), rtl ? |
| 85 | ConComp::Right2LeftComparer : ConComp::Left2RightComparer); |
| 86 | |
| 87 | // compute work breaking threshold as a ratio of line height |
| 88 | bool ret_val = false; |
| 89 | int word_break_threshold = ComputeWordBreakThreshold(con_comp_cnt, con_comps, |
| 90 | rtl); |
| 91 | if (word_break_threshold > 0) { |
| 92 | // over-allocate phrases object buffer |
| 93 | phrases_ = new CubeObject *[con_comp_cnt]; |
| 94 | // create a phrase if the horizontal distance between two consecutive |
| 95 | // concomps is higher than threshold |
| 96 | int start_con_idx = 0; |
| 97 | int current_phrase_limit = rtl ? con_comps[0]->Left() : |
| 98 | con_comps[0]->Right(); |
| 99 | |
| 100 | for (int con_idx = 1; con_idx <= con_comp_cnt; con_idx++) { |
| 101 | bool create_new_phrase = true; |
| 102 | // if not at the end, compute the distance between two consecutive |
| 103 | // concomps |
| 104 | if (con_idx < con_comp_cnt) { |
| 105 | int dist = 0; |
| 106 | if (cntxt_->ReadingOrder() == tesseract::CubeRecoContext::R2L) { |
| 107 | dist = current_phrase_limit - con_comps[con_idx]->Right(); |
| 108 | } else { |
| 109 | dist = con_comps[con_idx]->Left() - current_phrase_limit; |
nothing calls this directly
no test coverage detected