* Copyright (c) 2004-2005 Platon SDG, http://platon.sk/ * Licensed under terms of GNU General Public License. * All rights reserved. * * Changelog: * 2004-11-21 - created * 2005-04-02 - released as an open source * - imported to Platon SDG CVS repositery * */ /* $Platon$ */ if (count($_SERVER['argv']) <= 2) { printf("Usage:\n %s \n", $_SERVER['argv'][0]); exit; } $input_dir = $_SERVER['argv'][1]; $filename = $_SERVER['argv'][2]; if (! is_dir($input_dir)) { trigger_error('not a directory: '.$input_dir); exit; } if (($f = @fopen($filename, 'w')) == false) { trigger_error('cannot open filename: '.$filename); } require_once 'Image/OCR.php'; // Fetching directories and files data $dir_obj = dir($input_dir); $all_ar = null; while (1) { $entry = $dir_obj->read(); if ($entry === FALSE) { break; } if ($entry == '.' || $entry == '..') { continue; } if (@is_dir($entry)) { } else { echo "Reading $entry ... "; $img = new Image_OCR; if ($img->readAsciiFromFile("$input_dir/$entry")) { echo "OK\n"; } else { echo "ERROR\n"; } $all_ar[$entry[0]][] = $img; } } $dir_obj->close(); fwrite($f, '<'.'?php'."\n\n"); fwrite($f, "// This is generated file! Do not edit!\n"); ksort($all_ar); foreach ($all_ar as $letter => $img_ar) { echo "Processing letter $letter: "; fwrite($f, "\n/*******************\n"); fwrite($f, "Processing letter $letter:\n"); if (count($img_ar) <= 0) { fwrite($f, 'NO samples'."\n*/"); continue; } fwrite($f, count($img_ar).' samples'."\n"); $min_width = $img_ar[0]->getWidth(); $min_height = $img_ar[0]->getHeight(); $max_width = $img_ar[0]->getWidth(); $max_height = $img_ar[0]->getHeight(); foreach ($img_ar as $img) { $min_width = min($img->getWidth(), $min_width); $min_height = min($img->getHeight(), $min_height); $max_width = max($img->getWidth(), $max_width); $max_height = max($img->getHeight(), $max_height); } fwrite($f, 'Min size: '.$min_width.'x'.$min_height."\n"); fwrite($f, 'Max size: '.$max_width.'x'.$max_height."\n"); fwrite($f, 'Width: '.$min_width.'..'.$max_width.', diff: '.($max_width-$min_width)."\n"); fwrite($f, 'Height: '.$min_height.'..'.$max_height.', diff: '.($max_height-$min_height)."\n"); for ($samples = 1, $i = 0; $i < count($img_ar); $i++) { //$img_ar[$i]->extendTo($max_width, $max_height); $img_ar[$i]->extendTo(40, 40); // fixed sufficient size if ($i > 0) { $img_ar[0]->mergeWith($img_ar[$i]); $samples++; } } fwrite($f, sprintf("Used %d of %d samples.\n\n", $samples, count($img_ar))); $img_ar[0]->writeAscii($f); fwrite($f, "\n*******************/\n"); fwrite($f, '$'."OCR_DATA['$letter'] = "); $img_ar[0]->normalize(9); $img_ar[0]->writePHPcode($f); echo count($img_ar)." samples\n"; } fwrite($f, "\n".'?'.'>'); fclose($f); echo "File $filename written with ",count($all_ar)," letters.\n"; /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */ ?>