/**
* runScript函数的参数
*/
export interface RunScriptArg {
/**
* 脚本文件绝对路径,可以是.js或者.py
*/
filePath: string;
/**
* 一并拷贝过来的文件
*/
togetherWith?: {
/**
* 一并拷贝过来的文件的路径
*/
files?: string[];
/**
* files的路径为相对还是绝对
*/
relative?: boolean;
};
/**
* 在哪个文件夹运行该文件(该文件夹会自动创建)
*/
atDir?: string;
/**
* 向该脚本发送的信息,
* 在Python中
def receive():
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
return json.loads(sys.stdin.read())
* 在Js中, process.on("message", (msgTo)=>{ })
*/
msgTo?: any;
/**
* 该脚本是否为Python,默认自动判断
*/
isPython?: boolean;
/**
* 一块拷贝到atDir目录下的文件或文件夹
*/
copyFiles?: string[];
/**
* 在收到脚本发来的msg之后运行的函数,
* 对于Python,如果returnJson为true, 该msg已经过JSON.parse
*/
onMsg?: (msg: any) => any;
/**
* 是否在收到msg时就kill这个process;
* 如果returnJson为true时, 只有收到了nodejs-result时才会kill,
* 否则只要收到了任意一个msg就会kill
*/
killOnMsg?: boolean;
/**
* 是否对收到的msg进行JSON.parse,(仅用于Python)
*/
returnJson?: boolean;
/**
* 是否在end时Log
*/
useLog?: boolean;
}
/**
* 运行一个nodejs或python脚本
* @example // 在python中接收msgTo
// def receive():
// import sys
// import io
// import json
// sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
// return json.loads(sys.stdin.read())
* @example // 在python中将结果返回给nodejs
// def returns(result):
// import json
// print(f"{json.dumps(result)}")
* @param option
* @returns 该脚本的运行结果
*/
export declare function runScript({ filePath: originPath, togetherWith: { files: env, relative }, atDir, msgTo, isPython, copyFiles, onMsg, killOnMsg, returnJson, useLog, }: RunScriptArg): Promise;
export declare function exec(command?: string): Promise;
/**
* paddleOcr 函数返回值相关内容
*/
export declare namespace PaddleOcr {
interface PosRaw {
/** x */
0: number;
/** y */
1: number;
}
interface ResultRowRaw {
/** 该字符串的位置(四个角) */
0: [PosRaw, PosRaw, PosRaw, PosRaw];
/** 该字符串的内容和准确度 */
1: {
/** 该字符串的内容 */
0: string;
/** 该字符串的准确度, 越1越准确 */
1: number;
};
}
interface Pos {
x: number;
y: number;
}
interface ResultRow {
/** 该字符串的位置(四个角) */
pos: [Pos, Pos, Pos, Pos];
/** 该字符串的内容和准确度 */
content: {
/** 该字符串的内容 */
text: string;
/** 该字符串的准确度, 越1越准确 */
accuracy: number;
};
}
interface OcrResult {
/** Ocr结果,包括位置和内容 */
detail: ResultRow[];
/** Ocr识别出来的文字 */
text: string;
}
}
/**
* 通过直接调用python脚本和paddleOcr来实现OCR文字识别
* @requires 需要安装Anaconda和paddleOCR
* @link Anaconda https://www.anaconda.com/
* @link paddleocr https://pypi.org/project/paddleocr/
* @param imgPath img文件的绝对路径
* @param separator 输出text时的分隔符
* @returns 返回OCR文字识别结果
*/
export declare function paddleOcr(imgPath: string, separator?: string): Promise;