<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comentarios en: phpOCR, reconocer texto en imágenes desde php</title>
	<atom:link href="http://asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/</link>
	<description>Analista desarrollador web freelance</description>
	<pubDate>Fri, 29 Aug 2008 23:15:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>Por: pietro</title>
		<link>http://asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/#comment-12907</link>
		<dc:creator>pietro</dc:creator>
		<pubDate>Tue, 19 Feb 2008 10:22:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/#comment-12907</guid>
		<description>PLEASE give a solution for the below quoted error.When i m running the example.php class it displays the following error.
clear(); $this-&#62;name = $str; $this-&#62;createImage(); $this-&#62;charObject-&#62;setName($str); $this-&#62;charObject-&#62;setWidth($this-&#62;width); $this-&#62;charObject-&#62;setHeight($this-&#62;height); $this-&#62;makeCharObject(); } /** * Learn systems to understand symbols form image * * @param string $path * @param string $name */ function LearnFromImage($path, $name){ $this-&#62;clear(); $this-&#62;name = $name; $im = $this-&#62;createImageFromFile($path); $this-&#62;image = imagecreatetruecolor($this-&#62;width, $this-&#62;height); imagecopy($this-&#62;image, $im, 0, 0, 0, 0, $this-&#62;width, $this-&#62;height); $this-&#62;charObject-&#62;setName($name); $this-&#62;charObject-&#62;setWidth($this-&#62;width); $this-&#62;charObject-&#62;setHeight($this-&#62;height); $this-&#62;makeCharObject(); } /** * Create char object from image object * */ function makeCharObject(){ for ($x=0; $xwidth; $x++){ for ($y=0; $yheight; $y++){ $type = $this-&#62;getCornerType($this-&#62;image,$x,$y); if ($type!==false){ $this-&#62;charObject-&#62;setCorner($x, $y, $type); } } } } /** * Recognition method * * @param string $path * @return object */ function Recognition($path){ $this-&#62;clear(); $im = $this-&#62;createImageFromFile($path); $this-&#62;image = imagecreatetruecolor($this-&#62;width, $this-&#62;height); imagecopy($this-&#62;image, $im, 0, 0, 0, 0, $this-&#62;width, $this-&#62;height); $this-&#62;charObject-&#62;setWidth($this-&#62;width); $this-&#62;charObject-&#62;setHeight($this-&#62;height); $this-&#62;makeCharObject(); $d = dir("./storage/"); while (false !== ($entry = $d-&#62;read())) { if ((eregi(".char$",$entry))){ if ($this-&#62;checkCharObject(implode('',file("./storage/".$entry)))){ return unserialize(implode('',file("./storage/".$entry))); } } } $d-&#62;close(); return false; } /** * Get inverce corner * * @param int $type * @return int */ static function getNegative($type){ if ($type&#62;4){ return $type - 4; }else{ return $type + 4; } } /** * Clean up OCR object * */ function clear(){ unset($this-&#62;image); unset($this-&#62;charObject); unset($this-&#62;name); $this-&#62;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-&#62;getName()."\"
"; } $currentImagesInfo = $char-&#62;getImageInfo(); $imageInfo = $this-&#62;charObject-&#62;getImageInfo(); if (count($imageInfo)){ $m = 0; foreach ($imageInfo as $key =&#62; $value){ if ((isset($currentImagesInfo[$key]['type'])) &#38;&#38; (($currentImagesInfo[$key]['type']!=$value['type'])&#38;&#38;($currentImagesInfo[$key]['type']!=OCR::getNegative($value['type'])))){ $m++; } } } if ($print){ echo "We have ".$m." errors
"; } if ($m==0){ if ($print){ echo "It is \"".$char-&#62;getName()."\"
"; } return true; }else{ if ($print){ echo "It is not \"".$char-&#62;getName()."\"
"; } return false; } } /** * Save chars object to file in storage * */ function saveResult(){ $time = time(); $this-&#62;charObject-&#62;setTime($time); $fl = fopen("./storage/".$this-&#62;name.md5($this-&#62;name).".char","w"); fwrite($fl,serialize($this-&#62;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-&#62;name, $white); $this-&#62;getSize($im); $this-&#62;image = imagecreatetruecolor($this-&#62;width, $this-&#62;height); imagecopy($this-&#62;image, $im, 0, 0, 0, 0, $this-&#62;width, $this-&#62;height); } /** * get image size * * @param image $im */ function getSize($im){ $w = 0; $h = 0; for ($x=0; $x&#60;100; $x++){ for ($y=0; $ygetBWcolor($im, $x, $y)==COLOR_WHITE)&#38;&#38;($wgetBWcolor($im, $x, $y)==COLOR_WHITE)&#38;&#38;($h0)&#38;&#38;($h&#62;0)){ $w+=2; $h+=2; $this-&#62;width = $w; $this-&#62;height = $h; } } /** * Get type of corners * * @param image $im * @param int $x * @param int $y * @return int */ function getCornerType($im, $x, $y){ $p11 = $this-&#62;getBWcolor($im, $x, $y); $p21 = $this-&#62;getBWcolor($im, $x+1, $y); $p12 = $this-&#62;getBWcolor($im, $x, $y+1); $p22 = $this-&#62;getBWcolor($im, $x+1, $y+1); $sum = $p11 + $p12 + $p21 + $p22; if ($sum % 2 == 0){ return false; } if (($p11==COLOR_BLACK)&#38;&#38;($p21==COLOR_WHITE)&#38;&#38;($p12==COLOR_WHITE)&#38;&#38;($p22==COLOR_WHITE)){ return CORNER_BP_LEFT_TOP; } if (($p11==COLOR_WHITE)&#38;&#38;($p21==COLOR_BLACK)&#38;&#38;($p12==COLOR_WHITE)&#38;&#38;($p22==COLOR_WHITE)){ return CORNER_BP_RIGHT_TOP; } if (($p11==COLOR_WHITE)&#38;&#38;($p21==COLOR_WHITE)&#38;&#38;($p12==COLOR_BLACK)&#38;&#38;($p22==COLOR_WHITE)){ return CORNER_BP_LEFT_BOTTOM; } if (($p11==COLOR_WHITE)&#38;&#38;($p21==COLOR_WHITE)&#38;&#38;($p12==COLOR_WHITE)&#38;&#38;($p22==COLOR_BLACK)){ return CORNER_BP_RIGHT_BOTTOM; } if (($p11==COLOR_WHITE)&#38;&#38;($p21==COLOR_BLACK)&#38;&#38;($p12==COLOR_BLACK)&#38;&#38;($p22==COLOR_BLACK)){ return CORNER_WP_LEFT_TOP; } if (($p11==COLOR_BLACK)&#38;&#38;($p21==COLOR_WHITE)&#38;&#38;($p12==COLOR_BLACK)&#38;&#38;($p22==COLOR_BLACK)){ return CORNER_WP_RIGHT_TOP; } if (($p11==COLOR_BLACK)&#38;&#38;($p21==COLOR_BLACK)&#38;&#38;($p12==COLOR_WHITE)&#38;&#38;($p22==COLOR_BLACK)){ return CORNER_WP_LEFT_BOTTOM; } if (($p11==COLOR_BLACK)&#38;&#38;($p21==COLOR_BLACK)&#38;&#38;($p12==COLOR_BLACK)&#38;&#38;($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 &#62;&#62; 16) &#38; 0xFF; $g = ($rgb &#62;&#62; 8) &#38; 0xFF; $b = $rgb &#38; 0xFF; if (($r==255)&#38;&#38;($g==255)&#38;&#38;($b==255)){ return COLOR_WHITE; } return COLOR_BLACK; } /** * Output image * */ function outputImage(){ header('Content-type: image/png'); imagepng($this-&#62;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-&#62;width = $img_sz[0]; $this-&#62;height = $img_sz[1]; return $img; } } ?&#62;
Fatal error: Class 'OCR' not found in C:\wamp\www\phpocr-2006-02-10\example.php on line 14</description>
		<content:encoded><![CDATA[<p>PLEASE give a solution for the below quoted error.When i m running the example.php class it displays the following error.<br />
clear(); $this-&gt;name = $str; $this-&gt;createImage(); $this-&gt;charObject-&gt;setName($str); $this-&gt;charObject-&gt;setWidth($this-&gt;width); $this-&gt;charObject-&gt;setHeight($this-&gt;height); $this-&gt;makeCharObject(); } /** * Learn systems to understand symbols form image * * @param string $path * @param string $name */ function LearnFromImage($path, $name){ $this-&gt;clear(); $this-&gt;name = $name; $im = $this-&gt;createImageFromFile($path); $this-&gt;image = imagecreatetruecolor($this-&gt;width, $this-&gt;height); imagecopy($this-&gt;image, $im, 0, 0, 0, 0, $this-&gt;width, $this-&gt;height); $this-&gt;charObject-&gt;setName($name); $this-&gt;charObject-&gt;setWidth($this-&gt;width); $this-&gt;charObject-&gt;setHeight($this-&gt;height); $this-&gt;makeCharObject(); } /** * Create char object from image object * */ function makeCharObject(){ for ($x=0; $xwidth; $x++){ for ($y=0; $yheight; $y++){ $type = $this-&gt;getCornerType($this-&gt;image,$x,$y); if ($type!==false){ $this-&gt;charObject-&gt;setCorner($x, $y, $type); } } } } /** * Recognition method * * @param string $path * @return object */ function Recognition($path){ $this-&gt;clear(); $im = $this-&gt;createImageFromFile($path); $this-&gt;image = imagecreatetruecolor($this-&gt;width, $this-&gt;height); imagecopy($this-&gt;image, $im, 0, 0, 0, 0, $this-&gt;width, $this-&gt;height); $this-&gt;charObject-&gt;setWidth($this-&gt;width); $this-&gt;charObject-&gt;setHeight($this-&gt;height); $this-&gt;makeCharObject(); $d = dir(&#8221;./storage/&#8221;); while (false !== ($entry = $d-&gt;read())) { if ((eregi(&#8221;.char$&#8221;,$entry))){ if ($this-&gt;checkCharObject(implode(&#8221;,file(&#8221;./storage/&#8221;.$entry)))){ return unserialize(implode(&#8221;,file(&#8221;./storage/&#8221;.$entry))); } } } $d-&gt;close(); return false; } /** * Get inverce corner * * @param int $type * @return int */ static function getNegative($type){ if ($type&gt;4){ return $type - 4; }else{ return $type + 4; } } /** * Clean up OCR object * */ function clear(){ unset($this-&gt;image); unset($this-&gt;charObject); unset($this-&gt;name); $this-&gt;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 &#8220;Check \&#8221;".$char-&gt;getName().&#8221;\&#8221;<br />
&#8220;; } $currentImagesInfo = $char-&gt;getImageInfo(); $imageInfo = $this-&gt;charObject-&gt;getImageInfo(); if (count($imageInfo)){ $m = 0; foreach ($imageInfo as $key =&gt; $value){ if ((isset($currentImagesInfo[$key]['type'])) &amp;&amp; (($currentImagesInfo[$key]['type']!=$value['type'])&amp;&amp;($currentImagesInfo[$key]['type']!=OCR::getNegative($value['type'])))){ $m++; } } } if ($print){ echo &#8220;We have &#8220;.$m.&#8221; errors<br />
&#8220;; } if ($m==0){ if ($print){ echo &#8220;It is \&#8221;".$char-&gt;getName().&#8221;\&#8221;<br />
&#8220;; } return true; }else{ if ($print){ echo &#8220;It is not \&#8221;".$char-&gt;getName().&#8221;\&#8221;<br />
&#8220;; } return false; } } /** * Save chars object to file in storage * */ function saveResult(){ $time = time(); $this-&gt;charObject-&gt;setTime($time); $fl = fopen(&#8221;./storage/&#8221;.$this-&gt;name.md5($this-&gt;name).&#8221;.char&#8221;,&#8221;w&#8221;); fwrite($fl,serialize($this-&gt;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-&gt;name, $white); $this-&gt;getSize($im); $this-&gt;image = imagecreatetruecolor($this-&gt;width, $this-&gt;height); imagecopy($this-&gt;image, $im, 0, 0, 0, 0, $this-&gt;width, $this-&gt;height); } /** * get image size * * @param image $im */ function getSize($im){ $w = 0; $h = 0; for ($x=0; $x&lt;100; $x++){ for ($y=0; $ygetBWcolor($im, $x, $y)==COLOR_WHITE)&amp;&amp;($wgetBWcolor($im, $x, $y)==COLOR_WHITE)&amp;&amp;($h0)&amp;&amp;($h&gt;0)){ $w+=2; $h+=2; $this-&gt;width = $w; $this-&gt;height = $h; } } /** * Get type of corners * * @param image $im * @param int $x * @param int $y * @return int */ function getCornerType($im, $x, $y){ $p11 = $this-&gt;getBWcolor($im, $x, $y); $p21 = $this-&gt;getBWcolor($im, $x+1, $y); $p12 = $this-&gt;getBWcolor($im, $x, $y+1); $p22 = $this-&gt;getBWcolor($im, $x+1, $y+1); $sum = $p11 + $p12 + $p21 + $p22; if ($sum % 2 == 0){ return false; } if (($p11==COLOR_BLACK)&amp;&amp;($p21==COLOR_WHITE)&amp;&amp;($p12==COLOR_WHITE)&amp;&amp;($p22==COLOR_WHITE)){ return CORNER_BP_LEFT_TOP; } if (($p11==COLOR_WHITE)&amp;&amp;($p21==COLOR_BLACK)&amp;&amp;($p12==COLOR_WHITE)&amp;&amp;($p22==COLOR_WHITE)){ return CORNER_BP_RIGHT_TOP; } if (($p11==COLOR_WHITE)&amp;&amp;($p21==COLOR_WHITE)&amp;&amp;($p12==COLOR_BLACK)&amp;&amp;($p22==COLOR_WHITE)){ return CORNER_BP_LEFT_BOTTOM; } if (($p11==COLOR_WHITE)&amp;&amp;($p21==COLOR_WHITE)&amp;&amp;($p12==COLOR_WHITE)&amp;&amp;($p22==COLOR_BLACK)){ return CORNER_BP_RIGHT_BOTTOM; } if (($p11==COLOR_WHITE)&amp;&amp;($p21==COLOR_BLACK)&amp;&amp;($p12==COLOR_BLACK)&amp;&amp;($p22==COLOR_BLACK)){ return CORNER_WP_LEFT_TOP; } if (($p11==COLOR_BLACK)&amp;&amp;($p21==COLOR_WHITE)&amp;&amp;($p12==COLOR_BLACK)&amp;&amp;($p22==COLOR_BLACK)){ return CORNER_WP_RIGHT_TOP; } if (($p11==COLOR_BLACK)&amp;&amp;($p21==COLOR_BLACK)&amp;&amp;($p12==COLOR_WHITE)&amp;&amp;($p22==COLOR_BLACK)){ return CORNER_WP_LEFT_BOTTOM; } if (($p11==COLOR_BLACK)&amp;&amp;($p21==COLOR_BLACK)&amp;&amp;($p12==COLOR_BLACK)&amp;&amp;($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 &gt;&gt; 16) &amp; 0xFF; $g = ($rgb &gt;&gt; <img src='http://asiermarques.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> &amp; 0xFF; $b = $rgb &amp; 0xFF; if (($r==255)&amp;&amp;($g==255)&amp;&amp;($b==255)){ return COLOR_WHITE; } return COLOR_BLACK; } /** * Output image * */ function outputImage(){ header(&#8217;Content-type: image/png&#8217;); imagepng($this-&gt;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-&gt;width = $img_sz[0]; $this-&gt;height = $img_sz[1]; return $img; } } ?&gt;<br />
Fatal error: Class &#8216;OCR&#8217; not found in C:\wamp\www\phpocr-2006-02-10\example.php on line 14</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: Cesar Rodas</title>
		<link>http://asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/#comment-50</link>
		<dc:creator>Cesar Rodas</dc:creator>
		<pubDate>Tue, 26 Jun 2007 16:36:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/#comment-50</guid>
		<description>Sería bueno que alguien se interese y extienda este proyecto, ya que es muy  bueno</description>
		<content:encoded><![CDATA[<p>Sería bueno que alguien se interese y extienda este proyecto, ya que es muy  bueno</p>
]]></content:encoded>
	</item>
</channel>
</rss>
