Skip to content

Commit

Permalink
Tranform lang codes before passing to engine (#34)
Browse files Browse the repository at this point in the history
In #33 we allowed the user to enter ISO 639-1 codes, but we didn't use
EngineBase::getLangCodes() when actually setting the language, meaning
the language codes don't get transformed properly for the engine.

Bug: T282760
Bug: T282073
  • Loading branch information
MusikAnimal authored Jun 8, 2021
1 parent a0a3a65 commit 7c0137c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Engine/GoogleCloudVisionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getText(string $imageUrl, ?array $langs = null): string

$imageContext = new ImageContext();
if (null !== $langs) {
$imageContext->setLanguageHints($langs);
$imageContext->setLanguageHints($this->getLangCodes($langs));
}

$response = $this->imageAnnotator->textDetection($imageUrl, ['imageContext' => $imageContext]);
Expand Down
3 changes: 2 additions & 1 deletion src/Engine/TesseractEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ public function getText(string $imageUrl, ?array $langs = null): string
} catch (ClientException $exception) {
throw new OcrException('image-retrieval-failed', [$exception->getMessage()]);
}

$this->ocr->imageData($imageContent, $imageResponse->getHeaders()['content-length'][0]);
if ($langs && count($langs) > 0) {
$this->ocr->lang(...$langs);
$this->ocr->lang(...$this->getLangCodes($langs));
}

// Env vars are passed through by the thiagoalessio/tesseract_ocr package to the tesseract command,
Expand Down

0 comments on commit 7c0137c

Please sign in to comment.