* Copyright (c) 2004-2005 Platon SDG, http://platon.sk/ * Licensed under terms of GNU General Public License. * All rights reserved. * * Changelog: * 2004-11-20 - created * 2005-04-02 - released as an open source * - imported to Platon SDG CVS repositery * */ /* $Platon$ */ if (count($_SERVER['argv']) <= 1) { printf("Usage:\n %s [-c] (-c = compare OCR output with filename)\n", $_SERVER['argv'][0]); exit; } require_once 'Image/OCR.php'; require_once '03-output-PHP-code/data.php'; $img = new Image_OCR; $check_ocr = false; $filename = $_SERVER['argv'][1]; if ($filename == '-c') { $check_ocr = true; $filename = $_SERVER['argv'][2]; } if ($img->load($filename) == false) { trigger_error('image file not found: '.$filename); exit; } $img->setBlackWhite(); $img->invert(); $img->trimAll(); $img->removeLinesIntelligent(); $img->trimAll(); $img->fillAllIntelligent(); $sub_img_ar = $img->splitHorizontalEmptyCols(11 /* min_size */); //printf("Components: %d (%s)\n", count($sub_img_ar), $filename); if (count($sub_img_ar) < 1) { trigger_error('no components in '.$filename); exit; } else if (count($sub_img_ar) < 4) { // split the largest component $max_id = -1; $max_width = -1; for ($i = 0; $i < count($sub_img_ar); $i++) { if ($sub_img_ar[$i]->getWidth() > $max_width) { $max_id = $i; $max_width = $sub_img_ar[$i]->getWidth(); } } $sub_img_ar = array_merge( array_slice($sub_img_ar, 0, $max_id), $sub_img_ar[$max_id]->splitHorizontal(2 /* two components */), array_slice($sub_img_ar, $max_id + 1) ); if (0) { echo "max_id = $max_id, max_width = $max_width\n"; printf("Components: %d (%s)\n", count($sub_img_ar), $filename); } } echo "Processing $filename: "; for ($debug = 0; $debug < ($check_ocr ? 2 : 1); $debug++) { $word = ''; if (count($OCR_DATA) > 0) { for ($i = 0; $i < count($sub_img_ar); $i++) { $sub_img_ar[$i]->trimAll(); $sub_img_ar[$i]->extendTo(40, 40); $letter = $sub_img_ar[$i]->doOCR($OCR_DATA, $debug); $word .= $letter; if (!$debug) { echo $letter; } else { echo "\n[$letter]\n"; $sub_img_ar[$i]->writeAscii(); } } } else { echo " no OCR data\n"; break; } if ($check_ocr) { if (! strncmp($word, basename($filename), strlen($word))) { echo " OK\n"; break; } else { echo " NON-MATCH\n"; } } else { echo "\n"; } } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */ ?>