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