-
Notifications
You must be signed in to change notification settings - Fork 20
feat: Enhance OCR plugin loading mechanism #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Implemented logic to check for the availability of the OCR V5 plugin and load it if present. - Added fallback to load the default OCR plugin if the OCR V5 plugin fails to load. This change improves the flexibility and robustness of the OCR engine's plugin management.
|
TAG Bot TAG: 6.5.12 |
- update version to 6.5.12 log: update version to 6.5.12
4dbd05a to
5e26c72
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
2 similar comments
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review我来对这个diff进行审查:
改进建议代码: // 在类定义中添加常量
static const QString OCR_V5_PLUGIN = "PPOCR_V5";
// 构造函数中的改进实现
OCREngine::OCREngine()
{
qCInfo(dmOcr) << "Initializing OCR driver";
ocrDriver = new Dtk::Ocr::DOcr;
bool isPluginLoaded = ocrDriver->loadPlugin(OCR_V5_PLUGIN);
if (isPluginLoaded) {
qCInfo(dmOcr) << "OCR V5 plugin loaded successfully";
} else {
qCWarning(dmOcr) << "Failed to load OCR V5 plugin, falling back to default";
ocrDriver->loadDefaultPlugin();
qCInfo(dmOcr) << "Default OCR plugin loaded";
}
// TODO: Make thread count configurable
ocrDriver->setUseMaxThreadsCount(2);
// TODO: Add GPU detection and configuration
QFileInfo mtfi("/dev/mtgpu.0");
if (mtfi.exists()) {
// ...
}
}
这些改进将使代码更加健壮、安全和易于维护。 |
deepin pr auto review我来对这段代码进行审查:
改进后的代码示例: OCREngine::OCREngine()
: ocrDriver(nullptr)
{
// 定义常量
static const QString OCR_V5_PLUGIN_NAME = "PPOCR_V5";
static const QString MTGPU_DEVICE_PATH = "/dev/mtgpu.0";
qCInfo(dmOcr) << "Initializing OCR driver";
// 使用智能指针管理资源
ocrDriver = std::make_unique<Dtk::Ocr::DOcr>();
bool isV5PluginLoaded = false;
// 获取已安装插件列表(考虑缓存)
const auto plugins = ocrDriver->installedPluginNames();
const QString normalizedPluginName = OCR_V5_PLUGIN_NAME.toLower();
// 检查并尝试加载V5插件
if (std::any_of(plugins.begin(), plugins.end(),
[&normalizedPluginName](const QString& plugin) {
return plugin.toLower() == normalizedPluginName;
})) {
if (ocrDriver->loadPlugin(OCR_V5_PLUGIN_NAME)) {
isV5PluginLoaded = true;
qCInfo(dmOcr) << "Successfully loaded OCR V5 plugin";
} else {
qCWarning(dmOcr) << "Failed to load OCR V5 plugin, falling back to default";
}
}
// 如果V5插件加载失败,使用默认插件
if (!isV5PluginLoaded) {
ocrDriver->loadDefaultPlugin();
qCInfo(dmOcr) << "Default OCR plugin loaded";
}
// 设置线程数
ocrDriver->setUseMaxThreadsCount(2);
// 检查MTGPU设备
if (QFileInfo::exists(MTGPU_DEVICE_PATH)) {
// 处理MTGPU相关逻辑
}
}这些改进提高了代码的可维护性、性能和安全性,同时保持了原有功能的完整性。 |
feat: Enhance OCR plugin loading mechanism
This change improves the flexibility and robustness of the OCR engine's plugin management.