thiagoalessio / tesseract-ocr-for-php

A wrapper to work with Tesseract OCR inside PHP.
https://packagist.org/packages/thiagoalessio/tesseract_ocr
MIT License
2.87k stars 551 forks source link

Any idea why i have error? #193

Closed s811645 closed 3 years ago

s811645 commented 4 years ago

I do my script with using tesseract with PHP, script working fine for 1-2-3 requests simultaneously. But, if i send 10+ requests simultaneously its done first 2-3 request, but for next show error:

Error! Reading image data from stdin is not available this tesseract version
Required version is 3.03-rc1, actual version is fault

Generated command:
"tesseract" "" "/tmp/ocrEKUVOy"
Error! The command did not produce any output.

====
Returned message:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)
Error! The command did not produce any output.

Any idea why this can happen?

I check in Therminal version tesseract and this show 4.1.4 (photo)

My Code: `$this->Imagick->readImageBlob($result); $this->Imagick->resizeImage(450,120,Imagick::FILTER_CATROM,1); $this->Imagick->extentImage(450,120,Imagick::FILTER_CATROM,1);

// some other options imagick.. $data = $this->Imagick->getImageBlob(); $size = $this->Imagick->getImageLength(); // read image $this->tesseract->imageData($data, $size)->lang('eng'); $code = $this->tesseract->run(); $this->tesseract->clearCache();`

thiagoalessio commented 3 years ago

This is happening because you seem to be sharing $this->tesseract instance, which can lead to this kind of race condition, since temp filenames are stored as instance variables.

To avoid this, my suggestion is to spawn a new instance every time (replace $this->tesseract->.... by (new TesseractOCR())->...).