PHP Classes

Fatal error: Class 'OCR' not found in C:\wamp\www\phpocr-2006-02

Recommend this page to a friend!

      PHP OCR Class  >  All threads  >  Fatal error: Class 'OCR' not found...  >  (Un) Subscribe thread alerts  
Subject:Fatal error: Class 'OCR' not found...
Summary:error
Messages:8
Author:deepa jithesh
Date:2007-02-26 06:02:08
Update:2014-03-21 05:57:10
 

  1. Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of deepa  jithesh deepa jithesh - 2007-02-26 06:02:08
PLEASE give a solution for the below quoted error.When i m running the example.php class it displays the following error.

clear(); $this->name = $str; $this->createImage(); $this->charObject->setName($str); $this->charObject->setWidth($this->width); $this->charObject->setHeight($this->height); $this->makeCharObject(); } /** * Learn systems to understand symbols form image * * @param string $path * @param string $name */ function LearnFromImage($path, $name){ $this->clear(); $this->name = $name; $im = $this->createImageFromFile($path); $this->image = imagecreatetruecolor($this->width, $this->height); imagecopy($this->image, $im, 0, 0, 0, 0, $this->width, $this->height); $this->charObject->setName($name); $this->charObject->setWidth($this->width); $this->charObject->setHeight($this->height); $this->makeCharObject(); } /** * Create char object from image object * */ function makeCharObject(){ for ($x=0; $x<$this->width; $x++){ for ($y=0; $y<$this->height; $y++){ $type = $this->getCornerType($this->image,$x,$y); if ($type!==false){ $this->charObject->setCorner($x, $y, $type); } } } } /** * Recognition method * * @param string $path * @return object */ function Recognition($path){ $this->clear(); $im = $this->createImageFromFile($path); $this->image = imagecreatetruecolor($this->width, $this->height); imagecopy($this->image, $im, 0, 0, 0, 0, $this->width, $this->height); $this->charObject->setWidth($this->width); $this->charObject->setHeight($this->height); $this->makeCharObject(); $d = dir("./storage/"); while (false !== ($entry = $d->read())) { if ((eregi(".char$",$entry))){ if ($this->checkCharObject(implode('',file("./storage/".$entry)))){ return unserialize(implode('',file("./storage/".$entry))); } } } $d->close(); return false; } /** * Get inverce corner * * @param int $type * @return int */ static function getNegative($type){ if ($type>4){ return $type - 4; }else{ return $type + 4; } } /** * Clean up OCR object * */ function clear(){ unset($this->image); unset($this->charObject); unset($this->name); $this->charObject = new char(); } /** * Comare charObjects to congruous * * @param string $str * @param boolean $print * @return boolean */ function checkCharObject($str, $print = true){ $m = 1; $char = unserialize($str); if ($print){ echo "Check \"".$char->getName()."\"
"; } $currentImagesInfo = $char->getImageInfo(); $imageInfo = $this->charObject->getImageInfo(); if (count($imageInfo)){ $m = 0; foreach ($imageInfo as $key => $value){ if ((isset($currentImagesInfo[$key]['type'])) && (($currentImagesInfo[$key]['type']!=$value['type'])&&($currentImagesInfo[$key]['type']!=OCR::getNegative($value['type'])))){ $m++; } } } if ($print){ echo "We have ".$m." errors
"; } if ($m==0){ if ($print){ echo "It is \"".$char->getName()."\"
"; } return true; }else{ if ($print){ echo "It is not \"".$char->getName()."\"
"; } return false; } } /** * Save chars object to file in storage * */ function saveResult(){ $time = time(); $this->charObject->setTime($time); $fl = fopen("./storage/".$this->name.md5($this->name).".char","w"); fwrite($fl,serialize($this->charObject)); fclose($fl); } /** * Make image for learning * */ function createImage(){ $im = imagecreatetruecolor(100, 100); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); imagechar($im, 2, 1, 1, $this->name, $white); $this->getSize($im); $this->image = imagecreatetruecolor($this->width, $this->height); imagecopy($this->image, $im, 0, 0, 0, 0, $this->width, $this->height); } /** * get image size * * @param image $im */ function getSize($im){ $w = 0; $h = 0; for ($x=0; $x<100; $x++){ for ($y=0; $y<100; $y++){ if (($this->getBWcolor($im, $x, $y)==COLOR_WHITE)&&($w<=$x)){ $w = $x; } if (($this->getBWcolor($im, $x, $y)==COLOR_WHITE)&&($h<=$y)){ $h = $y; } } } if (($w>0)&&($h>0)){ $w+=2; $h+=2; $this->width = $w; $this->height = $h; } } /** * Get type of corners * * @param image $im * @param int $x * @param int $y * @return int */ function getCornerType($im, $x, $y){ $p11 = $this->getBWcolor($im, $x, $y); $p21 = $this->getBWcolor($im, $x+1, $y); $p12 = $this->getBWcolor($im, $x, $y+1); $p22 = $this->getBWcolor($im, $x+1, $y+1); $sum = $p11 + $p12 + $p21 + $p22; if ($sum % 2 == 0){ return false; } if (($p11==COLOR_BLACK)&&($p21==COLOR_WHITE)&&($p12==COLOR_WHITE)&&($p22==COLOR_WHITE)){ return CORNER_BP_LEFT_TOP; } if (($p11==COLOR_WHITE)&&($p21==COLOR_BLACK)&&($p12==COLOR_WHITE)&&($p22==COLOR_WHITE)){ return CORNER_BP_RIGHT_TOP; } if (($p11==COLOR_WHITE)&&($p21==COLOR_WHITE)&&($p12==COLOR_BLACK)&&($p22==COLOR_WHITE)){ return CORNER_BP_LEFT_BOTTOM; } if (($p11==COLOR_WHITE)&&($p21==COLOR_WHITE)&&($p12==COLOR_WHITE)&&($p22==COLOR_BLACK)){ return CORNER_BP_RIGHT_BOTTOM; } if (($p11==COLOR_WHITE)&&($p21==COLOR_BLACK)&&($p12==COLOR_BLACK)&&($p22==COLOR_BLACK)){ return CORNER_WP_LEFT_TOP; } if (($p11==COLOR_BLACK)&&($p21==COLOR_WHITE)&&($p12==COLOR_BLACK)&&($p22==COLOR_BLACK)){ return CORNER_WP_RIGHT_TOP; } if (($p11==COLOR_BLACK)&&($p21==COLOR_BLACK)&&($p12==COLOR_WHITE)&&($p22==COLOR_BLACK)){ return CORNER_WP_LEFT_BOTTOM; } if (($p11==COLOR_BLACK)&&($p21==COLOR_BLACK)&&($p12==COLOR_BLACK)&&($p22==COLOR_WHITE)){ return CORNER_WP_RIGHT_BOTTOM; } } /** * Get pixels color, understund only black or white pixels * * @param image $im * @param int $x * @param int $y * @return int */ function getBWcolor($im, $x, $y){ $rgb = @ImageColorAt($im,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; if (($r==255)&&($g==255)&&($b==255)){ return COLOR_WHITE; } return COLOR_BLACK; } /** * Output image * */ function outputImage(){ header('Content-type: image/png'); imagepng($this->image); } /** * create image for recognition * * @param string $img_file * @return image */ function createImageFromFile($img_file){ $img=0; $img_sz = getimagesize( $img_file ); switch( $img_sz[2] ){ case 1: $img = ImageCreateFromGif($img_file); break; case 2: $img = ImageCreateFromJpeg($img_file); break; case 3: $img = ImageCreateFromPng($img_file); break; } $this->width = $img_sz[0]; $this->height = $img_sz[1]; return $img; } } ?>
Fatal error: Class 'OCR' not found in C:\wamp\www\phpocr-2006-02-10\example.php on line 14



  2. Re: Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of Tarek Alexander Amiri Tarek Alexander Amiri - 2008-05-15 10:01:11 - In reply to message 1 from deepa jithesh
Just go to the OCR.class.php file and change the first <? to <?php

If you have a PHP5 server like Wampserver, it ignores the <? because it is not PHP 5 conform

  3. Re: Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of mMiniImManN mMiniImManN - 2009-08-16 06:00:33 - In reply to message 2 from Tarek Alexander Amiri
yea, that trick still fails dude, undefined function
imagecreatetruecolor
on line 193

  4. Re: Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of vamshi vamshi - 2011-12-09 12:52:28 - In reply to message 3 from mMiniImManN
yes change <? with <?php in the start of every php file found.Thank you for the information.

  5. Re: Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of david david - 2012-01-25 15:16:54 - In reply to message 4 from vamshi
Hi,

I changed <? to <?php in all php files but I still get the same error as deepa:
Fatal error: Class 'OCR' not found in C:\wamp\www\example.php

I'm grateful for any advice.

  6. Re: Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of fabrice fabrice - 2012-02-13 02:07:47 - In reply to message 5 from david
ye make sure you have:
<?php //
instead of
<?php//

there should be a space ' ' after the <?php or you won't be able to get anything

  7. Re: Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of FutureC FutureC - 2014-03-21 05:57:10 - In reply to message 1 from deepa jithesh
Is this PHP OCR solution compatible with .NET framework?
I'm developing a project that need OCR technology and I tried one but it has some problems. Any suggestion?

Here's the solution I've tried:
rasteredge.com/how-to/asp-net-imagi ...

  8. Re: Fatal error: Class 'OCR' not found...   Reply   Report abuse  
Picture of Jony Green Jony Green - 2015-09-22 02:00:58 - In reply to message 1 from deepa jithesh
You can try this free online ocr to convert image to text(http://www.online-code.net/ocr.html).