finished item finder
This commit is contained in:
parent
1246884be9
commit
930e00c9cc
7 changed files with 450 additions and 37 deletions
|
|
@ -24,6 +24,25 @@ export interface OcrResponse {
|
|||
lines: OcrLine[];
|
||||
}
|
||||
|
||||
export interface GridItem {
|
||||
row: number;
|
||||
col: number;
|
||||
w: number;
|
||||
h: number;
|
||||
}
|
||||
|
||||
export interface GridMatch {
|
||||
row: number;
|
||||
col: number;
|
||||
similarity: number;
|
||||
}
|
||||
|
||||
export interface GridScanResult {
|
||||
cells: boolean[][];
|
||||
items: GridItem[];
|
||||
matches?: GridMatch[];
|
||||
}
|
||||
|
||||
export interface DetectGridResult {
|
||||
detected: boolean;
|
||||
region?: Region;
|
||||
|
|
@ -51,6 +70,8 @@ interface DaemonResponse {
|
|||
lines?: OcrLine[];
|
||||
image?: string;
|
||||
cells?: boolean[][];
|
||||
items?: GridItem[];
|
||||
matches?: GridMatch[];
|
||||
detected?: boolean;
|
||||
region?: Region;
|
||||
cols?: number;
|
||||
|
|
@ -106,11 +127,13 @@ export class OcrDaemon {
|
|||
return Buffer.from(resp.image!, 'base64');
|
||||
}
|
||||
|
||||
async gridScan(region: Region, cols: number, rows: number, threshold?: number): Promise<boolean[][]> {
|
||||
async gridScan(region: Region, cols: number, rows: number, threshold?: number, targetRow?: number, targetCol?: number): Promise<GridScanResult> {
|
||||
const req: DaemonRequest = { cmd: 'grid', region, cols, rows };
|
||||
if (threshold) req.threshold = threshold;
|
||||
if (targetRow != null && targetRow >= 0) (req as any).targetRow = targetRow;
|
||||
if (targetCol != null && targetCol >= 0) (req as any).targetCol = targetCol;
|
||||
const resp = await this.sendWithRetry(req, REQUEST_TIMEOUT);
|
||||
return resp.cells ?? [];
|
||||
return { cells: resp.cells ?? [], items: resp.items ?? [], matches: resp.matches ?? undefined };
|
||||
}
|
||||
|
||||
async detectGrid(region: Region, minCellSize?: number, maxCellSize?: number): Promise<DetectGridResult> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue