ocr.php (850B)
1 <?php 2 3 include(__DIR__.'/../CaptchaBuilderInterface.php'); 4 include(__DIR__.'/../PhraseBuilderInterface.php'); 5 include(__DIR__.'/../CaptchaBuilder.php'); 6 include(__DIR__.'/../PhraseBuilder.php'); 7 8 use Gregwar\Captcha\CaptchaBuilder; 9 10 /** 11 * Generates 1000 captchas and try to read their code with the 12 * ocrad OCR 13 */ 14 15 $tests = 10000; 16 $passed = 0; 17 18 shell_exec('rm passed*.jpg'); 19 20 for ($i=0; $i<$tests; $i++) { 21 echo "Captcha $i/$tests... "; 22 23 $captcha = new CaptchaBuilder; 24 25 $captcha 26 ->setDistortion(false) 27 ->build() 28 ; 29 30 if ($captcha->isOCRReadable()) { 31 $passed++; 32 $captcha->save("passed$passed.jpg"); 33 echo "passed at ocr... "; 34 } else { 35 echo "failed... "; 36 } 37 38 echo "pass rate: ".round(100*$passed/($i+1),2)."%\n"; 39 } 40 41 echo "\n"; 42 echo "Over, $passed/$tests readed with OCR\n";