#include <imagedata.h>
Definition at line 62 of file imagedata.h.
◆ ImageData() [1/2]
tesseract::ImageData::ImageData |
( |
| ) |
|
Definition at line 44 of file imagedata.cpp.
44 : page_number_(-1), vertical_text_(
false) {}
◆ ImageData() [2/2]
tesseract::ImageData::ImageData |
( |
bool |
vertical, |
|
|
Image |
pix |
|
) |
| |
Definition at line 46 of file imagedata.cpp.
47 : page_number_(0), vertical_text_(vertical) {
◆ ~ImageData()
tesseract::ImageData::~ImageData |
( |
| ) |
|
Definition at line 50 of file imagedata.cpp.
51 #ifdef TESSERACT_IMAGEDATA_AS_PIX
52 internal_pix_.destroy();
◆ AddBoxes()
void tesseract::ImageData::AddBoxes |
( |
const std::vector< TBOX > & |
boxes, |
|
|
const std::vector< std::string > & |
texts, |
|
|
const std::vector< int > & |
box_pages |
|
) |
| |
Definition at line 315 of file imagedata.cpp.
319 for (
unsigned i = 0; i < box_pages.size(); ++i) {
320 if (page_number_ >= 0 && box_pages[i] != page_number_) {
323 transcription_ += texts[i];
324 boxes_.push_back(
boxes[i]);
325 box_texts_.push_back(texts[i]);
const std::vector< TBOX > & boxes() const
◆ box_text()
const std::string& tesseract::ImageData::box_text |
( |
int |
index | ) |
const |
|
inline |
Definition at line 113 of file imagedata.h.
114 return box_texts_[index];
◆ box_texts()
const std::vector<std::string>& tesseract::ImageData::box_texts |
( |
| ) |
const |
|
inline |
◆ boxes()
const std::vector<TBOX>& tesseract::ImageData::boxes |
( |
| ) |
const |
|
inline |
◆ Build()
ImageData * tesseract::ImageData::Build |
( |
const char * |
name, |
|
|
int |
page_number, |
|
|
const char * |
lang, |
|
|
const char * |
imagedata, |
|
|
int |
imagedatasize, |
|
|
const char * |
truth_text, |
|
|
const char * |
box_text |
|
) |
| |
|
static |
Definition at line 58 of file imagedata.cpp.
68 memcpy(&
image_data->image_data_[0], imagedata, imagedatasize);
70 if (truth_text ==
nullptr || truth_text[0] ==
'\0') {
71 tprintf(
"Error: No text corresponding to page %d from image %s!\n",
78 image_data->box_texts_.emplace_back(truth_text);
81 }
else if (truth_text !=
nullptr && truth_text[0] !=
'\0' &&
void tprintf(const char *format,...)
const std::vector< char > & image_data() const
const std::string & box_text(int index) const
◆ DeSerialize()
bool tesseract::ImageData::DeSerialize |
( |
TFile * |
fp | ) |
|
Definition at line 117 of file imagedata.cpp.
118 if (!fp->DeSerialize(imagefilename_)) {
121 if (!fp->DeSerialize(&page_number_)) {
124 if (!fp->DeSerialize(image_data_)) {
127 if (!fp->DeSerialize(language_)) {
130 if (!fp->DeSerialize(transcription_)) {
133 if (!fp->DeSerialize(boxes_)) {
136 if (!fp->DeSerialize(box_texts_)) {
140 if (!fp->DeSerialize(&vertical)) {
143 vertical_text_ = vertical != 0;
◆ Display()
void tesseract::ImageData::Display |
( |
| ) |
const |
Definition at line 275 of file imagedata.cpp.
276 const int kTextSize = 64;
279 if (pix ==
nullptr) {
282 int width = pixGetWidth(pix);
283 int height = pixGetHeight(pix);
284 auto *win =
new ScrollView(
"Imagedata", 100, 100, 2 * (width + 2 * kTextSize),
285 2 * (height + 4 * kTextSize), width + 10,
286 height + 3 * kTextSize,
true);
287 win->Draw(pix, 0, height - 1);
292 int text_size = kTextSize;
293 if (!boxes_.empty() && boxes_[0].height() * 2 < text_size) {
294 text_size = boxes_[0].height() * 2;
296 win->TextAttributes(
"Arial", text_size,
false,
false,
false);
297 if (!boxes_.empty()) {
298 for (
unsigned b = 0; b < boxes_.size(); ++b) {
300 win->Text(boxes_[b].left(), height + kTextSize, box_texts_[b].c_str());
305 win->Text(0, height + kTextSize * 2, transcription_.c_str());
◆ GetPix()
Image tesseract::ImageData::GetPix |
( |
| ) |
const |
Definition at line 193 of file imagedata.cpp.
194 #ifdef TESSERACT_IMAGEDATA_AS_PIX
195 # ifdef GRAPHICS_DISABLED
198 return internal_pix_.clone();
202 return internal_pix_.copy();
205 return GetPixInternal(image_data_);
◆ image_data()
const std::vector<char>& tesseract::ImageData::image_data |
( |
| ) |
const |
|
inline |
◆ imagefilename()
const std::string& tesseract::ImageData::imagefilename |
( |
| ) |
const |
|
inline |
Definition at line 83 of file imagedata.h.
84 return imagefilename_;
◆ language()
const std::string& tesseract::ImageData::language |
( |
| ) |
const |
|
inline |
◆ MemoryUsed()
int tesseract::ImageData::MemoryUsed |
( |
| ) |
const |
◆ page_number()
int tesseract::ImageData::page_number |
( |
| ) |
const |
|
inline |
◆ PreScale()
Image tesseract::ImageData::PreScale |
( |
int |
target_height, |
|
|
int |
max_height, |
|
|
float * |
scale_factor, |
|
|
int * |
scaled_width, |
|
|
int * |
scaled_height, |
|
|
std::vector< TBOX > * |
boxes |
|
) |
| const |
Definition at line 215 of file imagedata.cpp.
219 int input_height = 0;
222 input_width = pixGetWidth(src_pix);
223 input_height = pixGetHeight(src_pix);
224 if (target_height == 0) {
225 target_height = std::min(input_height, max_height);
227 float im_factor =
static_cast<float>(target_height) / input_height;
228 if (scaled_width !=
nullptr) {
231 if (scaled_height !=
nullptr) {
232 *scaled_height = target_height;
235 Image pix = pixScale(src_pix, im_factor, im_factor);
236 if (pix ==
nullptr) {
237 tprintf(
"Scaling pix of size %d, %d by factor %g made null pix!!\n",
238 input_width, input_height, im_factor);
242 if (scaled_width !=
nullptr) {
243 *scaled_width = pixGetWidth(pix);
245 if (scaled_height !=
nullptr) {
246 *scaled_height = pixGetHeight(pix);
249 if (
boxes !=
nullptr) {
252 for (
auto box : boxes_) {
253 box.scale(im_factor);
254 boxes->push_back(box);
256 if (
boxes->empty()) {
258 TBOX box(0, 0, im_factor * input_width, target_height);
259 boxes->push_back(box);
262 if (scale_factor !=
nullptr) {
263 *scale_factor = im_factor;
int IntCastRounded(double x)
◆ Serialize()
bool tesseract::ImageData::Serialize |
( |
TFile * |
fp | ) |
const |
Definition at line 90 of file imagedata.cpp.
91 if (!fp->Serialize(imagefilename_)) {
94 if (!fp->Serialize(&page_number_)) {
97 if (!fp->Serialize(image_data_)) {
100 if (!fp->Serialize(language_)) {
103 if (!fp->Serialize(transcription_)) {
106 if (!fp->Serialize(boxes_)) {
109 if (!fp->Serialize(box_texts_)) {
112 int8_t vertical = vertical_text_;
113 return fp->Serialize(&vertical);
◆ set_imagefilename()
void tesseract::ImageData::set_imagefilename |
( |
const std::string & |
name | ) |
|
|
inline |
Definition at line 86 of file imagedata.h.
87 imagefilename_ = name;
◆ set_language()
void tesseract::ImageData::set_language |
( |
const std::string & |
lang | ) |
|
|
inline |
◆ set_page_number()
void tesseract::ImageData::set_page_number |
( |
int |
num | ) |
|
|
inline |
◆ SetPix()
void tesseract::ImageData::SetPix |
( |
Image |
pix | ) |
|
Definition at line 184 of file imagedata.cpp.
185 #ifdef TESSERACT_IMAGEDATA_AS_PIX
188 SetPixInternal(pix, &image_data_);
◆ SkipDeSerialize()
bool tesseract::ImageData::SkipDeSerialize |
( |
TFile * |
fp | ) |
|
|
static |
Definition at line 148 of file imagedata.cpp.
149 if (!fp->DeSerializeSkip()) {
156 if (!fp->DeSerializeSkip()) {
159 if (!fp->DeSerializeSkip()) {
162 if (!fp->DeSerializeSkip()) {
165 if (!fp->DeSerializeSkip(
sizeof(
TBOX))) {
169 if (!fp->DeSerialize(&number)) {
172 for (
int i = 0; i < number; i++) {
173 if (!fp->DeSerializeSkip()) {
178 return fp->DeSerialize(&vertical);
◆ transcription()
const std::string& tesseract::ImageData::transcription |
( |
| ) |
const |
|
inline |
Definition at line 104 of file imagedata.h.
105 return transcription_;
The documentation for this class was generated from the following files: