<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tara Andrei &#187; php</title>
	<atom:link href="http://andreitara.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://andreitara.com</link>
	<description>I could change the world if they would let my allocate more instances of myself.</description>
	<lastBuildDate>Mon, 13 Jun 2011 21:32:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Perform face detection in PHP</title>
		<link>http://andreitara.com/2011/06/perform-face-detection-in-php/</link>
		<comments>http://andreitara.com/2011/06/perform-face-detection-in-php/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 21:31:41 +0000</pubDate>
		<dc:creator>andreiT</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[computer vision]]></category>
		<category><![CDATA[face detection php]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[php module]]></category>

		<guid isPermaLink="false">http://www.andreitara.com/?p=364</guid>
		<description><![CDATA[This short article will learn you how to perform face detection in PHP. So basically we are going to make use of OpenCV ( you know it you are using it everyday &#8230;aren&#8217;t you ?? ) we actually will abuse only on face detection algorithm that comes with it. We are going to compile the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.andreitara.com/wp-content/uploads/2011/06/clip_php_cms.png"><img class="alignleft size-full wp-image-374" style="margin: 10px;" title="clip_php_cms" src="http://www.andreitara.com/wp-content/uploads/2011/06/clip_php_cms.png" alt="" width="342" height="198" /></a>This short article will learn you how to perform <strong>face detection</strong> in <strong>PHP</strong>. So basically we are going to make use of OpenCV ( you know it you are using it everyday &#8230;aren&#8217;t you ?? <img src='http://andreitara.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  ) we actually will abuse only on face detection algorithm that comes with it. We are going to compile the face detection as an .so module for php and hook this module in PHP.</p>
<p>&nbsp;</p>
<p>Requirements:</p>
<ul>
<li>LAMP stack installed, you know&#8230; Apache 2, PHP</li>
<li>Build essentials (gcc compilers and all the hoard )</li>
<li>A Linux distribution (mine is Ubuntu  11.something)</li>
<li>1 beer &amp; nothing beater to do  <img src='http://andreitara.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> <span id="more-364"></span></li>
</ul>
<p>OK so the fist thing that you have to do is to install the build essentials by running the command :</p>
<blockquote>
<pre escaped="true">sudo apt-get install build-essential</pre>
</blockquote>
<p>Be proud ! and tell to all you&#8217;re friends ! you are a linux developer &#8217;cause you have a compiler running on you PC. Now that you can compile c/c++ files you will need the OpenCV library. There are two ways to install it: that first is to download the latest version from http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.2/ and run make and make-install commands (not recommended, there is always a missing library or a stupid error ) or you just can open System-&gt;Administration-&gt;Synaptic package manager search <strong>opencv</strong> and check all the libraries as in the following image:</p>
<p><a href="http://www.andreitara.com/wp-content/uploads/2011/06/Screenshot-3.png"><img class="size-full wp-image-365 alignnone" title="Screenshot-3" src="http://www.andreitara.com/wp-content/uploads/2011/06/Screenshot-3.png" alt="" width="545" height="396" /></a></p>
<p>OpenCv library is installed but&#8230; hold on, do not touch you&#8217;re beer yet ! you still have to download and compile facedetection library, do that by using the following magic incantation :</p>
<blockquote>
<pre escaped="true">wget http://www.xarg.org/download/facedetect-1.0.1.tar.gz
tar -xvf facedetect-1.0.1.tar.gz
cd facedetect
phpize
configure
make
make-install</pre>
</blockquote>
<p>Congratulation !! you parents should be so proud of  you, now is the first time when you have compiled a module for PHP. The facedetect.so was created and copied to the corresponding PHP lib directory (/usr/lib/PPH5), add <strong>extension=facedetect.so</strong> to the php.ini file ( in  /etc/php5/apache2/php.ini or a similar location) restart the apache, now if you run phpinfo you should see the facedetect module up and running:</p>
<p><a href="http://www.andreitara.com/wp-content/uploads/2011/06/Screenshot-4.png"><img class="alignnone size-full wp-image-366" title="Screenshot-4" src="http://www.andreitara.com/wp-content/uploads/2011/06/Screenshot-4.png" alt="" width="541" height="202" /></a></p>
<p>Now let&#8217;s create a PHP file ( for e.g. face.php)  with the following content:</p>
<blockquote><p>&lt;?php</p>
<p>function LoadJpeg($img) {<br />
$im = @imagecreatefromjpeg($img);<br />
if (!$im) {</p>
<p>echo &#8216;Bad image&#8217;;<br />
}</p>
<p>$total = face_count($_GET['file'], &#8216;haarcascade_frontalface_alt.xml&#8217;);<br />
$rectangles = face_detect($_GET['file'], &#8216;haarcascade_frontalface_alt.xml&#8217;);</p>
<p>$im = LoadJpeg($_GET['file']);<br />
$pink = imagecolorallocate($im, 255, 105, 180);</p>
<p>if (count($rectangles) &gt; 0) {</p>
<p>foreach ($rectangles as $arr) {<br />
imagerectangle($im, $arr['x'], $arr['y'], $arr['x'] + $arr['w'],<br />
$arr['y'] + $arr['h'], $pink);<br />
}<br />
}<br />
header(&#8216;Content-Type: image/jpeg&#8217;);<br />
imagejpeg($im);<br />
imagedestroy($im);</p></blockquote>
<p>now run it in the browser http://localhost/face.php?file=lena.jpg and voala !!! you have detected the face of Lenna (still have to test it on fill version of Lenna <img src='http://andreitara.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) .</p>
<p><a href="http://www.andreitara.com/wp-content/uploads/2011/06/Screenshot-5.png"><img class="alignnone size-full wp-image-367" title="Screenshot-5" src="http://www.andreitara.com/wp-content/uploads/2011/06/Screenshot-5.png" alt="" width="406" height="395" /></a></p>
<p>While you are enjoying you&#8217;re beer just add few words as feed back in section belowww.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreitara.com/2011/06/perform-face-detection-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bad web programming technique.</title>
		<link>http://andreitara.com/2010/02/bad-web-programming-technique/</link>
		<comments>http://andreitara.com/2010/02/bad-web-programming-technique/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 19:01:19 +0000</pubDate>
		<dc:creator>andreiT</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[spaghetti code]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://www.andreitara.com/?p=215</guid>
		<description><![CDATA[ASP.Net and JSP are two wonderful enviroment to create web application, application that are easy to modify and adapt to all requirements, but the major problems of ASP.Net and JSP is that they are not cheap and slow, in fact there are not many hosting provider that are offering hosting service for this technologies at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-217" title="code-stickers" src="http://www.andreitara.com/wp-content/uploads/2010/02/code-stickers1.jpg" alt="code-stickers" width="207" height="155" />ASP.Net and JSP are two wonderful enviroment to create web application, application that are easy to modify and adapt to all requirements, but the major problems of ASP.Net and JSP is that they are not cheap and slow, in fact there are not many hosting provider that are offering hosting service for this technologies at a affordable price (for a common user ).</p>
<p>Therefore  other affordable technology like PHP are commonly wide used by most common users. In comparison with Java  or C#,  PHP language is pretty simple and doesn&#8217;t relay on so much formalism and doesn&#8217;t need a lot of knowledge about programming, allowing users to create application without knowing much think about programming technique.</p>
<p>The side effect is that the applications developed in this way are extremely hard to debug and even more harder to extend from a very wide variety of factors, some I will discuss later in this paper.</p>
<ol>
<li> The first think to speak about  is the <em><strong>&#8220;spaghetti code&#8221;</strong></em> where the entire application logic (code) is meshed up in same file, you know what I am talking about: a lot of  if/else/for/while and functions with no logic organization.  To extend such crap application wrote by some other programmers is quite hard and unproductive.</li>
<li> Since version 4 PHP offers OOP(object orientated programming) but it seams that most of users doesn&#8217;t know how to use it right, how to increase their productivity using OOP programming technique and software engineering technique .It seams that web programmers are still writing code like in the stone age.</li>
<li>Another problem, <strong>the biggest one</strong> is that users are creating applications dependent on design. The design of a web site is changing frequently that means restructuring the code again and again and again.</li>
</ol>
<p>The list is still open. I will continue to add more and more bad programming technique.</p>
]]></content:encoded>
			<wfw:commentRss>http://andreitara.com/2010/02/bad-web-programming-technique/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

