实现 tesseract 的核心部分打包
This commit is contained in:
parent
1c92b6fddd
commit
8f8106a0a3
@ -5,6 +5,7 @@ import { routeMessage } from './common/router';
|
||||
import { VSCodeWebViewLike } from './hook/adapter';
|
||||
import path from 'node:path';
|
||||
import * as fs from 'node:fs';
|
||||
import { setRunningCWD } from './hook/setting';
|
||||
|
||||
export interface VSCodeMessage {
|
||||
command: string;
|
||||
@ -94,6 +95,9 @@ function updateConnectionOption(data: any) {
|
||||
}
|
||||
}
|
||||
|
||||
const devHome = path.join(__dirname, '..', '..');
|
||||
setRunningCWD(devHome);
|
||||
|
||||
wss.on('connection', ws => {
|
||||
|
||||
// 仿造 webview 进行统一接口访问
|
||||
|
@ -47,17 +47,23 @@ export async function tesseractOCR(
|
||||
logger: (message: Tesseract.LoggerMessage) => void,
|
||||
lang: string = 'eng+chi_sim'
|
||||
) {
|
||||
|
||||
const ocrHome = path.join(RUNNING_CWD, 'resources', 'ocr');
|
||||
|
||||
if (!ocrHome) {
|
||||
console.log('ocr 目录不存在');
|
||||
return '安装包已经损坏';
|
||||
}
|
||||
|
||||
try {
|
||||
const { data: { text } } = await Tesseract.recognize(
|
||||
imagePath,
|
||||
lang,
|
||||
{
|
||||
logger,
|
||||
langPath: './',
|
||||
gzip: false,
|
||||
cacheMethod: 'cache',
|
||||
cachePath: RUNNING_CWD
|
||||
langPath: ocrHome,
|
||||
corePath: ocrHome,
|
||||
workerPath: path.join(ocrHome, 'worker.js'),
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -14,8 +14,9 @@ export class HookController {
|
||||
console.log('test ocr begin');
|
||||
|
||||
const cachePath = context.extensionPath;
|
||||
const workerPath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.js');
|
||||
const corePath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.wasm');
|
||||
const workerPath = path.join(cachePath, 'resources', 'ocr', 'worker.js');
|
||||
const corePath = path.join(cachePath, 'resources', 'ocr');
|
||||
const langPath = path.join(cachePath,'resources', 'ocr');
|
||||
|
||||
console.log('workerPath', workerPath);
|
||||
console.log('corePath', corePath);
|
||||
@ -26,10 +27,8 @@ export class HookController {
|
||||
'eng+chi_sim',
|
||||
{
|
||||
logger: (m) => console.log(m),
|
||||
langPath: './',
|
||||
langPath,
|
||||
gzip: false,
|
||||
cacheMethod: 'cache',
|
||||
cachePath,
|
||||
workerPath,
|
||||
corePath
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user