aboutsummaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/libchelleport.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/cpp/libchelleport.cpp b/cpp/libchelleport.cpp
index 345a454..4ec3599 100644
--- a/cpp/libchelleport.cpp
+++ b/cpp/libchelleport.cpp
@@ -10,25 +10,16 @@
#include "../include/libchelleport.h"
-std::vector<OCRMatch> extractTextCoordinates(const char *imagePath);
-
-#define CONFIDENCE_THRESHOLD 30.
-#define MIN_CHARACTER_COUNT 2
-const tesseract::PageIteratorLevel RESULT_ITER_MODE = tesseract::RIL_WORD;
-
OCRMatch *findWordCoordinates(const char *image_path, int *size) {
- auto boxes = extractTextCoordinates(image_path);
- static OCRMatch *ptr = new OCRMatch[boxes.size()];
- std::copy(boxes.begin(), boxes.end(), ptr);
+ auto matches = extractTextCoordinates(image_path);
+
+ static OCRMatch *ptr = new OCRMatch[matches.size()];
+ std::copy(matches.begin(), matches.end(), ptr);
- // for (const auto &box : boxes) {
- // std::cout << box.text << "\n\n";
- // std::cout << "Text: " << box.text << "\nPosition: (" << box.startX << ","
- // << box.startY << ") -> (" << box.endX << "," << box.endY << ")"
- // << "\n\n";
- // }
+ // for (const auto &match : matches)
+ // showMatch(match);
- *size = boxes.size();
+ *size = matches.size();
return ptr;
}
@@ -52,16 +43,16 @@ std::vector<OCRMatch> extractTextCoordinates(const char *imagePath) {
tesseract::ResultIterator *iterator = tesseract->GetIterator();
auto level = RESULT_ITER_MODE;
+ int x1, y1, x2, y2;
if (iterator != 0) {
do {
float conf = iterator->Confidence(level);
const char *word = iterator->GetUTF8Text(level);
- int x1, y1, x2, y2;
- iterator->BoundingBox(level, &x1, &y1, &x2, &y2);
if (conf > CONFIDENCE_THRESHOLD && word != nullptr &&
strlen(word) >= MIN_CHARACTER_COUNT) {
+ iterator->BoundingBox(level, &x1, &y1, &x2, &y2);
results.push_back(OCRMatch{x1, y1, x2, y2, word});
}
} while (iterator->Next(level));
@@ -74,3 +65,9 @@ std::vector<OCRMatch> extractTextCoordinates(const char *imagePath) {
return results;
}
+
+void showMatch(const OCRMatch &match) {
+ std::cout << "Text: " << match.text << "; Position: (" << match.startX << ","
+ << match.startY << ") -> (" << match.endX << "," << match.endY
+ << ")" << "\n\n";
+}