check dependencies

This commit is contained in:
Dennis Eichhorn 2022-09-28 00:11:41 +02:00
parent 6e6aa16f84
commit eb3449f308
2 changed files with 22 additions and 2 deletions

View File

@ -102,14 +102,22 @@ final class TesseractOcr
. ' -l ' . \implode('+', $languages)
);
$parsed = \file_get_contents($temp . '.txt');
$filepath = \is_file($temp . '.txt')
? $temp . '.txt'
: $temp;
if (!\is_file($filepath)) {
return '';
}
$parsed = \file_get_contents($filepath);
if ($parsed === false) {
return '';
}
// @todo: auto flip image if x% of text are garbage words?
\unlink($temp);
\unlink($filepath);
return \trim($parsed);
}

View File

@ -24,6 +24,18 @@ use phpOMS\Image\Thresholding;
*/
final class TesseractOcrTest extends \PHPUnit\Framework\TestCase
{
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
if (!\is_file('/usr/bin/tesseract')) {
$this->markTestSkipped(
'Couldn\'t find tesseract'
);
}
}
private function outputTest(string $name, float $m1, float $m2) : void
{
if (false) {