mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
tesseract worker restart to aviod memory leak
This commit is contained in:
parent
96b413a365
commit
0259cfe1a7
3 changed files with 85 additions and 25 deletions
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue