@aspiresys/visor 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -2
- package/dist/index.js +6 -4
- package/dist/ocr.js +3 -1
- package/dist/text.d.ts +1 -1
- package/dist/text.js +15 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -298,18 +298,20 @@ export declare class Visor {
|
|
|
298
298
|
* on the matched text region.
|
|
299
299
|
*
|
|
300
300
|
* @param text Text to search for.
|
|
301
|
+
* @param index Index of the text to click.
|
|
301
302
|
*
|
|
302
303
|
* @throws Error if text is not found.
|
|
303
304
|
*
|
|
304
305
|
* @example
|
|
305
306
|
* await visor.clickText("Login");
|
|
306
307
|
*/
|
|
307
|
-
clickText(text: string): Promise<void>;
|
|
308
|
+
clickText(text: string, index?: number): Promise<void>;
|
|
308
309
|
/**
|
|
309
310
|
* Finds text on screen or inside
|
|
310
311
|
* a specific region using OCR.
|
|
311
312
|
*
|
|
312
313
|
* @param text Text to search for.
|
|
314
|
+
* @param index Index of the text to search.
|
|
313
315
|
* @param region Optional search region.
|
|
314
316
|
*
|
|
315
317
|
* @returns Matched text region or null.
|
|
@@ -318,7 +320,7 @@ export declare class Visor {
|
|
|
318
320
|
* const region =
|
|
319
321
|
* await visor.findText("Submit");
|
|
320
322
|
*/
|
|
321
|
-
findText(text: string, region?: {
|
|
323
|
+
findText(text: string, index?: number, region?: {
|
|
322
324
|
x: number;
|
|
323
325
|
y: number;
|
|
324
326
|
width: number;
|
package/dist/index.js
CHANGED
|
@@ -415,14 +415,15 @@ CONF:${m.confidence.toFixed(3)}
|
|
|
415
415
|
* on the matched text region.
|
|
416
416
|
*
|
|
417
417
|
* @param text Text to search for.
|
|
418
|
+
* @param index Index of the text to click.
|
|
418
419
|
*
|
|
419
420
|
* @throws Error if text is not found.
|
|
420
421
|
*
|
|
421
422
|
* @example
|
|
422
423
|
* await visor.clickText("Login");
|
|
423
424
|
*/
|
|
424
|
-
async clickText(text) {
|
|
425
|
-
const region = await (0, text_1.findText)(text);
|
|
425
|
+
async clickText(text, index = 0) {
|
|
426
|
+
const region = await (0, text_1.findText)(text, index);
|
|
426
427
|
if (!region) {
|
|
427
428
|
throw new Error(`Text not found: ${text}`);
|
|
428
429
|
}
|
|
@@ -433,6 +434,7 @@ CONF:${m.confidence.toFixed(3)}
|
|
|
433
434
|
* a specific region using OCR.
|
|
434
435
|
*
|
|
435
436
|
* @param text Text to search for.
|
|
437
|
+
* @param index Index of the text to search.
|
|
436
438
|
* @param region Optional search region.
|
|
437
439
|
*
|
|
438
440
|
* @returns Matched text region or null.
|
|
@@ -441,8 +443,8 @@ CONF:${m.confidence.toFixed(3)}
|
|
|
441
443
|
* const region =
|
|
442
444
|
* await visor.findText("Submit");
|
|
443
445
|
*/
|
|
444
|
-
async findText(text, region) {
|
|
445
|
-
return await (0, text_1.findText)(text, region);
|
|
446
|
+
async findText(text, index = 0, region) {
|
|
447
|
+
return await (0, text_1.findText)(text, index, region);
|
|
446
448
|
}
|
|
447
449
|
/**
|
|
448
450
|
* Checks whether specific text exists
|
package/dist/ocr.js
CHANGED
|
@@ -71,7 +71,9 @@ async function extractTextFromRegion(region) {
|
|
|
71
71
|
blocks: true,
|
|
72
72
|
hocr: true,
|
|
73
73
|
tsv: true,
|
|
74
|
-
|
|
74
|
+
tessedit_pageseg_mode: "6",
|
|
75
|
+
tessedit_char_whitelist: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .:-/₹$€-,",
|
|
76
|
+
user_defined_dpi: "300"
|
|
75
77
|
});
|
|
76
78
|
(0, logger_1.log)("[OCR] Extracted Text:");
|
|
77
79
|
(0, logger_1.log)(result.data.text);
|
package/dist/text.d.ts
CHANGED
package/dist/text.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findText = findText;
|
|
4
4
|
exports.existsText = existsText;
|
|
5
5
|
const ocr_1 = require("./ocr");
|
|
6
|
-
async function findText(text, region) {
|
|
6
|
+
async function findText(text, index = 0, region) {
|
|
7
7
|
const result = await (0, ocr_1.extractTextFromRegion)(region);
|
|
8
8
|
const tsv = result.tsv;
|
|
9
9
|
if (!tsv) {
|
|
@@ -40,29 +40,35 @@ async function findText(text, region) {
|
|
|
40
40
|
confidence
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
+
const matches = [];
|
|
43
44
|
for (const key in lineGroups) {
|
|
44
45
|
const words = lineGroups[key];
|
|
45
46
|
words.sort((a, b) => a.x - b.x);
|
|
47
|
+
const searchWords = text.toLowerCase().split(/\s+/);
|
|
46
48
|
//const combinedText = words.map(w => w.text).join(" ");
|
|
47
49
|
const combinedText = words.map(w => w.text).join(" ").replace(/\s+/g, " ").trim();
|
|
48
50
|
if (combinedText.toLowerCase().replace(/[^a-z0-9 ]/gi, "").includes(text.toLowerCase().replace(/[^a-z0-9 ]/gi, ""))) {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
51
|
+
const matchedWords = words.filter(w => searchWords.includes(w.text.toLowerCase().replace(/[^a-z0-9]/gi, "")));
|
|
52
|
+
const regionWords = matchedWords.length > 0 ? matchedWords : words;
|
|
53
|
+
const minX = Math.min(...regionWords.map(w => w.x));
|
|
54
|
+
const minY = Math.min(...regionWords.map(w => w.y));
|
|
55
|
+
const maxX = Math.max(...regionWords.map(w => w.x + w.width));
|
|
56
|
+
const maxY = Math.max(...regionWords.map(w => w.y + w.height));
|
|
53
57
|
const avgConfidence = words.reduce((sum, w) => sum + w.confidence, 0) / words.length;
|
|
54
|
-
|
|
58
|
+
matches.push({
|
|
55
59
|
x: minX,
|
|
56
60
|
y: minY,
|
|
57
61
|
width: maxX - minX,
|
|
58
62
|
height: maxY - minY,
|
|
59
63
|
confidence: avgConfidence
|
|
60
|
-
};
|
|
64
|
+
});
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
|
-
|
|
67
|
+
matches.sort((a, b) => a.y - b.y ||
|
|
68
|
+
a.x - b.x);
|
|
69
|
+
return matches[index] || null;
|
|
64
70
|
}
|
|
65
71
|
async function existsText(text, region) {
|
|
66
|
-
const match = await findText(text, region);
|
|
72
|
+
const match = await findText(text, 0, region);
|
|
67
73
|
return match !== null;
|
|
68
74
|
}
|