| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /**
- * 测试步骤6:检查格子可视化图片生成
- */
- import fs from 'fs';
- import path from 'path';
- import { fileURLToPath } from 'url';
- import { start as startCheckReg } from '../check-reg.js';
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = path.dirname(__filename);
- function getProjectRoot() {
- return path.join(__dirname, '..', '..');
- }
- async function testStep6() {
- try {
- const projectRoot = getProjectRoot();
-
- const imagePath = path.join(
- projectRoot,
- 'static',
- '漫画',
- 'image',
- '鬼-巷第001卷',
- '第一章',
- '0004_鬼-巷第001卷.jpeg'
- );
-
- const tmpDir = path.join(
- projectRoot,
- 'static',
- '漫画',
- 'image',
- '鬼-巷第001卷',
- '第一章',
- 'test',
- 'tmp'
- );
-
- const textMaskPath = path.join(tmpDir, '0004_鬼-巷第001卷_text_mask.png');
-
- if (!fs.existsSync(imagePath)) {
- throw new Error(`图片不存在: ${imagePath}`);
- }
-
- if (!fs.existsSync(textMaskPath)) {
- throw new Error(`文字遮罩图不存在: ${textMaskPath}`);
- }
-
- console.log('='.repeat(60));
- console.log('🧪 测试步骤6:生成格子可视化图片(带绿色线框)');
- console.log('='.repeat(60));
- console.log(`📷 图片路径: ${imagePath}`);
- console.log(`📖 文字遮罩图: ${textMaskPath}`);
- console.log(`📂 输出目录: ${tmpDir}`);
-
- // 调用check-reg.js
- const panelResult = await startCheckReg(imagePath, tmpDir, textMaskPath, projectRoot);
-
- // 检查生成的图片
- const imageName = path.basename(imagePath, path.extname(imagePath));
- const panelVisualPath = panelResult.panelVisualPath || path.join(tmpDir, `${imageName}_panel_visual.png`);
- const panelMaskPath = panelResult.panelMaskPath || path.join(tmpDir, `${imageName}_panel_mask.png`);
-
- console.log('\n' + '='.repeat(60));
- console.log('📊 检查生成的文件');
- console.log('='.repeat(60));
-
- // 检查格子遮罩图
- if (fs.existsSync(panelMaskPath)) {
- const stats = fs.statSync(panelMaskPath);
- console.log(`✅ 格子遮罩图: ${path.basename(panelMaskPath)} (${(stats.size / 1024).toFixed(2)} KB)`);
- } else {
- console.log(`❌ 格子遮罩图不存在: ${panelMaskPath}`);
- }
-
- // 检查格子可视化图片(带绿色线框)
- if (fs.existsSync(panelVisualPath)) {
- const stats = fs.statSync(panelVisualPath);
- console.log(`✅ 格子可视化图片(带绿色线框): ${path.basename(panelVisualPath)} (${(stats.size / 1024).toFixed(2)} KB)`);
- console.log(` 📍 文件路径: ${panelVisualPath}`);
- console.log(` ✅ 图片已成功生成,包含绿色线框标记`);
- } else {
- console.log(`❌ 格子可视化图片不存在: ${panelVisualPath}`);
- console.log(` ⚠️ 请检查draw_panels.py脚本是否正常执行`);
- }
-
- // 检查panels数据
- if (panelResult.panels && panelResult.panels.length > 0) {
- console.log(`\n📊 检测到 ${panelResult.panels.length} 个格子:`);
- panelResult.panels.forEach((panel, index) => {
- console.log(` ${index + 1}. 格子 ${index + 1}: x=${panel.x}, y=${panel.y}, width=${panel.width}, height=${panel.height}`);
- });
- }
-
- console.log('\n' + '='.repeat(60));
- console.log('✅ 测试完成!');
- console.log('='.repeat(60));
-
- return {
- success: fs.existsSync(panelVisualPath),
- panelVisualPath: panelVisualPath,
- panelMaskPath: panelMaskPath,
- panels: panelResult.panels || []
- };
-
- } catch (error) {
- console.error('\n❌ 测试失败:', error.message);
- if (error.stack) {
- console.error(error.stack);
- }
- throw error;
- }
- }
- // 执行测试
- testStep6();
- export { testStep6 };
|