Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAGE XML renderer / export #4214

Merged
merged 26 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d574363
Add page-xml-export and documentation. To generate page xml output ju…
JKamlah Mar 18, 2022
100d8b7
Set polygonisation with parameter page as default.
JKamlah Apr 6, 2022
c0ccd8e
Rework page-output to be valid with 2019 format and dont fit the base…
JKamlah Apr 6, 2022
808248b
Optimize: Use integers instead of floats.
JKamlah Mar 10, 2023
a447ce5
Fix: Id creation on wordlevel.
JKamlah Mar 10, 2023
c8d18fd
Rework to make it PAGE-XML-Schema valid.
Mar 20, 2024
68cf702
Update src/api/pagerenderer.cpp (add missing include statements)
stweil Mar 20, 2024
09b5117
Apply suggestions from code review by @stweil
JKamlah Mar 20, 2024
be62873
Add terminating linefeed, delete trailing whitespaces and fix some ty…
Mar 20, 2024
6621e5a
Remove type information from metadata, dont print reading direction f…
Mar 20, 2024
d885a4d
Fix some issues mentioned by codacy.
Mar 20, 2024
83587ab
Fix some issues mentioned by codacy.
Mar 20, 2024
f294bb2
Formatting with clang and added parethesis to one-line if statements.
Mar 22, 2024
ed966fd
Update src/ccmain/tesseractclass.cpp
JKamlah Mar 22, 2024
4d52d1b
Apply suggestions from code review
JKamlah Mar 22, 2024
9130d34
Update src/api/pagerenderer.cpp
JKamlah Mar 22, 2024
4d3737c
Refactor: Enforce 'page' cmd, rename params, and prune unused vars
Mar 22, 2024
49abc07
Fix typos for level description.
Mar 22, 2024
df29f8b
Change generation of line string to default (as text).
Mar 26, 2024
ea659cb
Fix problem, if all original baselinepoints are outside of the new po…
Apr 9, 2024
cdf6e5d
Use fallback bbox values for text with orientation with 90 and 180 de…
Apr 9, 2024
81f0ebb
Rename flag for skewed lines.
Apr 9, 2024
a84e4be
Delete old comments.
Apr 9, 2024
65a40ec
Fix XML escape for UTF-8 content.
Apr 12, 2024
4e9053b
Check for skewed lines on TextRegion level.
Apr 12, 2024
bc12457
Format code with clang-format
stweil Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ set(TESSERACT_SRC
src/api/capi.cpp
src/api/renderer.cpp
src/api/altorenderer.cpp
src/api/pagerenderer.cpp
src/api/hocrrenderer.cpp
src/api/lstmboxrenderer.cpp
src/api/pdfrenderer.cpp
Expand All @@ -764,6 +765,7 @@ set(TESSERACT_CONFIGS
tessdata/configs/lstmbox
tessdata/configs/lstmdebug
tessdata/configs/makebox
tessdata/configs/page
tessdata/configs/pdf
tessdata/configs/quiet
tessdata/configs/rebox
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ libtesseract_la_LDFLAGS += -version-info $(GENERIC_LIBRARY_VERSION)

libtesseract_la_SOURCES = src/api/baseapi.cpp
libtesseract_la_SOURCES += src/api/altorenderer.cpp
libtesseract_la_SOURCES += src/api/pagerenderer.cpp
libtesseract_la_SOURCES += src/api/capi.cpp
libtesseract_la_SOURCES += src/api/hocrrenderer.cpp
libtesseract_la_SOURCES += src/api/lstmboxrenderer.cpp
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Tesseract has **unicode (UTF-8) support**, and can **recognize [more than 100 la

Tesseract supports **[various image formats](https://tesseract-ocr.github.io/tessdoc/InputFormats)** including PNG, JPEG and TIFF.

Tesseract supports **various output formats**: plain text, hOCR (HTML), PDF, invisible-text-only PDF, TSV and ALTO.
Tesseract supports **various output formats**: plain text, hOCR (HTML), PDF, invisible-text-only PDF, TSV, ALTO and PAGE.

You should note that in many cases, in order to get better OCR results, you'll need to **[improve the quality](https://tesseract-ocr.github.io/tessdoc/ImproveQuality.html) of the image** you are giving Tesseract.

Expand Down
4 changes: 4 additions & 0 deletions doc/tesseract.1.asc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ OPTIONS

* *alto* -- Output in ALTO format ('OUTPUTBASE'`.xml`).
* *hocr* -- Output in hOCR format ('OUTPUTBASE'`.hocr`).
* *page* -- Output in PAGE format ('OUTPUTBASE'`.page.xml`).
The output can be customized with the flags:
page_xml_polygon -- Create polygons instead of bounding boxes (default: true)
page_xml_level -- Create the PAGE file on 0=linelevel or 1=wordlevel (default: 0)
* *pdf* -- Output PDF ('OUTPUTBASE'`.pdf`).
* *tsv* -- Output TSV ('OUTPUTBASE'`.tsv`).
* *txt* -- Output plain text ('OUTPUTBASE'`.txt`).
Expand Down
12 changes: 12 additions & 0 deletions include/tesseract/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,18 @@ class TESS_API TessBaseAPI {
*/
char *GetAltoText(int page_number);

/**
* Make an XML-formatted string with PAGE markup from the internal
* data structures.
*/
char *GetPAGEText(ETEXT_DESC *monitor, int page_number);

/**
* Make an XML-formatted string with PAGE markup from the internal
* data structures.
*/
char *GetPAGEText(int page_number);

stweil marked this conversation as resolved.
Show resolved Hide resolved
/**
* Make a TSV-formatted string from the internal data structures.
* page_number is 0-based but will appear in the output as 1-based.
Expand Down
17 changes: 17 additions & 0 deletions include/tesseract/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ class TESS_API TessAltoRenderer : public TessResultRenderer {
bool begin_document;
};

/**
* Renders Tesseract output into a PAGE XML text string
*/
class TESS_API TessPAGERenderer : public TessResultRenderer {
public:
explicit TessPAGERenderer(const char *outputbase);

protected:
bool BeginDocumentHandler() override;
bool AddImageHandler(TessBaseAPI *api) override;
bool EndDocumentHandler() override;

private:
bool begin_document;
};


/**
* Renders Tesseract output into a TSV string
*/
Expand Down
8 changes: 8 additions & 0 deletions src/api/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ TessResultRenderer *TessAltoRendererCreate(const char *outputbase) {
return new tesseract::TessAltoRenderer(outputbase);
}

TessResultRenderer *TessPAGERendererCreate(const char *outputbase) {
return new tesseract::TessPAGERenderer(outputbase);
}

TessResultRenderer *TessTsvRendererCreate(const char *outputbase) {
return new tesseract::TessTsvRenderer(outputbase);
}
Expand Down Expand Up @@ -420,6 +424,10 @@ char *TessBaseAPIGetAltoText(TessBaseAPI *handle, int page_number) {
return handle->GetAltoText(page_number);
}

char *TessBaseAPIGetPAGEText(TessBaseAPI *handle, int page_number) {
return handle->GetPAGEText(page_number);
}

char *TessBaseAPIGetTsvText(TessBaseAPI *handle, int page_number) {
return handle->GetTSVText(page_number);
}
Expand Down
Loading
Loading