Merge branch 'feature/add-base91-official' of https://github.com/ialejandrozalles/CyberChef into feature/add-base91-official
This commit is contained in:
commit
d734a8aa1a
@ -15,6 +15,7 @@ import { isWorkerEnvironment } from "../Utils.mjs";
|
|||||||
import { createWorker } from "tesseract.js";
|
import { createWorker } from "tesseract.js";
|
||||||
|
|
||||||
const OEM_MODES = ["Tesseract only", "LSTM only", "Tesseract/LSTM Combined"];
|
const OEM_MODES = ["Tesseract only", "LSTM only", "Tesseract/LSTM Combined"];
|
||||||
|
const OCR_DEFAULT_WHITELIST = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optical Character Recognition operation
|
* Optical Character Recognition operation
|
||||||
@ -34,6 +35,11 @@ class OpticalCharacterRecognition extends Operation {
|
|||||||
this.inputType = "ArrayBuffer";
|
this.inputType = "ArrayBuffer";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Character whitelist (optional)",
|
||||||
|
type: "string",
|
||||||
|
value: OCR_DEFAULT_WHITELIST
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Show confidence",
|
name: "Show confidence",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
@ -85,6 +91,10 @@ class OpticalCharacterRecognition extends Operation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
self.sendStatusMessage("Configuring OCR parameters...");
|
||||||
|
if (whitelist && whitelist.length) {
|
||||||
|
await worker.setParameters({ /* eslint-disable camelcase */ tessedit_char_whitelist: whitelist /* eslint-enable camelcase */ });
|
||||||
|
}
|
||||||
self.sendStatusMessage("Finding text...");
|
self.sendStatusMessage("Finding text...");
|
||||||
const result = await worker.recognize(image);
|
const result = await worker.recognize(image);
|
||||||
let text = result?.data?.text ?? "";
|
let text = result?.data?.text ?? "";
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { fromBase64, toBase64 } from "../lib/Base64.mjs";
|
|||||||
import { fromHex } from "../lib/Hex.mjs";
|
import { fromHex } from "../lib/Hex.mjs";
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import OperationError from "../errors/OperationError.mjs";
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import Utils from "../Utils.mjs";
|
import Utils, { isWorkerEnvironment } from "../Utils.mjs";
|
||||||
import {isImage} from "../lib/FileType.mjs";
|
import {isImage} from "../lib/FileType.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +104,12 @@ class RenderImage extends Operation {
|
|||||||
// Add image data to URI
|
// Add image data to URI
|
||||||
dataURI += "base64," + toBase64(data);
|
dataURI += "base64," + toBase64(data);
|
||||||
|
|
||||||
return "<img src='" + dataURI + "'>";
|
let html = "<img src='" + dataURI + "'>";
|
||||||
|
if (isWorkerEnvironment()) {
|
||||||
|
const ocrLink = "#recipe=Optical_Character_Recognition('Show confidence',true,'OCR Engine Mode','LSTM only')";
|
||||||
|
html = "<div style=\"position:relative; display:inline-block;\">" + html + "<a href=\"" + ocrLink + "\" title=\"Run OCR\" style=\"position:absolute; top:8px; right:8px; background:rgba(0,0,0,.6); color:#fff; padding:4px 6px; border-radius:4px; text-decoration:none; font-weight:bold;\">✎</a></div>";
|
||||||
|
}
|
||||||
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user