Skip to content

Commit

Permalink
Adding an OCR test, that should be 0%
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregwar committed Dec 29, 2012
1 parent 47701eb commit 00ac9a5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
demo/out.jpg
demo/*.jpg
demo/*.pgm
2 changes: 1 addition & 1 deletion CaptchaBuilder.php
Expand Up @@ -203,7 +203,7 @@ public function build($width = 150, $height = 40, $font = null, $fingerprint = n

// Apply effects
$square = $width * $height;
$effects = $this->rand($square/5000, $square/2500);
$effects = $this->rand($square/3000, $square/1000);
for ($e = 0; $e < $effects; $e++) {
$function = $this->getScramblingFunction();
for ($i=0; $i<$square/5000; $i++) {
Expand Down
41 changes: 41 additions & 0 deletions demo/ocr.php
@@ -0,0 +1,41 @@
<?php

include('../CaptchaBuilder.php');
include('../PhraseBuilder.php');

use Gregwar\Captcha\CaptchaBuilder;

/**
* Generates 1000 captchas and try to read their code with the
* ocrad OCR
*/

$tests = 1000;
$passed = 0;

shell_exec('rm passed*.jpg');

for ($i=0; $i<$tests; $i++) {
echo "Captcha $i/$tests... ";

$captcha = new CaptchaBuilder;

$captcha
->build()
->save('out.jpg', 20)
;

shell_exec('convert out.jpg out.pgm');
$result = trim(shell_exec('ocrad out.pgm'));

if ($result == $captcha->getPhrase()) {
echo "passed at ocr\n";
shell_exec("cp out.jpg passed$passed.jpg");
$passed++;
} else {
echo "failed\n";
}
}

echo "\n";
echo "Over, $passed/$tests readed with OCR\n";
2 changes: 1 addition & 1 deletion demo/output.php
Expand Up @@ -8,6 +8,6 @@
header('Content-type: image/jpeg');

CaptchaBuilder::create()
->build(300, 70)
->build()
->output(20)
;

0 comments on commit 00ac9a5

Please sign in to comment.