| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /**
- * OnnxOCR配置参数测试示例
- */
- import { startOcrDialogBlockReg, createOcrConfig, getPresetConfig } from '../ocr-dialog-block-reg.js';
- import path from 'path';
- async function testOcrConfigurations() {
- const imagePath = "static/漫画/image/鬼-巷第001卷/第一章/test/tmp/0004_鬼-巷第001卷_text_mask.png";
- const outputDir = "static/漫画/image/鬼-巷第001卷/第一章/test/tmp";
-
- console.log('🧪 OnnxOCR配置参数测试');
- console.log('=' * 60);
-
- // 测试1: 使用预设配置
- console.log('\n📋 测试1: 预设配置');
-
- const configs = [
- { name: '平衡配置', config: getPresetConfig('balanced') },
- { name: '高精度配置', config: getPresetConfig('high_precision') },
- { name: '快速配置', config: getPresetConfig('fast') }
- ];
-
- for (const { name, config } of configs) {
- console.log(`\n🔧 ${name}:`);
- console.log(JSON.stringify(config, null, 2));
-
- const textBlocksJsonPath = path.join(outputDir, `test_${name.replace(/\s+/g, '_')}_blocks.json`);
- const textRegionImagePath = path.join(outputDir, `test_${name.replace(/\s+/g, '_')}_region.png`);
-
- try {
- const result = await startOcrDialogBlockReg(imagePath, textBlocksJsonPath, textRegionImagePath, config);
- console.log(`✅ ${name} 完成: 识别到 ${result.totalCount} 个文字区域`);
- } catch (error) {
- console.log(`❌ ${name} 失败: ${error.message}`);
- }
- }
-
- // 测试2: 自定义配置
- console.log('\n📋 测试2: 自定义配置');
-
- const customConfigs = [
- {
- name: '超高精度配置',
- config: createOcrConfig({
- det_db_thresh: 0.1, // 极低检测阈值
- det_db_box_thresh: 0.4, // 极低框阈值
- det_limit_side_len: 1536, // 最大处理尺寸
- drop_score: 0.2, // 极低置信度阈值
- use_angle_cls: true,
- det_db_unclip_ratio: 1.8 // 更大的框扩展
- })
- },
- {
- name: '极速配置',
- config: createOcrConfig({
- det_db_thresh: 0.5, // 高检测阈值
- det_db_box_thresh: 0.8, // 高框阈值
- det_limit_side_len: 480, // 小处理尺寸
- drop_score: 0.7, // 高置信度阈值
- use_angle_cls: false, # 禁用角度分类器
- det_db_unclip_ratio: 1.2 // 小框扩展
- })
- }
- ];
-
- for (const { name, config } of customConfigs) {
- console.log(`\n🔧 ${name}:`);
- console.log(JSON.stringify(config, null, 2));
-
- const textBlocksJsonPath = path.join(outputDir, `test_${name.replace(/\s+/g, '_')}_blocks.json`);
- const textRegionImagePath = path.join(outputDir, `test_${name.replace(/\s+/g, '_')}_region.png`);
-
- try {
- const result = await startOcrDialogBlockReg(imagePath, textBlocksJsonPath, textRegionImagePath, config);
- console.log(`✅ ${name} 完成: 识别到 ${result.totalCount} 个文字区域`);
- } catch (error) {
- console.log(`❌ ${name} 失败: ${error.message}`);
- }
- }
-
- console.log('\n🎉 所有配置测试完成!');
- }
- // 运行测试
- testOcrConfigurations().catch(console.error);
|