/** * OnnxOCR配置参数使用示例 * * 这个文件展示了如何在 ocr-dialog-block-reg.js 中配置 OnnxOCR 的所有参数 */ import { startOcrDialogBlockReg, createOcrConfig, getPresetConfig } from './ocr-dialog-block-reg.js'; // ============================================================================ // 使用方式1: 使用预设配置 // ============================================================================ async function usePresetConfig() { const imagePath = "your_image.png"; const textBlocksJsonPath = "output/text_blocks.json"; const textRegionImagePath = "output/text_region.png"; // 获取高精度预设配置 const config = getPresetConfig('high_precision'); const result = await startOcrDialogBlockReg( imagePath, textBlocksJsonPath, textRegionImagePath, config ); } // ============================================================================ // 使用方式2: 创建自定义配置 // ============================================================================ async function useCustomConfig() { const imagePath = "your_image.png"; const textBlocksJsonPath = "output/text_blocks.json"; const textRegionImagePath = "output/text_region.png"; // 创建自定义配置 const config = createOcrConfig({ // 检测参数(影响能检测到多少文字区域) det_db_thresh: 0.15, // 检测阈值:0.1-0.5,越小检测越敏感 det_db_box_thresh: 0.45, // 框置信度:0.3-0.8,越小检测更多框 det_limit_side_len: 1536, # 处理尺寸:640/960/1280/1536,越大精度越高 // 识别参数(影响文字识别准确度) drop_score: 0.25, // 识别阈值:0.2-0.6,越小保留更多结果 use_angle_cls: true, // 角度分类器:true提高倾斜文字识别 // 高级参数 det_db_unclip_ratio: 1.6, // 框扩展比例:1.2-2.0 det_box_type: "quad", // 检测框类型:quad/poly use_dilation: false, // 膨胀操作:true可能提高小文字检测 det_db_score_mode: "fast" // 计算模式:fast/slow }); const result = await startOcrDialogBlockReg( imagePath, textBlocksJsonPath, textRegionImagePath, config ); } // ============================================================================ // 使用方式3: 直接传入配置对象 // ============================================================================ async function useDirectConfig() { const imagePath = "your_image.png"; const textBlocksJsonPath = "output/text_blocks.json"; const textRegionImagePath = "output/text_region.png"; // 直接传入配置对象 const result = await startOcrDialogBlockReg( imagePath, textBlocksJsonPath, textRegionImagePath, { det_db_thresh: 0.2, det_db_box_thresh: 0.5, det_limit_side_len: 1280, drop_score: 0.3, use_angle_cls: true } ); } // ============================================================================ // 预设配置说明 // ============================================================================ /* 可用的预设配置: 1. 'balanced' (平衡配置) - 默认 - 速度和精度平衡 - 适合大多数场景 2. 'high_precision' (高精度配置) - 识别更准确,检测更多区域 - 速度较慢,适合要求高精度的场景 3. 'fast' (快速配置) - 速度优先,精度稍低 - 适合实时处理或大批量处理 */ // ============================================================================ // 参数详细说明 // ============================================================================ /* 主要参数说明: 📍 检测相关参数: - det_db_thresh: 文字检测阈值 (0.1-0.5) * 越小 = 检测越敏感,能找到更多文字区域 * 越大 = 检测越严格,只保留明显的文字区域 - det_db_box_thresh: 文字框置信度阈值 (0.3-0.8) * 越小 = 保留更多候选框 * 越大 = 只保留高置信度的框 - det_limit_side_len: 图片处理尺寸 (640/960/1280/1536) * 越大 = 精度越高,但速度越慢 * 越小 = 速度越快,但可能漏检小文字 📝 识别相关参数: - drop_score: 识别置信度阈值 (0.2-0.6) * 越小 = 保留更多识别结果(包括不确定的) * 越大 = 只保留高置信度的识别结果 - use_angle_cls: 角度分类器 (true/false) * true = 能更好识别倾斜、旋转的文字 * false = 速度更快,但对倾斜文字效果差 🔧 高级参数: - det_db_unclip_ratio: 文字框扩展比例 (1.2-2.0) * 控制检测框相对于实际文字的大小 * 越大 = 框越大,能包含更多边缘文字 - rec_image_shape: 识别图片尺寸 ("3, 48, 320") * 固定值,不建议修改(模型限制) - det_box_type: 检测框类型 ("quad"/"poly") * quad = 四边形框(推荐) * poly = 多边形框(更精确但复杂) */ export { usePresetConfig, useCustomConfig, useDirectConfig };