I am using Tesseract in javascript for an OCR project. First, i will read the image using cv.imread(imgElement). then when I preprocess the image using Opencv and make it grey let's say, I have to pass the processed image in form of Mat variable to Tesseract, but it turns out that I can not pass the Mat variable to worker.recognize() method of Tesseract, the recognize() method only accepts the path of the image, not a Mat variable or anything else.
So, my question is how to pass Mat variable to worker.recognize() method in Tesseract? is there any other way that I can do to preprocess the image, and pass it to Tesseract?
let src = cv.imread(imgElement);
let dst = new cv.Mat();
let dstFilter = new cv.Mat();
let dsize = new cv.Size(1600, 1055);
cv.cvtColor(dst, dst, cv.COLOR_BGRA2BGR, 0);
cv.cvtColor(dst, dst, cv.COLOR_BGR2GRAY, 0);
cv.bilateralFilter(dst, dstFilter, 7, 27, 27, cv.BORDER_DEFAULT);
let dstThresh = new cv.Mat();
cv.threshold(
dstFilter,
dstThresh,
0,
255,
cv.THRESH_BINARY + cv.THRESH_OTSU
)[1];
const { createWorker } = Tesseract;
const worker = createWorker({
langPath: "..",
gzip: false,
logger: (m) => console.log(m),
});
(async () => {
await worker.load();
await worker.loadLanguage("ckbLayer");
await worker.initialize("ckbLayer");
const {
data: { text },
} = **await worker.recognize(dstThresh);**
document.getElementById("message").innerHTML = text;
await worker.terminate();
})();
so I have a problem in the last sentences, when i want to pass the processed the image to the worker.recognize() method.