string-reg-location.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * 文字识别和定位功能(Node.js 实现)
  3. * 在截图中查找指定文字,并返回文字在截图中的坐标
  4. *
  5. * 注意:Python 脚本已被删除,此功能需要重新实现
  6. * 未来可以迁移到 Node.js 的 OCR 库(如 tesseract.js)
  7. */
  8. import { exec } from 'child_process';
  9. import { promisify } from 'util';
  10. import { join } from 'path';
  11. import { fileURLToPath } from 'url';
  12. import { dirname } from 'path';
  13. const execAsync = promisify(exec);
  14. const __filename = fileURLToPath(import.meta.url);
  15. const __dirname = dirname(__filename);
  16. /**
  17. * 查找文字位置
  18. * @param {string} screenshotPath - 截图路径
  19. * @param {string} targetText - 目标文字
  20. * @param {number} deviceWidth - 设备宽度(可选)
  21. * @param {number} deviceHeight - 设备高度(可选)
  22. * @returns {Promise<{success: boolean, found?: boolean, x?: number, y?: number, width?: number, height?: number, error?: string}>}
  23. */
  24. export async function findTextLocation(screenshotPath, targetText, deviceWidth, deviceHeight) {
  25. try {
  26. // Python 脚本已被删除,此功能需要重新实现
  27. // TODO: 使用 Node.js 的 OCR 库(如 tesseract.js)重新实现
  28. return {
  29. success: false,
  30. found: false,
  31. error: 'string-reg-location.py 已被删除,此功能需要重新实现。请使用 Node.js 的 OCR 库(如 tesseract.js)。'
  32. };
  33. } catch (error) {
  34. return { success: false, found: false, error: error.message };
  35. }
  36. }