diff --git a/src/components/LogOutput.vue b/src/components/LogOutput.vue index f666c8e..5e73878 100644 --- a/src/components/LogOutput.vue +++ b/src/components/LogOutput.vue @@ -1,25 +1,94 @@ diff --git a/src/components/capture-area/AfterConstraint.vue b/src/components/capture-area/AfterConstraint.vue new file mode 100644 index 0000000..7e827f3 --- /dev/null +++ b/src/components/capture-area/AfterConstraint.vue @@ -0,0 +1,215 @@ + + + + + diff --git a/src/components/capture-area/BeforeConstraint.vue b/src/components/capture-area/BeforeConstraint.vue new file mode 100644 index 0000000..1886e0b --- /dev/null +++ b/src/components/capture-area/BeforeConstraint.vue @@ -0,0 +1,215 @@ + + + + + diff --git a/src/components/capture-area/CaptureAreaSearchValue.vue b/src/components/capture-area/CaptureAreaSearchValue.vue index cd79a73..fe58b03 100644 --- a/src/components/capture-area/CaptureAreaSearchValue.vue +++ b/src/components/capture-area/CaptureAreaSearchValue.vue @@ -1,36 +1,15 @@ diff --git a/src/components/capture-area/ValueRegex.vue b/src/components/capture-area/ValueRegex.vue new file mode 100644 index 0000000..3b89cae --- /dev/null +++ b/src/components/capture-area/ValueRegex.vue @@ -0,0 +1,215 @@ + + + + + diff --git a/src/proc/TesseractHandler.ts b/src/proc/TesseractHandler.ts index 37fbdc6..1c0faec 100644 --- a/src/proc/TesseractHandler.ts +++ b/src/proc/TesseractHandler.ts @@ -52,12 +52,12 @@ export class TesseractHandler { * @return void */ public async addWorker(): Promise { - const worker = createWorker({cachePath: "."}); + const worker = createWorker({ cachePath: '.' }); await worker.load(); await worker.loadLanguage('eng'); await worker.initialize('eng'); this.worker.push(worker); - console.log("added tesseract worker"); + console.log('added tesseract worker'); } /** @@ -73,7 +73,12 @@ export class TesseractHandler { * @param stream: MediaStream * @return Promise */ - public async run(stream:MediaStream, callback:Function, previewWidth: number, previewHeight: number): Promise { + public async run( + stream: MediaStream, + callback: Function, + previewWidth: number, + previewHeight: number + ): Promise { if (!this.running) { this.running = true; await new Promise(async () => { @@ -92,28 +97,49 @@ export class TesseractHandler { const canvas = document.createElement('canvas'); canvas.height = video.videoHeight; canvas.width = video.videoWidth; - canvas.getContext('2d')!.drawImage(video, 0, 0, video.videoWidth, video.videoHeight); + canvas + .getContext('2d')! + .drawImage( + video, + 0, + 0, + video.videoWidth, + video.videoHeight + ); const img = canvas.toDataURL('image/png'); video.pause(); // create rectangles from capture areas const rectangles = this.enabledCaptureAreas.map((ca) => { - let streamScales = ca.getStreamScales(stream, previewWidth, previewHeight); + let streamScales = ca.getStreamScales( + stream, + previewWidth, + previewHeight + ); return { id: ca.getId(), left: streamScales.left, top: streamScales.top, width: streamScales.width, - height: streamScales.height + height: streamScales.height, }; }); // run tesseract (async () => { - const results: {ca_id: number, data: string}[] = []; - await Promise.all(rectangles.map((rectangle) => ( - scheduler.addJob('recognize', img, {rectangle}).then((x) => results.push({ca_id: rectangle.id, data: x.data.text})) - ))); + const results: { ca_id: number; data: string }[] = []; + await Promise.all( + rectangles.map((rectangle) => + scheduler + .addJob('recognize', img, { rectangle }) + .then((x) => + results.push({ + ca_id: rectangle.id, + data: x.data.text, + }) + ) + ) + ); callback(results); this.running = false; })(); @@ -121,4 +147,4 @@ export class TesseractHandler { }); } } -} \ No newline at end of file +} diff --git a/src/proc/regex/Regex.ts b/src/proc/regex/Regex.ts index 1a7353c..1648afe 100644 --- a/src/proc/regex/Regex.ts +++ b/src/proc/regex/Regex.ts @@ -1,5 +1,5 @@ -import RandExp from "randexp"; -import { RegexHandler } from "./RegexHandler"; +import RandExp from 'randexp'; +import { RegexHandler } from './RegexHandler'; export abstract class Regex { protected id: number; @@ -8,18 +8,21 @@ export abstract class Regex { protected slicing: Slicing; protected similarity: Similarity; protected matchesNum: number; - protected substrings: {index: number, element: string}[]; - protected lastBestMatch: {rating: number, match: {index: number, element: string}}; + protected substrings: { index: number; element: string }[]; + protected lastBestMatch: { + rating: number; + match: { index: number; element: string }; + }; - protected constructor () { + protected constructor() { this.id = 0; - this.regex = new RegExp(""); + this.regex = new RegExp(''); this.matching = Matching.EXACT; this.slicing = Slicing.SUBSTR; this.similarity = Similarity.NONE; this.matchesNum = 10000; this.substrings = []; - this.lastBestMatch = {rating: -1, match: {index: -1, element: ""}} + this.lastBestMatch = { rating: -1, match: { index: -1, element: '' } }; } public getId(): number { @@ -66,15 +69,18 @@ export abstract class Regex { this.matchesNum = matchesNum; } - public getSubstrings(): {index: number, element: string}[] { + public getSubstrings(): { index: number; element: string }[] { return this.substrings; } - public setSubstrings(substrings: {index: number, element: string}[]) { + public setSubstrings(substrings: { index: number; element: string }[]) { this.substrings = substrings; } - public getLastBestMatch(): {rating: number, match: {index: number, element: string}} { + public getLastBestMatch(): { + rating: number; + match: { index: number; element: string }; + } { return this.lastBestMatch; } @@ -83,18 +89,21 @@ export abstract class Regex { * @param data * @return void */ - public genSubstrings(data:string) { + public genSubstrings(data: string) { switch (this.slicing) { case Slicing.SUBSTR: this.substrings = this.getAllSubstrings(data!); break; case Slicing.SPACES: - data.split(" ").forEach(element => { - this.substrings.push({index: this.indexOfFirst(data), element: element}); + data.split(' ').forEach((element) => { + this.substrings.push({ + index: this.indexOfFirst(data), + element: element, + }); }); break; case Slicing.ENTIRE_STR: - this.substrings.push({index: 0, element: data}); + this.substrings.push({ index: 0, element: data }); break; } } @@ -103,12 +112,18 @@ export abstract class Regex { switch (this.similarity) { case Similarity.NUM_LET: this.substrings.forEach((element, index) => { - this.substrings[index] = {index: element.index, element: this.repSimNumLet(element.element)}; + this.substrings[index] = { + index: element.index, + element: this.repSimNumLet(element.element), + }; }); break; case Similarity.LET_NUM: this.substrings.forEach((element, index) => { - this.substrings[index] = {index: element.index, element: this.repSimLetNum(element.element)}; + this.substrings[index] = { + index: element.index, + element: this.repSimLetNum(element.element), + }; }); break; } @@ -119,7 +134,7 @@ export abstract class Regex { * @param max: number * @return string[] */ - public genMatches(max:number = this.matchesNum) { + public genMatches(max: number = this.matchesNum) { let regLev0: string[] = []; let randexp = new RandExp(this.regex); for (let i = 0; i < max; i++) { @@ -130,7 +145,6 @@ export abstract class Regex { // i--; May be a good performance optimization, doesn't work however if max is greater than the number of possible matches } } - console.log("generated matches for regex: " + this.id); return regLev0; } @@ -139,12 +153,14 @@ export abstract class Regex { * @param str: string * @return {index: number, element: string}[] */ - private getAllSubstrings(str:string): {index: number, element: string}[] { + private getAllSubstrings( + str: string + ): { index: number; element: string }[] { var i, j, result = []; for (i = 0; i < str.length; i++) { for (j = i + 1; j < str.length + 1; j++) { - result.push({index: i, element: str.slice(i, j)}); + result.push({ index: i, element: str.slice(i, j) }); } } return result; @@ -155,19 +171,34 @@ export abstract class Regex { * @param data: string * @return {rating: number, match: {index: number, element: string}} */ - public getBestMatch(data: string): {rating: number, match: {index: number, element: string}} { - let bestMatch = {rating: -1, match: {index: -1, element: ""}}; + public getBestMatch(data: string): { + rating: number; + match: { index: number; element: string }; + } { + let bestMatch = { rating: -1, match: { index: -1, element: '' } }; switch (this.matching) { case Matching.EXACT: - this.substrings.every(element => { + this.substrings.every((element) => { let exactMatch = element.element.match(this.regex); - if (exactMatch !== null && bestMatch.match.element.length < exactMatch[0].length) { - bestMatch = {rating: 1, match: {index: this.indexOfFirst(data), element: exactMatch[0]}}; + if ( + exactMatch !== null && + bestMatch.match.element.length < exactMatch[0].length + ) { + bestMatch = { + rating: 1, + match: { + index: this.indexOfFirst(data), + element: exactMatch[0], + }, + }; } }); break; case Matching.APPROX: - bestMatch = RegexHandler.approxMatching(this.substrings, this.genMatches()); + bestMatch = RegexHandler.approxMatching( + this.substrings, + this.genMatches() + ); break; } this.lastBestMatch = bestMatch; @@ -179,7 +210,7 @@ export abstract class Regex { * @param str: string * @return string */ - private repSimNumLet(str:string):string { + private repSimNumLet(str: string): string { for (let i = 0; i < str.length; i++) { switch (str.charAt(i)) { case '0': @@ -218,7 +249,7 @@ export abstract class Regex { * @param str: string * @return string */ - private repSimLetNum(str:string):string { + private repSimLetNum(str: string): string { for (let i = 0; i < str.length; i++) { switch (str.charAt(i)) { case 'o': @@ -292,7 +323,7 @@ export abstract class Regex { * @param replacement: string * @return string */ - private replaceCharAt(str:string, index:number, replacement:string) { + private replaceCharAt(str: string, index: number, replacement: string) { return str.substring(0, index) + replacement + str.substring(index + 1); } @@ -303,7 +334,7 @@ export abstract class Regex { * @param before: boolean * @return number */ - private indexOfFirst(data:string, before:boolean = false):number { + private indexOfFirst(data: string, before: boolean = false): number { let match = data.match(this.regex); if (!match) { return -1; @@ -317,18 +348,18 @@ export abstract class Regex { } export enum Matching { - EXACT = "Exact", - APPROX = "Approximate" + EXACT = 'Exact', + APPROX = 'Approximate', } export enum Slicing { - SUBSTR = "Substring", - SPACES = "Spaces", - ENTIRE_STR = "Entire String" + SUBSTR = 'Substring', + SPACES = 'Spaces', + ENTIRE_STR = 'Entire String', } export enum Similarity { - NONE = "None", - NUM_LET = "Numbers To Letters", - LET_NUM = "Letters To Numbers" -} \ No newline at end of file + NONE = 'None', + NUM_LET = 'Numbers To Letters', + LET_NUM = 'Letters To Numbers', +} diff --git a/src/views/RegexView.vue b/src/views/RegexView.vue index 3b67254..fb88ce3 100644 --- a/src/views/RegexView.vue +++ b/src/views/RegexView.vue @@ -24,7 +24,9 @@ {{ captureArea.getId() }} - + diff --git a/src/views/RunPage.vue b/src/views/RunPage.vue index abe9f67..13109e1 100644 --- a/src/views/RunPage.vue +++ b/src/views/RunPage.vue @@ -20,17 +20,30 @@