Builds and returns an ImageData from the basic data. Note that imagedata, truth_text, and box_text are all the actual file data, NOT filenames.
| 132 | // Builds and returns an ImageData from the basic data. Note that imagedata, |
| 133 | // truth_text, and box_text are all the actual file data, NOT filenames. |
| 134 | ImageData* ImageData::Build(const char* name, int page_number, const char* lang, |
| 135 | const char* imagedata, int imagedatasize, |
| 136 | const char* truth_text, const char* box_text) { |
| 137 | ImageData* image_data = new ImageData(); |
| 138 | image_data->imagefilename_ = name; |
| 139 | image_data->page_number_ = page_number; |
| 140 | image_data->language_ = lang; |
| 141 | // Save the imagedata. |
| 142 | image_data->image_data_.resize_no_init(imagedatasize); |
| 143 | memcpy(&image_data->image_data_[0], imagedata, imagedatasize); |
| 144 | if (!image_data->AddBoxes(box_text)) { |
| 145 | if (truth_text == NULL || truth_text[0] == '\0') { |
| 146 | tprintf("Error: No text corresponding to page %d from image %s!\n", |
| 147 | page_number, name); |
| 148 | delete image_data; |
| 149 | return NULL; |
| 150 | } |
| 151 | image_data->transcription_ = truth_text; |
| 152 | // If we have no boxes, the transcription is in the 0th box_texts_. |
| 153 | image_data->box_texts_.push_back(truth_text); |
| 154 | // We will create a box for the whole image on PreScale, to save unpacking |
| 155 | // the image now. |
| 156 | } else if (truth_text != NULL && truth_text[0] != '\0' && |
| 157 | image_data->transcription_ != truth_text) { |
| 158 | // Save the truth text as it is present and disagrees with the box text. |
| 159 | image_data->transcription_ = truth_text; |
| 160 | } |
| 161 | return image_data; |
| 162 | } |
| 163 | |
| 164 | // Writes to the given file. Returns false in case of error. |
| 165 | bool ImageData::Serialize(TFile* fp) const { |
nothing calls this directly
no test coverage detected