| 123456789101112131415161718192021222324252627282930313233343536373839 |
- /**
- * 文字识别和定位功能(Node.js 实现)
- * 在截图中查找指定文字,并返回文字在截图中的坐标
- *
- * 注意:Python 脚本已被删除,此功能需要重新实现
- * 未来可以迁移到 Node.js 的 OCR 库(如 tesseract.js)
- */
- import { exec } from 'child_process';
- import { promisify } from 'util';
- import { join } from 'path';
- import { fileURLToPath } from 'url';
- import { dirname } from 'path';
- const execAsync = promisify(exec);
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = dirname(__filename);
- /**
- * 查找文字位置
- * @param {string} screenshotPath - 截图路径
- * @param {string} targetText - 目标文字
- * @param {number} deviceWidth - 设备宽度(可选)
- * @param {number} deviceHeight - 设备高度(可选)
- * @returns {Promise<{success: boolean, found?: boolean, x?: number, y?: number, width?: number, height?: number, error?: string}>}
- */
- export async function findTextLocation(screenshotPath, targetText, deviceWidth, deviceHeight) {
- try {
- // Python 脚本已被删除,此功能需要重新实现
- // TODO: 使用 Node.js 的 OCR 库(如 tesseract.js)重新实现
- return {
- success: false,
- found: false,
- error: 'string-reg-location.py 已被删除,此功能需要重新实现。请使用 Node.js 的 OCR 库(如 tesseract.js)。'
- };
- } catch (error) {
- return { success: false, found: false, error: error.message };
- }
- }
|