tesseract worker restart to aviod memory leak

This commit is contained in:
mrfry 2022-12-10 16:36:59 +01:00
parent 96b413a365
commit 0259cfe1a7
3 changed files with 85 additions and 25 deletions

View file

@ -287,14 +287,16 @@ function createQuestion(
async function recognizeQuestionImage(question: Question): Promise<Question> {
const base64Data = question.data.base64
if (Array.isArray(base64Data) && base64Data.length) {
try {
const res: string[] = []
for (let i = 0; i < base64Data.length; i++) {
const base64 = base64Data[i]
const text = await recognizeTextFromBase64(base64)
const res: string[] = []
for (let i = 0; i < base64Data.length; i++) {
const base64 = base64Data[i]
const text = await recognizeTextFromBase64(base64)
if (text && text.trim()) {
res.push(text)
}
}
if (res.length) {
return {
...question,
Q: res.join(' '),
@ -303,9 +305,6 @@ async function recognizeQuestionImage(question: Question): Promise<Question> {
type: 'simple',
},
}
} catch (e) {
console.error('Error happened in recognizeQuestionImage!')
console.error(e)
}
}
@ -972,5 +971,4 @@ export {
dataToString,
doSearch,
setNoPossibleAnswersPenalties,
recognizeQuestionImage,
}