work on new crop

This commit is contained in:
Boki 2026-02-12 22:07:54 -05:00
parent 9845e7f9bf
commit a7fab55d44
22 changed files with 975 additions and 10 deletions

View file

@ -104,6 +104,22 @@ export interface DiffOcrParams {
ocr?: OcrParams;
}
export type TooltipMethod = 'diff' | 'edge';
export interface EdgeCropParams {
cannyLow?: number;
cannyHigh?: number;
minLineLength?: number;
roiSize?: number;
densityThreshold?: number;
ocrPad?: number;
}
export interface EdgeOcrParams {
crop?: EdgeCropParams;
ocr?: OcrParams;
}
interface DaemonRequest {
cmd: string;
region?: Region;
@ -116,6 +132,9 @@ interface DaemonRequest {
engine?: string;
preprocess?: string;
params?: DiffOcrParams;
edgeParams?: EdgeOcrParams;
cursorX?: number;
cursorY?: number;
}
interface DaemonResponse {
@ -236,6 +255,24 @@ export class OcrDaemon {
};
}
async edgeOcr(savePath?: string, region?: Region, engine?: OcrEngine, preprocess?: OcrPreprocess, edgeParams?: EdgeOcrParams, cursorX?: number, cursorY?: number): Promise<DiffOcrResponse> {
const req: DaemonRequest = { cmd: 'edge-ocr' };
if (savePath) req.path = savePath;
if (region) req.region = region;
if (engine && engine !== 'tesseract') req.engine = engine;
if (preprocess) req.preprocess = preprocess;
if (edgeParams && Object.keys(edgeParams).length > 0) req.edgeParams = edgeParams;
if (cursorX != null) req.cursorX = cursorX;
if (cursorY != null) req.cursorY = cursorY;
const timeout = (engine && engine !== 'tesseract') ? 120_000 : CAPTURE_TIMEOUT;
const resp = await this.sendWithRetry(req, timeout);
return {
text: resp.text ?? '',
lines: resp.lines ?? [],
region: resp.region,
};
}
async saveScreenshot(path: string, region?: Region): Promise<void> {
const req: DaemonRequest = { cmd: 'screenshot', path };
if (region) req.region = region;