<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<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>apuntes personales, arquitectura web y negocios en internet</description>
	<lastBuildDate>Wed, 25 Jan 2012 13:52:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>Por: John</title>
		<link>http://asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/#comment-1667</link>
		<dc:creator>John</dc:creator>
		<pubDate>Mon, 19 Jul 2010 17:27:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/#comment-1667</guid>
		<description>I had the same issue. You should check if all &quot;.php&quot; files starts with &quot;&lt;?php&quot; instead of &quot;&lt;?&quot;.
The problem is that one or two PHP files starts with &quot;&lt;?&quot; and the example file at the include_once statement instead of reading it as a php file, it just paste the whole text as plain text.</description>
		<content:encoded><![CDATA[<p>I had the same issue. You should check if all &#8220;.php&#8221; files starts with &#8220;&lt;?php&quot; instead of &quot;&lt;?&quot;.<br />
The problem is that one or two PHP files starts with &quot;&lt;?&quot; and the example file at the include_once statement instead of reading it as a php file, it just paste the whole text as plain text.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: pietro</title>
		<link>http://asiermarques.com/2007/06/25/phpocr-reconocer-texto-en-imagenes-desde-php/#comment-376</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-376</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-&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(&quot;./storage/&quot;); while (false !== ($entry = $d-&gt;read())) { if ((eregi(&quot;.char$&quot;,$entry))){ if ($this-&gt;checkCharObject(implode(&#039;&#039;,file(&quot;./storage/&quot;.$entry)))){ return unserialize(implode(&#039;&#039;,file(&quot;./storage/&quot;.$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 &quot;Check \&quot;&quot;.$char-&gt;getName().&quot;\&quot;
&quot;; } $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][&#039;type&#039;])) &amp;&amp; (($currentImagesInfo[$key][&#039;type&#039;]!=$value[&#039;type&#039;])&amp;&amp;($currentImagesInfo[$key][&#039;type&#039;]!=OCR::getNegative($value[&#039;type&#039;])))){ $m++; } } } if ($print){ echo &quot;We have &quot;.$m.&quot; errors
&quot;; } if ($m==0){ if ($print){ echo &quot;It is \&quot;&quot;.$char-&gt;getName().&quot;\&quot;
&quot;; } return true; }else{ if ($print){ echo &quot;It is not \&quot;&quot;.$char-&gt;getName().&quot;\&quot;
&quot;; } return false; } } /** * Save chars object to file in storage * */ function saveResult(){ $time = time(); $this-&gt;charObject-&gt;setTime($time); $fl = fopen(&quot;./storage/&quot;.$this-&gt;name.md5($this-&gt;name).&quot;.char&quot;,&quot;w&quot;); 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; 8) &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(&#039;Content-type: image/png&#039;); 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;
Fatal error: Class &#039;OCR&#039; 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(&#8220;./storage/&#8221;); while (false !== ($entry = $d-&gt;read())) { if ((eregi(&#8220;.char$&#8221;,$entry))){ if ($this-&gt;checkCharObject(implode(&#8221;,file(&#8220;./storage/&#8221;.$entry)))){ return unserialize(implode(&#8221;,file(&#8220;./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 &#8211; 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(&#8220;./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; 8) &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(&#8216;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-375</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-375</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>

