From 5262d942c4c2c36529fbe704e7de165044e6dc99 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 31 Dec 2024 11:43:49 +0530 Subject: Add timing measurement for each section of screen --- cpp/libchelleport.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'cpp/libchelleport.cpp') 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> recognizers; - recognizers.push_back( - std::make_unique(0, 0, width / 2, height / 2)); + // clang-format off recognizers.push_back( - std::make_unique(width / 2, 0, width / 2, height / 2)); - + std::make_unique("top-left", 0, 0, width / 2, height / 2)); recognizers.push_back( - std::make_unique(0, height / 2, width / 2, height / 2)); - - recognizers.push_back(std::make_unique(width / 2, height / 2, - width / 2, height / 2)); + std::make_unique("top-right", width / 2, 0, width / 2, height / 2)); + recognizers.push_back( + std::make_unique("bottom-left", 0, height / 2, width / 2, height / 2)); + recognizers.push_back( + std::make_unique("bottom-right", width / 2, height / 2, width / 2, height / 2)); + // clang-format on return runRecognizers(recognizers, image); } @@ -59,9 +60,10 @@ runRecognizers(std::vector> &recognizers, std::vector 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> &recognizers, t.join(); } - for (auto &ext : recognizers) { - for (auto &match : ext->getResults()) + for (auto &recognizer : recognizers) { + for (auto &match : recognizer->getResults()) results.insert(match); } -- cgit v1.3.1