From 1c65b30a6478cb509bf334a2fde641f61d114431 Mon Sep 17 00:00:00 2001 From: UnknownObject Date: Tue, 8 Jul 2025 15:00:22 +0800 Subject: [PATCH] fix repeat char bug --- EasyOCR-CPP/EasyOCR-CPP.cpp | 2 +- EasyOCR-CPP/OCRCharset.cpp | 5 +++++ LibEasyOCR-CPP/OCRCharset.cpp | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/EasyOCR-CPP/EasyOCR-CPP.cpp b/EasyOCR-CPP/EasyOCR-CPP.cpp index 836b0a6..62bdf3f 100644 --- a/EasyOCR-CPP/EasyOCR-CPP.cpp +++ b/EasyOCR-CPP/EasyOCR-CPP.cpp @@ -11,7 +11,7 @@ int main() const std::wstring detModelPath = L".\\DetectionModel.onnx"; const std::wstring recModelPath = L".\\RecognitionModel-EN.onnx"; const std::wstring recModelWithChnPath = L".\\RecognitionModel_EN+CH_SIM.onnx"; - const std::string imagePath = "..\\..\\vin.jpg"; + const std::string imagePath = "..\\..\\vin-err.jpg"; //Init Config uns::G_OCRConfig.SetGPUUsage(uns::OCRConfig::GPUUsage::CPUOnly); diff --git a/EasyOCR-CPP/OCRCharset.cpp b/EasyOCR-CPP/OCRCharset.cpp index 9e735d6..58de7e6 100644 --- a/EasyOCR-CPP/OCRCharset.cpp +++ b/EasyOCR-CPP/OCRCharset.cpp @@ -1,5 +1,6 @@ #include "OCRCharset.h" #include "OCRConfig.h" +#include #pragma warning(disable:6262) std::map uns::OCRCharset::en_charmap = @@ -6860,11 +6861,15 @@ std::wstring uns::OCRCharset::GetString(const std::vector& indexs) } if ((charset_ptr == nullptr)) return L""; + int last_index = 0; std::wstring result; for (const auto& index : indexs) { if (charset_ptr->find(index) == charset_ptr->end()) continue; + if (last_index == index) + continue; + last_index = index; if (index == 0) //Ignore 0 (Invalidate Value) continue; result += (*charset_ptr)[index]; diff --git a/LibEasyOCR-CPP/OCRCharset.cpp b/LibEasyOCR-CPP/OCRCharset.cpp index d938234..45f1c77 100644 --- a/LibEasyOCR-CPP/OCRCharset.cpp +++ b/LibEasyOCR-CPP/OCRCharset.cpp @@ -6861,11 +6861,15 @@ std::wstring uns::OCRCharset::GetString(const std::vector& indexs) } if ((charset_ptr == nullptr)) return L""; + int last_index = 0; std::wstring result; for (const auto& index : indexs) { if (charset_ptr->find(index) == charset_ptr->end()) continue; + if (last_index == index) + continue; + last_index = index; if (index == 0) //Ignore 0 (Invalidate Value) continue; result += (*charset_ptr)[index];