diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-31 11:43:49 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-01-01 11:51:46 +0530 |
| commit | 5262d942c4c2c36529fbe704e7de165044e6dc99 (patch) | |
| tree | 9fb782f19e564bdc9c7ab6852238e12a6b6f85f3 /cpp/libchelleport.cpp | |
| parent | 2f35bbd272d7b1414003bf437cc6ad675fe81400 (diff) | |
| download | chelleport-5262d942c4c2c36529fbe704e7de165044e6dc99.tar.gz chelleport-5262d942c4c2c36529fbe704e7de165044e6dc99.zip | |
Add timing measurement for each section of screen
Diffstat (limited to '')
| -rw-r--r-- | cpp/libchelleport.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/cpp/libchelleport.cpp b/cpp/libchelleport.cpp index 010fdd4..ff3f7d6 100644 --- a/cpp/libchelleport.cpp +++ b/cpp/libchelleport.cpp @@ -24,6 +24,7 @@ extern "C" OCRMatch *findWordCoordinates(const char *image_path, int *size) { OCRMatchSet extractTextMatches(const char *imagePath) { Pix *image = image::loadImage(imagePath); + if (image == nullptr) { return OCRMatchSet(); } @@ -35,17 +36,17 @@ OCRMatchSet extractTextMatches(const char *imagePath) { int height = pixGetHeight(image); std::vector<std::unique_ptr<Recognizer>> recognizers; - recognizers.push_back( - std::make_unique<Recognizer>(0, 0, width / 2, height / 2)); + // clang-format off recognizers.push_back( - std::make_unique<Recognizer>(width / 2, 0, width / 2, height / 2)); - + std::make_unique<Recognizer>("top-left", 0, 0, width / 2, height / 2)); recognizers.push_back( - std::make_unique<Recognizer>(0, height / 2, width / 2, height / 2)); - - recognizers.push_back(std::make_unique<Recognizer>(width / 2, height / 2, - width / 2, height / 2)); + std::make_unique<Recognizer>("top-right", width / 2, 0, width / 2, height / 2)); + recognizers.push_back( + std::make_unique<Recognizer>("bottom-left", 0, height / 2, width / 2, height / 2)); + recognizers.push_back( + std::make_unique<Recognizer>("bottom-right", width / 2, height / 2, width / 2, height / 2)); + // clang-format on return runRecognizers(recognizers, image); } @@ -59,9 +60,10 @@ runRecognizers(std::vector<std::unique_ptr<Recognizer>> &recognizers, std::vector<std::thread> workers; workers.reserve(recognizers.size()); - for (auto &ext : recognizers) { - workers.push_back(std::thread( - [&ext, &sharedImage]() { ext->recognize(sharedImage.get()); })); + for (auto &recognizer : recognizers) { + workers.push_back(std::thread([&recognizer, &sharedImage]() { + MEASURE(recognizer->id, { recognizer->recognize(sharedImage.get()); }) + })); } for (std::thread &t : workers) { @@ -69,8 +71,8 @@ runRecognizers(std::vector<std::unique_ptr<Recognizer>> &recognizers, t.join(); } - for (auto &ext : recognizers) { - for (auto &match : ext->getResults()) + for (auto &recognizer : recognizers) { + for (auto &match : recognizer->getResults()) results.insert(match); } |
