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 testBlueBackground() { Recognizer::setInfelicity(1); $text = Recognizer::read(__DIR__ . '/../template/test_img/blue_img1.png', Recognizer::loadTemplate('blue_background')); $this->assertEquals('+7(91 8) 432-57-00', $text); }
$allChar = []; foreach ($chars as $lines) { foreach ($lines as $words) { foreach ($words as $charValue) { $allChar[] = $charValue; } } } $chars = Recognizer::findUniqueChar($allChar); ?> <form method="POST" action=""> <?php foreach ($chars as $key => $fileName) { $name = './tmp/' . rand() . microtime(true) . '.png'; imagepng($fileName, $name); $tmp = Recognizer::generateTemplateChar($fileName); ?> <img src="<?php echo $name; ?> "/><label> <input type='text' name="template_<?php echo $key; ?> " value=''/> </label><br/> <input type="hidden" name="pattern_<?php echo $key; ?> " value="<?php echo $tmp;
<?php require_once __DIR__ . '/vendor/autoload.php'; use bpteam\phpOCR\Recognizer; use bpteam\phpOCR\Img; $file_name = __DIR__ . '/template/test_img/olx1.png'; $ex = 'png'; Recognizer::setInfelicity(10); $img = Recognizer::openImg($file_name); //Source image echo "<br>Step 0 src img<br>"; Img::show($img, $ex, 100); //load template $name = 'olx'; Recognizer::setTemplateDir(__DIR__ . '/template/'); $template = Recognizer::loadTemplate($name); // OCR echo "<br>defineImg<br>"; $text = Recognizer::read($file_name, $template); echo $text . "<br>";