change recognizer output format

master
UnknownObject 2 months ago
parent d070976d35
commit 521273638d

@ -37,8 +37,8 @@ int main()
auto results = uns::EasyOCR_CPP::FullAuto(img); auto results = uns::EasyOCR_CPP::FullAuto(img);
for (const auto& [index, info] : results) for (const auto& [index, info] : results)
{ {
const auto& [text, conf] = info; const auto& [text, conf, rect] = info;
std::cout << "Box " << index << ": \"" << uns::EOCR_SupportTools::WtoA(text) << "\" Confidence=" << conf << "\n"; printf("Result %d: Text = {%s}, Box = [%d, %d, %d, %d], Confidence = %.3f\n", (int)index, uns::EOCR_SupportTools::WtoA(text).c_str(), rect.tl().x, rect.tl().y, rect.br().x, rect.br().y, conf);
} }
uns::EasyOCR_CPP::CleanupOCR(); uns::EasyOCR_CPP::CleanupOCR();

@ -32,8 +32,9 @@ namespace uns
EN_CH EN_CH
}; };
using EOCR_Result = std::pair<std::wstring, float>; using EOCR_Result = std::tuple<std::wstring, float>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result>; using EOCR_Result_Single = std::tuple<std::wstring, float, cv::Rect>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result_Single>;
using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>; using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>;
} }

Binary file not shown.

Binary file not shown.

@ -45,16 +45,19 @@ int main()
cv::blur(image, image, { 3,3 }); cv::blur(image, image, { 3,3 });
//WarmUP GPU //WarmUP GPU
for (int i = 0; i < 10; i++) if (uns::G_OCRConfig.GetGPUUsage() != uns::OCRConfig::GPUUsage::CPUOnly)
{ {
std::cout << "Warming UP GPU (" << i << ") ......" << std::endl; for (int i = 0; i < 10; i++)
clock_t start = clock(); {
auto rects = detector(image); std::cout << "Warming UP GPU (" << i << ") ......" << std::endl;
auto results = recognizer(image, rects); clock_t start = clock();
clock_t end = clock(); auto rects = detector(image);
std::cout << "Warm UP [" << i << "] Cost " << static_cast<double>(end - start) / static_cast<double>(CLOCKS_PER_SEC) << " Second(s)" << std::endl; auto results = recognizer(image, rects);
clock_t end = clock();
std::cout << "Warm UP [" << i << "] Cost " << static_cast<double>(end - start) / static_cast<double>(CLOCKS_PER_SEC) << " Second(s)" << std::endl;
}
std::cout << "GPU Warm UP Finished" << std::endl;
} }
std::cout << "GPU Warm UP Finished" << std::endl;
//Begin OCR //Begin OCR
clock_t start = clock(); clock_t start = clock();
@ -64,8 +67,8 @@ int main()
clock_t recognize_finished = clock(); clock_t recognize_finished = clock();
for (const auto& [index, info] : results) for (const auto& [index, info] : results)
{ {
const auto& [text, conf] = info; const auto& [text, conf, rect] = info;
std::cout << "Box " << index << ": \"" << WtoA(text) << "\" Confidence=" << conf << "\n"; printf("Result %d: Text = {%s}, Box = [%d, %d, %d, %d], Confidence = %.3f\n", (int)index, WtoA(text).c_str(), rect.tl().x, rect.tl().y, rect.br().x, rect.br().y, conf);
} }
//Output Time Cost //Output Time Cost

@ -377,7 +377,7 @@ uns::EOCR_ResultSet uns::EasyOCR_Recognizer::operator()(const cv::Mat& full_imag
if (crop.empty()) if (crop.empty())
continue; continue;
auto [text, conf] = (*this)(crop); auto [text, conf] = (*this)(crop);
result_set.insert({ i, { text, conf } }); result_set.insert({ i, { text, conf, rect } });
} }
return result_set; return result_set;
} }

@ -11,8 +11,9 @@ namespace uns
using VecFloat = std::vector<float>; using VecFloat = std::vector<float>;
using IONames = std::vector<const char*>; using IONames = std::vector<const char*>;
using IONamesStorage = std::vector<std::string>; using IONamesStorage = std::vector<std::string>;
using EOCR_Result = std::pair<std::wstring, float>; using EOCR_Result = std::tuple<std::wstring, float>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result>; using EOCR_Result_Single = std::tuple<std::wstring, float, cv::Rect>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result_Single>;
using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>; using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>;
class OCRToolBox class OCRToolBox

@ -378,7 +378,7 @@ uns::EOCR_ResultSet uns::EasyOCR_Recognizer::operator()(const cv::Mat& full_imag
if (crop.empty()) if (crop.empty())
continue; continue;
auto [text, conf] = (*this)(crop); auto [text, conf] = (*this)(crop);
result_set.insert({ i, { text, conf } }); result_set.insert({ i, { text, conf, rect } });
} }
return result_set; return result_set;
} }

@ -10,8 +10,9 @@ namespace uns
{ {
namespace easyocr namespace easyocr
{ {
using EOCR_Result = std::pair<std::wstring, float>; using EOCR_Result = std::tuple<std::wstring, float>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result>; using EOCR_Result_Single = std::tuple<std::wstring, float, cv::Rect>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result_Single>;
using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>; using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>;
} }

@ -3,6 +3,9 @@
uns::OCRConfig uns::G_OCRConfig; uns::OCRConfig uns::G_OCRConfig;
std::wstring detect_model_path;
std::wstring recognize_model_path;
uns::OCRConfig::OCRConfig() uns::OCRConfig::OCRConfig()
{ {
language = easyocr::CharsetType::EN; language = easyocr::CharsetType::EN;

@ -25,8 +25,6 @@ namespace uns
private: private:
easyocr::GPUUsage gpu_usage; easyocr::GPUUsage gpu_usage;
easyocr::CharsetType language; easyocr::CharsetType language;
std::wstring detect_model_path;
std::wstring recognize_model_path;
public: public:
OCRConfig(); OCRConfig();

@ -11,8 +11,9 @@ namespace uns
using VecFloat = std::vector<float>; using VecFloat = std::vector<float>;
using IONames = std::vector<const char*>; using IONames = std::vector<const char*>;
using IONamesStorage = std::vector<std::string>; using IONamesStorage = std::vector<std::string>;
using EOCR_Result = std::pair<std::wstring, float>; using EOCR_Result = std::tuple<std::wstring, float>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result>; using EOCR_Result_Single = std::tuple<std::wstring, float, cv::Rect>;
using EOCR_ResultSet = std::map<size_t, EOCR_Result_Single>;
using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>; using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>;
class OCRToolBox class OCRToolBox

Loading…
Cancel
Save