Skip to content

Commit

Permalink
Merge branch 'buggy_libparam_refactor_misc' into page-output-with-int…
Browse files Browse the repository at this point in the history
…-coordinates
  • Loading branch information
GerHobbelt committed Jul 27, 2024
2 parents f286356 + e204daa commit 238b46c
Show file tree
Hide file tree
Showing 36 changed files with 761 additions and 545 deletions.
78 changes: 33 additions & 45 deletions include/tesseract/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class TESS_API TessBaseAPI {
FileReader reader,
const char *data = nullptr, size_t data_size = 0);

/** @} */
/** @} */

public:
/**
Expand Down Expand Up @@ -1043,7 +1043,21 @@ class TESS_API TessBaseAPI {
/// Returns a reference to the internal instance of the Tesseract class;
/// the presence of which is guaranteed, i.e. the returned pointer
/// WILL NOT be `nullptr`.
Tesseract& tesseract() const;
///
/// Note that the reference's lifetime ends once the TessBaseAPI's instance
/// is deleted or its End() API is invoked, whichever comes first.
///
/// \sa End()
/// \sa WipeSqueakyCleanForReUse()
///
/// @{
const Tesseract &tesseract() const;
Tesseract &tesseract();
// https://stackoverflow.com/questions/856542/elegant-solution-to-duplicate-const-and-non-const-getters
//inline Tesseract &tesseract() {
// return const_cast<Tesseract &>(this->tesseract());
//}
/// @}

OcrEngineMode oem() const {
return last_oem_requested_;
Expand Down Expand Up @@ -1099,40 +1113,41 @@ class TESS_API TessBaseAPI {
}

protected:
Tesseract *tesseract_; ///< The underlying data object.
mutable Tesseract *tesseract_ = nullptr; ///< The underlying data object.
#if !DISABLED_LEGACY_ENGINE
Tesseract *osd_tesseract_; ///< For orientation & script detection.
EquationDetect *equ_detect_; ///< The equation detector.
Tesseract *osd_tesseract_ = nullptr; ///< For orientation & script detection.
EquationDetect *equ_detect_ = nullptr; ///< The equation detector.
#endif
ETEXT_DESC *monitor_ = nullptr;
ETEXT_DESC default_minimal_monitor_;
FileReader reader_; ///< Reads files from any filesystem.
ImageThresholder *thresholder_; ///< Image thresholding module.
std::vector<ParagraphModel *> *paragraph_models_;
BLOCK_LIST *block_list_; ///< The page layout.
PAGE_RES *page_res_; ///< The page-level data.
ImageThresholder *thresholder_ = nullptr; ///< Image thresholding module.
std::vector<ParagraphModel *> *paragraph_models_ = nullptr;
BLOCK_LIST *block_list_ = nullptr; ///< The page layout.
PAGE_RES *page_res_ = nullptr; ///< The page-level data.
std::string visible_image_file_;
Image pix_visible_image_; ///< Image used in output PDF
std::string output_file_; ///< Name used by debug code.
std::string datapath_; ///< Current location of tessdata.
std::string language_; ///< Last initialized language.
OcrEngineMode last_oem_requested_; ///< Last ocr language mode requested.
bool recognition_done_; ///< page_res_ contains recognition data.
OcrEngineMode last_oem_requested_ = OEM_DEFAULT; ///< Last ocr language mode requested.
bool recognition_done_ = false; ///< page_res_ contains recognition data.

/**
* @defgroup ThresholderParams Thresholder Parameters
* Parameters saved from the Thresholder. Needed to rebuild coordinates.
*/
/* @{ */
int rect_left_;
int rect_top_;
int rect_width_;
int rect_height_;
int image_width_;
int image_height_;
int rect_left_ = 0;
int rect_top_ = 0;
int rect_width_ = 0;
int rect_height_ = 0;

int image_width_ = 0;
int image_height_ = 0;
/* @} */

private:
protected:
// A list of image filenames gets special consideration
//
// If global parameter `tessedit_page_number` is non-negative, will only process that
Expand All @@ -1156,33 +1171,6 @@ std::string HOcrEscape(const char *text);
*/
std::string mkUniqueOutputFilePath(const char *basepath, int page_number, const char *label, const char *filename_extension);

/**
* Helper function around leptonica's `pixWrite()` which writes the given `pic` image to file, in the `file_type` format.
*
* The `file_type` format is defined in leptonica's `imageio.h`. Here's an (possibly incomplete) extract:
*
* - IFF_BMP = 1 (Windows BMP)
* - IFF_JFIF_JPEG = 2 (regular JPEG, default quality 75%)
* - IFF_PNG = 3 (PNG, lossless)
* - IFF_TIFF = 4 (TIFF)
* - IFF_TIFF_PACKBITS = 5 (TIFF, lossless)
* - IFF_TIFF_RLE = 6 (TIFF, lossless)
* - IFF_TIFF_G3 = 7 (TIFF, lossless)
* - IFF_TIFF_G4 = 8 (TIFF, lossless)
* - IFF_TIFF_LZW = 9 (TIFF, lossless)
* - IFF_TIFF_ZIP = 10 (TIFF, lossless)
* - IFF_PNM = 11 (PNM)
* - IFF_PS = 12 (PS: PostScript)
* - IFF_GIF = 13 (GIF)
* - IFF_JP2 = 14 (JP2
* - IFF_WEBP = 15 (WebP)
* - IFF_LPDF = 16 (LDPF)
* - IFF_TIFF_JPEG = 17 (JPEG embedded in TIFF)
* - IFF_DEFAULT = 18 (The IFF_DEFAULT flag is used to write the file out in the same (input) file format that the pix was read from. If the pix was not read from file, the input format field will be IFF_UNKNOWN and the output file format will be chosen to be compressed and lossless; namely: IFF_TIFF_G4 for depth = 1 bit and IFF_PNG for everything else.)
* - IFF_SPIX = 19 (SPIX: serialized PIX, a leptonica-specific file format)
*/
void WritePix(const std::string &filepath, Pix *pic, int file_type);

} // namespace tesseract

#endif // TESSERACT_API_BASEAPI_H_
2 changes: 1 addition & 1 deletion include/tesseract/pageiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class TESS_API PageIterator {
PAGE_RES_IT *it_;
/**
* The current input WERD being iterated. If there is an output from OCR,
* then word_ is nullptr. Owned by the API
* then word_ is nullptr. Owned by the API.
*/
WERD *word_;
/** The length of the current word_. */
Expand Down
Loading

0 comments on commit 238b46c

Please sign in to comment.