-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update OCR Plugin features and add new localization strings (#21)
* Update OCR Plugin features and add new localization strings * Refactor OCR filter properties callback in ocr-filter.cpp and include necessary headers in text-render-helper.cpp
- Loading branch information
Showing
11 changed files
with
163 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "text-render-helper.h" | ||
|
||
#include <QPainter> | ||
#include <QPixmap> | ||
|
||
/** | ||
* Render text to a buffer using QTextDocument | ||
* @param text Text to render | ||
* @param width Output width | ||
* @param height Output height | ||
* @param data Output buffer, user must free | ||
* @param css_props CSS properties to apply to the text | ||
*/ | ||
QImage render_boxes_with_qtextdocument(const std::vector<OCRBox> &boxes, uint32_t width, | ||
uint32_t height) | ||
{ | ||
QPixmap pixmap(width, height); | ||
pixmap.fill(Qt::transparent); | ||
QPainter painter; | ||
painter.begin(&pixmap); | ||
painter.setCompositionMode(QPainter::CompositionMode_Source); | ||
|
||
// draw individual boxes on the pixmap | ||
for (const OCRBox &box : boxes) { | ||
painter.setPen(Qt::blue); | ||
// set the character size according to the box height | ||
QFont font = painter.font(); | ||
font.setPixelSize(box.box.height); | ||
painter.setFont(font); | ||
painter.drawText(box.box.x, box.box.y + box.box.height, | ||
QString::fromStdString(box.text)); | ||
} | ||
|
||
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); | ||
painter.end(); | ||
|
||
return pixmap.toImage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef TEXT_RENDER_HELPER_H | ||
#define TEXT_RENDER_HELPER_H | ||
|
||
#include "tesseract-ocr-utils.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <QImage> | ||
|
||
QImage render_boxes_with_qtextdocument(const std::vector<OCRBox> &boxes, uint32_t width, | ||
uint32_t height); | ||
|
||
#endif // TEXT_RENDER_HELPER_H |