diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-25 14:25:09 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-25 14:25:09 +0530 |
| commit | 4e74eeebbaa441cda3a6846c47d82516878f8f05 (patch) | |
| tree | 7a67bfd8cfbef2092931fd4d12a8ce69b3b3d2d4 /cpp/libchelleport.cpp | |
| parent | 82d612b7c37b432bc4abd8e158d6fe076d391ddc (diff) | |
| download | chelleport-4e74eeebbaa441cda3a6846c47d82516878f8f05.tar.gz chelleport-4e74eeebbaa441cda3a6846c47d82516878f8f05.zip | |
Add searching indication text for search mode + a lot of refactoring
Diffstat (limited to 'cpp/libchelleport.cpp')
| -rw-r--r-- | cpp/libchelleport.cpp | 33 |
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"; +} |
