@aspiresys/visor 1.1.2 → 1.1.4
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/config.d.ts +1 -0
- package/dist/config.js +2 -1
- package/dist/index.d.ts +26 -2
- package/dist/index.js +35 -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/config.d.ts
CHANGED
package/dist/config.js
CHANGED
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;
|
|
@@ -669,6 +671,27 @@ export declare class Visor {
|
|
|
669
671
|
*/
|
|
670
672
|
getImagePath(): string;
|
|
671
673
|
/**
|
|
674
|
+
* Sets the default output path
|
|
675
|
+
* used for visual automation APIs.
|
|
676
|
+
*
|
|
677
|
+
* @param path Output directory path.
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* visor.setOutputPath("./images");
|
|
681
|
+
*/
|
|
682
|
+
setOutputPath(path: string): void;
|
|
683
|
+
/**
|
|
684
|
+
* Returns the current default
|
|
685
|
+
* Output path.
|
|
686
|
+
*
|
|
687
|
+
* @returns Output path.
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* const path =
|
|
691
|
+
* visor.getOutputPath();
|
|
692
|
+
*/
|
|
693
|
+
getOutputPath(): string;
|
|
694
|
+
/**
|
|
672
695
|
* Closes a desktop application
|
|
673
696
|
* using Windows taskkill.
|
|
674
697
|
*
|
|
@@ -705,6 +728,7 @@ export declare class Visor {
|
|
|
705
728
|
loadConfig(config: {
|
|
706
729
|
scaleFactor?: number;
|
|
707
730
|
imagePath?: string;
|
|
731
|
+
ssOutputPath?: string;
|
|
708
732
|
debug?: boolean;
|
|
709
733
|
}): void;
|
|
710
734
|
/**
|
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
|
|
@@ -530,6 +532,7 @@ CONF:${m.confidence.toFixed(3)}
|
|
|
530
532
|
* );
|
|
531
533
|
*/
|
|
532
534
|
async captureScreenshot(path) {
|
|
535
|
+
path = config_1.visorConfig.outputPath + "/" + path;
|
|
533
536
|
console.log(`[VISOR] Saving screenshot: ${path}`);
|
|
534
537
|
await (0, screen_1.saveScreenshot)(path);
|
|
535
538
|
console.log("[VISOR] Screenshot saved");
|
|
@@ -835,6 +838,31 @@ CONF:${m.confidence.toFixed(3)}
|
|
|
835
838
|
return config_1.visorConfig.imagePath;
|
|
836
839
|
}
|
|
837
840
|
/**
|
|
841
|
+
* Sets the default output path
|
|
842
|
+
* used for visual automation APIs.
|
|
843
|
+
*
|
|
844
|
+
* @param path Output directory path.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* visor.setOutputPath("./images");
|
|
848
|
+
*/
|
|
849
|
+
setOutputPath(path) {
|
|
850
|
+
config_1.visorConfig.outputPath = path;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Returns the current default
|
|
854
|
+
* Output path.
|
|
855
|
+
*
|
|
856
|
+
* @returns Output path.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* const path =
|
|
860
|
+
* visor.getOutputPath();
|
|
861
|
+
*/
|
|
862
|
+
getOutputPath() {
|
|
863
|
+
return config_1.visorConfig.outputPath;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
838
866
|
* Closes a desktop application
|
|
839
867
|
* using Windows taskkill.
|
|
840
868
|
*
|
|
@@ -877,6 +905,9 @@ CONF:${m.confidence.toFixed(3)}
|
|
|
877
905
|
if (config.imagePath) {
|
|
878
906
|
this.setImagePath(config.imagePath);
|
|
879
907
|
}
|
|
908
|
+
if (config.ssOutputPath) {
|
|
909
|
+
this.setOutputPath(config.ssOutputPath);
|
|
910
|
+
}
|
|
880
911
|
if (config.debug !== undefined) {
|
|
881
912
|
this.setDebug(config.debug);
|
|
882
913
|
}
|
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
|
}
|