From 397c0a613e66487fead7afb4b89b783d887389f3 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 28 Dec 2024 14:38:55 +0530 Subject: Create a sorted list of ocr matches by position on screen --- cpp/libchelleport.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'cpp/libchelleport.cpp') diff --git a/cpp/libchelleport.cpp b/cpp/libchelleport.cpp index 20c2d4f..5845bc4 100644 --- a/cpp/libchelleport.cpp +++ b/cpp/libchelleport.cpp @@ -10,7 +10,7 @@ #include "../include/recognizer.h" extern "C" OCRMatch *findWordCoordinates(const char *image_path, int *size) { - std::vector matches; + OCRMatchSet matches; MEASURE("OCR", { matches = extractTextMatches(image_path); }); std::cout << "Match count: " << matches.size() << std::endl; @@ -22,12 +22,11 @@ extern "C" OCRMatch *findWordCoordinates(const char *image_path, int *size) { return ptr; } -std::vector extractTextMatches(const char *imagePath) { - std::vector results; - +OCRMatchSet extractTextMatches(const char *imagePath) { Pix *image = image::loadImage(imagePath); - if (image == nullptr) - return results; + if (image == nullptr) { + return OCRMatchSet(); + } // printf("imagePath: %s\n", imagePath); // pixWrite(imagePath, image, IFF_JFIF_JPEG); @@ -51,10 +50,10 @@ std::vector extractTextMatches(const char *imagePath) { return runRecognizers(recognizers, image); } -std::vector +OCRMatchSet runRecognizers(std::vector> &recognizers, Pix *image) { - std::vector results; + OCRMatchSet results; std::shared_ptr sharedImage(image, [](Pix *p) { pixDestroy(&p); }); std::vector workers; @@ -72,7 +71,7 @@ runRecognizers(std::vector> &recognizers, for (auto &ext : recognizers) { for (auto &match : ext->getResults()) - results.push_back(match); + results.insert(match); } return results; -- cgit v1.3.1