You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB
C++

// DLLUsageDemo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include "LibEasyOCR-CPP.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
int main()
{
std::wstring detect_model = L"..\\EasyOCR-CPP\\DetectionModel.onnx";
std::wstring recognize_model = L"..\\EasyOCR-CPP\\RecognitionModel-EN.onnx";
std::string image = "..\\..\\vin.jpg";
uns::EasyOCR_CPP::GlobalOCRConfig().SetDetectModelPath(detect_model);
uns::EasyOCR_CPP::GlobalOCRConfig().SetGPUUsage(uns::easyocr::GPUUsage::CPUOnly);
uns::EasyOCR_CPP::SetRecognitionModel(recognize_model, uns::easyocr::CharsetType::EN);
if (!uns::EasyOCR_CPP::InitDetectionModel())
{
std::cout << "Detector Init Failure!" << std::endl;
return -1;
}
if (!uns::EasyOCR_CPP::InitRecognitionModel())
{
std::cout << "Recognizer Init Failure!" << std::endl;
return -2;
}
cv::Mat img = uns::EOCR_SupportTools::ReadImage(image, true);
if (img.empty())
{
std::cerr << "Failed to load image: " << image << std::endl;
return -1;
}
auto results = uns::EasyOCR_CPP::FullAuto(img);
for (const auto& [index, info] : results)
{
const auto& [text, conf, rect] = info;
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();
return 0;
}