public function testGenerateTemplateChar() { $img = Recognizer::openImg(__DIR__ . '/../template/test_img/olx1.png'); $width = imagesx($img); $height = imagesy($img); $template = Recognizer::generateTemplateChar($img, $width, $height); $this->assertEquals(preg_match_all('%[01]%', $template), $width * $height); }
public function testDivideByChar() { $img = Recognizer::openImg(__DIR__ . '/../template/test_img/olx1.png'); $lines = self::getMethod('byChar', 'bpteam\\phpOCR\\Divider')->invoke(null, $img); $this->assertCount(2, $lines); foreach ($lines as $line) { foreach ($line as $words) { foreach ($words as $char) { $this->assertEquals('gd', get_resource_type($char)); } } } }
use bpteam\phpOCR\Img; use bpteam\phpOCR\Recognizer; ini_set('display_errors', 1); error_reporting(E_ALL); set_time_limit(600); if (!isset($_POST['Submit1'])) { $templateName = 'blue_img'; $picFiles = []; $maxTemplate = 1; for ($i = 1; file_exists(__DIR__ . '/../template/test_img/' . $templateName . $i . '.png') && $i <= $maxTemplate; $i++) { $picFiles[] = __DIR__ . '/../template/test_img/' . $templateName . $i . '.png'; } $chars = []; Recognizer::setInfelicity(1); foreach ($picFiles as $key => $fileName) { $img = Recognizer::openImg($fileName); Img::show($img); $imgs = Divider::byChar($img); if (is_array($imgs)) { $chars = array_merge($chars, $imgs); } } $allChar = []; foreach ($chars as $lines) { foreach ($lines as $words) { foreach ($words as $charValue) { $allChar[] = $charValue; } } } $chars = Recognizer::findUniqueChar($allChar);