<?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>Silveira Neto &#187; opencv</title>
	<atom:link href="http://silveiraneto.net/tag/opencv/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>OpenCV on Ubuntu</title>
		<link>http://silveiraneto.net/2009/12/21/opencv-on-ubuntu/</link>
		<comments>http://silveiraneto.net/2009/12/21/opencv-on-ubuntu/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 04:18:49 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[9.10]]></category>
		<category><![CDATA[image processing]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[karmic koala]]></category>
		<category><![CDATA[open computer vision library]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2786</guid>
		<description><![CDATA[Open Computer Vision Library or just OpenCV, is a cross-platform computer vision library focused on real-time image processing for video files or webcams. You have two options to obtain the environment to develop on OpenCV. You can insert a new repository in your package manager or compile it by yourself. For Ubuntu 9.10 Karmic Koala [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-2974 aligncenter" title="digital_eye" src="http://silveiraneto.net/wp-content/uploads/2009/11/digital_eye.jpeg" alt="digital_eye" width="350" height="309" /></p>
<p><a href="http://sourceforge.net/projects/opencvlibrary/">Open Computer Vision Library</a> or just OpenCV, is a cross-platform computer vision library focused on real-time image processing for video files or webcams.</p>
<p>You have two options to obtain the environment to develop on OpenCV. You can insert a new repository in your package manager or compile it by yourself.</p>
<p><a title="OpenCV Package for Ubuntu 9.10" href="https://launchpad.net/~gijzelaar/+archive/opencv2-karmic">For Ubuntu 9.10 Karmic Koala there&#8217;s this repository with OpenCV&#8217;s package</a>.</p>
<p>To compile it you have to install some additional libraries compile it by your self. And it&#8217;s instructions vary for each distribution and version. For example, from Ubuntu Linux 9.10 to 9.04, the process varies slightly. I followed the instructions on this post <a title="how to install OpenCV on Ubuntu 9.10" href="http://ivkin.net/2009/11/installing-opencv-2-0-on-ubuntu-9-10-karmic-koala/">&#8220;Installing OpenCV 2.0 on Ubuntu 9.10 Karmic Koala&#8221;</a>.</p>
<p>After you have installed and have a well configured OpenCV development environment, you can compile a &#8220;source.c&#8221; file into a &#8220;program&#8221; binary like this:</p>
<blockquote><p>gcc gcc source.c -o program `pkg-config opencv ‑‑libs ‑‑cflags`</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/12/21/opencv-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenCV: Hue, Saturation and Value.</title>
		<link>http://silveiraneto.net/2009/12/08/opencv-hue-saturation-and-value/</link>
		<comments>http://silveiraneto.net/2009/12/08/opencv-hue-saturation-and-value/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:52:43 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[hue]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[saturation]]></category>
		<category><![CDATA[value]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3018</guid>
		<description><![CDATA[Here a simple OpenCV example of separation of a image into its hue, saturation and value channels. #include &#60;stdio.h&#62; #include &#60;cv.h&#62; #include &#60;highgui.h&#62; &#160; int main&#40; int argc, char **argv &#41;&#123; IplImage *img, *hsv, *hue, *sat, *val; int key = 0, depth; CvSize size; &#160; /* Load command line passed image, check it. */ if [...]]]></description>
			<content:encoded><![CDATA[<p>Here a simple OpenCV example of separation of a image into its <a href="http://en.wikipedia.org/wiki/HSL_and_HSV">hue, saturation and value</a> channels.</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;cv.h&gt;</span>
<span style="color: #339933;">#include &lt;highgui.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    IplImage <span style="color: #339933;">*</span>img<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>hsv<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>hue<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>sat<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>val;
    <span style="color: #993333;">int</span> key <span style="color: #339933;">=</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> depth;
    CvSize size;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Load command line passed image, check it. */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        img <span style="color: #339933;">=</span> cvLoadImage<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> CV_LOAD_IMAGE_COLOR<span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>img<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Could not open image.&quot;</span><span style="color: #009900;">&#41;</span>;
            exit <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>img<span style="color: #339933;">-&gt;</span>nChannels<span style="color: #339933;">!=</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;We need color image!&quot;</span><span style="color: #009900;">&#41;</span>;
            exit <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: %s VIDEO_FILE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Create a hsv image with 3 channels and hue, sat e val with 1 channel.
       All with the same size */</span>
    size <span style="color: #339933;">=</span> cvGetSize<span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span>;
    depth <span style="color: #339933;">=</span> img<span style="color: #339933;">-&gt;</span>depth;
    hue <span style="color: #339933;">=</span> cvCreateImage<span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span> depth<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
    sat <span style="color: #339933;">=</span> cvCreateImage<span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span> depth<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
    val <span style="color: #339933;">=</span> cvCreateImage<span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span> depth<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
    hsv <span style="color: #339933;">=</span> cvCreateImage<span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span> depth<span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span>;
    cvZero<span style="color: #009900;">&#40;</span>hue<span style="color: #009900;">&#41;</span>;
    cvZero<span style="color: #009900;">&#40;</span>sat<span style="color: #009900;">&#41;</span>;
    cvZero<span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span>;
    cvZero<span style="color: #009900;">&#40;</span>hsv<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Convert from Red-Green-Blue to Hue-Saturation-Value */</span>
    cvCvtColor<span style="color: #009900;">&#40;</span> img<span style="color: #339933;">,</span> hsv<span style="color: #339933;">,</span> CV_BGR2HSV <span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Split hue, saturation and value of hsv on them */</span>
    cvSplit<span style="color: #009900;">&#40;</span>hsv<span style="color: #339933;">,</span> hue<span style="color: #339933;">,</span> sat<span style="color: #339933;">,</span> val<span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Create windows, display them, wait for a key */</span>
    cvNamedWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;original&quot;</span><span style="color: #339933;">,</span> CV_WINDOW_AUTOSIZE<span style="color: #009900;">&#41;</span>;
    cvNamedWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;hue&quot;</span><span style="color: #339933;">,</span> CV_WINDOW_AUTOSIZE<span style="color: #009900;">&#41;</span>;
    cvNamedWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;saturation&quot;</span><span style="color: #339933;">,</span> CV_WINDOW_AUTOSIZE<span style="color: #009900;">&#41;</span>;
    cvNamedWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #339933;">,</span> CV_WINDOW_AUTOSIZE<span style="color: #009900;">&#41;</span>;
&nbsp;
    cvShowImage<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;original&quot;</span><span style="color: #339933;">,</span> img<span style="color: #009900;">&#41;</span>;
    cvShowImage<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;hue&quot;</span><span style="color: #339933;">,</span> hue<span style="color: #009900;">&#41;</span>;
    cvShowImage<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;saturation&quot;</span><span style="color: #339933;">,</span> sat<span style="color: #009900;">&#41;</span>;
    cvShowImage<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span>;
&nbsp;
    cvWaitKey<span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Free memory and get out */</span>
    cvDestroyWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;original&quot;</span><span style="color: #009900;">&#41;</span>;
    cvDestroyWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;hue&quot;</span><span style="color: #009900;">&#41;</span>;
    cvDestroyWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;saturation&quot;</span><span style="color: #009900;">&#41;</span>;
    cvDestroyWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>img<span style="color: #009900;">&#41;</span>;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>hsv<span style="color: #009900;">&#41;</span>;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>hue<span style="color: #009900;">&#41;</span>;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>sat<span style="color: #009900;">&#41;</span>;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>val<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color:#800080;">0</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Resized <a href="http://commons.wikimedia.org/wiki/File:Peter_iredale_sunset_edited1.jpg">original image</a>, photo by Robert Bradshaw at <a href="http://commons.wikimedia.org">Wikimedia Commons</a>.</p>
<p><center><img src="http://silveiraneto.net/wp-content/uploads/2009/12/sunset2.jpg" alt="Sunset Peter Iredale" title="Sunset Peter Iredale" width="300" height="228" class="alignnone size-full wp-image-3019" /></center></p>
<p>Hue channel:<br />
<center><img src="http://silveiraneto.net/wp-content/uploads/2009/12/hue.png" alt="hue sunset Peter Iredale" title="hue" width="300" height="228" class="alignnone size-full wp-image-3020" /></center></p>
<p>Saturation channel:<br />
<center><img src="http://silveiraneto.net/wp-content/uploads/2009/12/sat.png" alt="saturation sunset Peter Iredale" title="saturation sunset Peter Iredale" width="300" height="228" class="alignnone size-full wp-image-3021" /></center></p>
<p>Value channel:<br />
<center><img src="http://silveiraneto.net/wp-content/uploads/2009/12/value.png" alt="value sunset Peter Iredale" title="value sunset Peter Iredale" width="300" height="228" class="alignnone size-full wp-image-3022" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/12/08/opencv-hue-saturation-and-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenCV: adding two images</title>
		<link>http://silveiraneto.net/2009/12/08/opencv-adding-two-images/</link>
		<comments>http://silveiraneto.net/2009/12/08/opencv-adding-two-images/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 04:55:05 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Computer Vision]]></category>
		<category><![CDATA[cvadd]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[surfer]]></category>
		<category><![CDATA[universe]]></category>
		<category><![CDATA[wikimedia]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3013</guid>
		<description><![CDATA[This is a very simple example of how to open two images and display them added. I got two pictures at project Commons from Wikimedia that were highlighted on Featured Pictures. I did a crop on both to have the same size, as I&#8217;m trying to make this example as simple as possible. The first [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very simple example of how to open two images and display them added.</p>
<p>I got two pictures at project <a href="http://commons.wikimedia.org">Commons</a> from <a href="http://wikimedia.org">Wikimedia</a> <span id="result_box"><span style="background-color: #ffffff;" title="Duas imagens que ganharam destaque.">that were highlighted on Featured Pictures</span></span>. I did a crop on both to have the same size, as I&#8217;m trying to make this example as simple as possible.</p>
<p>The <a title="Wikipedia" href="http://commons.wikimedia.org/wiki/File:Guisard_-_Milky_Way.jpg">first one is a photo of our Milky Way</a>, taken at <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Paranal_Observatory">Paranal Observatory</a> by Stéphane Guisard.</p>
<p style="text-align: center;"><img class="size-full wp-image-3014 aligncenter" title="milkyway sky Stéphane Guisard Paranal" src="http://silveiraneto.net/wp-content/uploads/2009/12/milkyway.jpg" alt="milkyway " width="500" height="400" /></p>
<p>The second one is a <a href="http://commons.wikimedia.org/wiki/File:California_surfer_inside_wave.jpg">California surfer inside wave</a>, taken by <a href="http://home.comcast.net/~milazinkova/Fogshadow.html">Mila Zinkova</a>.</p>
<p style="text-align: center;"><img class="size-full wp-image-3015 aligncenter" title="surfer" src="http://silveiraneto.net/wp-content/uploads/2009/12/surfer.jpg" alt="surfer" width="500" height="400" /></p>
<p>In this simple <a title="OpenCV" href="http://sourceforge.net/projects/opencvlibrary/">OpenCV</a> code below, we open the images, create a new one to display the result and use cvAdd to add them. We do not save the result or handle more than the ordinary case of two images with the same size.</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;cv.h&gt;</span>
<span style="color: #339933;">#include &lt;highgui.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    IplImage <span style="color: #339933;">*</span>surfer<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>milkyway<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>result;
    <span style="color: #993333;">int</span> key <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
    CvSize size;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* load images, check, get size (both should have the same) */</span>
    surfer <span style="color: #339933;">=</span> cvLoadImage<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;surfer.jpg&quot;</span><span style="color: #339933;">,</span> CV_LOAD_IMAGE_COLOR<span style="color: #009900;">&#41;</span>;
    milkyway <span style="color: #339933;">=</span> cvLoadImage<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;milkyway.jpg&quot;</span><span style="color: #339933;">,</span> CV_LOAD_IMAGE_COLOR<span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>surfer<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>milkyway<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Could not open one or more images.&quot;</span><span style="color: #009900;">&#41;</span>;
        exit <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
    size <span style="color: #339933;">=</span> cvGetSize<span style="color: #009900;">&#40;</span>surfer<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* create a empty image, same size, depth and channels of others */</span>
    result <span style="color: #339933;">=</span> cvCreateImage<span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span> surfer<span style="color: #339933;">-&gt;</span>depth<span style="color: #339933;">,</span> surfer<span style="color: #339933;">-&gt;</span>nChannels<span style="color: #009900;">&#41;</span>;
    cvZero<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* result = surfer + milkyway (NULL mask)*/</span>
    cvAdd<span style="color: #009900;">&#40;</span>surfer<span style="color: #339933;">,</span> milkyway<span style="color: #339933;">,</span> result<span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* create a window, display the result, wait for a key */</span>
    cvNamedWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;example&quot;</span><span style="color: #339933;">,</span> CV_WINDOW_AUTOSIZE<span style="color: #009900;">&#41;</span>;
    cvShowImage<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;example&quot;</span><span style="color: #339933;">,</span> result<span style="color: #009900;">&#41;</span>;
    cvWaitKey<span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* free memory and get out */</span>
    cvDestroyWindow<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;example&quot;</span><span style="color: #009900;">&#41;</span>;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>surfer<span style="color: #009900;">&#41;</span>;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>milkyway<span style="color: #009900;">&#41;</span>;
    cvReleaseImage<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>result<span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">return</span> <span style="color:#800080;">0</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* gcc add.c -o add `pkg-config opencv --libs --cflags` */</span></pre>
</div>
</div>
<p>Compile it (on a well configured OpenCV development environment) and run it:</p>
<blockquote><p>gcc add.c -o add `pkg-config opencv &#8211;libs &#8211;cflags`<br />
./add</p></blockquote>
<p>The result got pretty cool, a milky way surfer.</p>
<p style="text-align: center;"><img class="size-full wp-image-3016 aligncenter" title="surfer in the milk way" src="http://silveiraneto.net/wp-content/uploads/2009/12/result.jpg" alt="surfer in the milk way" width="500" height="400" /></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/12/08/opencv-adding-two-images/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>OpenCV: Edge Detection</title>
		<link>http://silveiraneto.net/2009/12/04/opencv-edge-detection/</link>
		<comments>http://silveiraneto.net/2009/12/04/opencv-edge-detection/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 11:50:14 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Canny]]></category>
		<category><![CDATA[Computer Vision]]></category>
		<category><![CDATA[cvCanny]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[vision]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3004</guid>
		<description><![CDATA[This is a simple example of how pass edge detection in a video using OpenCV. It uses the built-in OpenCV Canny edge detector algorithm. #include &#60;highgui.h&#62; #include &#60;stdio.h&#62; #include &#60;cv.h&#62; &#160; int main&#40;int argc, char *argv&#91;&#93;&#41; &#123; int delay = 0, key=0, i=0; char *window_name; CvCapture *video = NULL; IplImage *frame = NULL; IplImage *grey [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple example of how pass edge detection in a video using <a title="OpenCV" href="http://sourceforge.net/projects/opencvlibrary/">OpenCV</a>. It uses the built-in OpenCV <a title="Wikipedia" href="http://en.wikipedia.org/wiki/Canny_edge_detector">Canny edge detector algorithm</a>.</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;highgui.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;cv.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> delay <span style="color: #339933;">=</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> key<span style="color: #339933;">=</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color:#800080;">0</span>;
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>window_name;
    CvCapture <span style="color: #339933;">*</span>video <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
    IplImage  <span style="color: #339933;">*</span>frame <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
    IplImage  <span style="color: #339933;">*</span>grey  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
    IplImage  <span style="color: #339933;">*</span>edges <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* check for video file passed by command line */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        video <span style="color: #339933;">=</span> cvCaptureFromFile<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: %s VIDEO_FILE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* check file was correctly opened */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>video<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Unable to open <span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* create a video window with same name of the video file, auto sized */</span>
    window_name <span style="color: #339933;">=</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>;
    cvNamedWindow<span style="color: #009900;">&#40;</span>window_name<span style="color: #339933;">,</span> CV_WINDOW_AUTOSIZE<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Get the first frame and create a edges image with the same size */</span>
    frame <span style="color: #339933;">=</span> cvQueryFrame<span style="color: #009900;">&#40;</span>video<span style="color: #009900;">&#41;</span>;
    grey  <span style="color: #339933;">=</span> cvCreateImage<span style="color: #009900;">&#40;</span>cvGetSize<span style="color: #009900;">&#40;</span>frame<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> IPL_DEPTH_8U<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
    edges <span style="color: #339933;">=</span> cvCreateImage<span style="color: #009900;">&#40;</span>cvGetSize<span style="color: #009900;">&#40;</span>frame<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> IPL_DEPTH_8U<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* calculate the delay between each frame and display video's FPS */</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%2.2f FPS<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> cvGetCaptureProperty<span style="color: #009900;">&#40;</span>video<span style="color: #339933;">,</span> CV_CAP_PROP_FPS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    delay <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">/</span>cvGetCaptureProperty<span style="color: #009900;">&#40;</span>video<span style="color: #339933;">,</span> CV_CAP_PROP_FPS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>frame<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/* Edges on the input gray image (needs to be grayscale) using the Canny algorithm.
           Uses two threshold and a aperture parameter for Sobel operator. */</span>
        cvCvtColor<span style="color: #009900;">&#40;</span>frame<span style="color: #339933;">,</span> grey<span style="color: #339933;">,</span> CV_BGR2GRAY<span style="color: #009900;">&#41;</span>;
        cvCanny<span style="color: #009900;">&#40;</span> grey<span style="color: #339933;">,</span> edges<span style="color: #339933;">,</span> <span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* show loaded frame */</span>
        cvShowImage<span style="color: #009900;">&#40;</span>window_name<span style="color: #339933;">,</span> edges<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* load and check next frame*/</span>
        frame <span style="color: #339933;">=</span> cvQueryFrame<span style="color: #009900;">&#40;</span>video<span style="color: #009900;">&#41;</span>;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>frame<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;error loading frame.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* wait delay and check for the quit key */</span>
        key <span style="color: #339933;">=</span> cvWaitKey<span style="color: #009900;">&#40;</span>delay<span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">==</span><span style="color: #ff0000;">'q'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>To compile it in a well configured OpenCV development environment:</p>
<blockquote><p>gcc edgeplayer.c -o edgeplayer `pkg-config opencv &#8211;libs &#8211;cflags`</p></blockquote>
<p>To run it call edgeplayer and the name of the video:</p>
<blockquote><p>./edgeplayer rick.avi</p></blockquote>
<p>The result is something similar to this:</p>
<p><center><img src="http://silveiraneto.net/wp-content/uploads/2009/12/rickedge.png" alt="rick roll edge" title="rick roll edge" width="400" height="240" class="alignnone size-full wp-image-3005" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/12/04/opencv-edge-detection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Face Detection Player</title>
		<link>http://silveiraneto.net/2009/12/01/simple-face-detection-player/</link>
		<comments>http://silveiraneto.net/2009/12/01/simple-face-detection-player/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 22:03:15 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[Paul Viola]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Rainer Lienhar]]></category>
		<category><![CDATA[vision]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2987</guid>
		<description><![CDATA[Here&#8217;s a simple video player that also performs facial detection thought the Open Computer Vision Library. Here&#8217;s a code developed using codes from nashruddin.com and samples from OpenCV, including the haar classifier xml. More detailed explanation on the theory about how the OpenCV face detection algorithm works can be found here. The code: #include &#60;highgui.h&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple video player that also performs facial detection thought the <a title="OpenCV at Wikipedia" href="http://en.wikipedia.org/wiki/OpenCV">Open Computer Vision Library</a>.</p>
<p>Here&#8217;s a code developed using codes <a title="OpenCV Face Detection" href="http://nashruddin.com/OpenCV_Face_Detection">from nashruddin.com</a> and samples from <a title="OpenCV Project" href="http://sourceforge.net/projects/opencvlibrary/">OpenCV</a>, including the haar classifier xml. More detailed explanation on the theory about how the OpenCV face detection algorithm works can be found <a title="Face Detection on OpenCV" href="http://opencv.willowgarage.com/wiki/FaceDetection">here</a>.</p>
<p>The code:</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;highgui.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;cv.h&gt;</span>
&nbsp;
CvHaarClassifierCascade <span style="color: #339933;">*</span>cascade;
CvMemStorage <span style="color: #339933;">*</span>storage;
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    CvCapture <span style="color: #339933;">*</span>video <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
    IplImage <span style="color: #339933;">*</span>frame <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #993333;">int</span> delay <span style="color: #339933;">=</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> key<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color:#800080;">0</span>;
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>window_name <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Video&quot;</span>;
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>cascadefile <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;haarcascade_frontalface_alt.xml&quot;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* check for video file passed by command line */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        video <span style="color: #339933;">=</span> cvCaptureFromFile<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: %s VIDEO_FILE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* check file was correctly opened */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>video<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Unable to open <span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* load the classifier */</span>
    cascade <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> CvHaarClassifierCascade<span style="color: #339933;">*</span> <span style="color: #009900;">&#41;</span>cvLoad<span style="color: #009900;">&#40;</span> cascadefile<span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span> <span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cascade<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Error loading the classifier.&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* setup the memory buffer for the face detector */</span>
    storage <span style="color: #339933;">=</span> cvCreateMemStorage<span style="color: #009900;">&#40;</span> <span style="color:#800080;">0</span> <span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>storage<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Error creating the memory storage.&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* create a video window, auto size */</span>
    cvNamedWindow<span style="color: #009900;">&#40;</span>window_name<span style="color: #339933;">,</span> CV_WINDOW_AUTOSIZE<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* get a frame. Necessary for use the cvGetCaptureProperty */</span>
    frame <span style="color: #339933;">=</span> cvQueryFrame<span style="color: #009900;">&#40;</span>video<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* calculate the delay between each frame and display video's FPS */</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%2.2f FPS<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> cvGetCaptureProperty<span style="color: #009900;">&#40;</span>video<span style="color: #339933;">,</span> CV_CAP_PROP_FPS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    delay <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">/</span>cvGetCaptureProperty<span style="color: #009900;">&#40;</span>video<span style="color: #339933;">,</span> CV_CAP_PROP_FPS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>frame<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/* show loaded frame */</span>
        cvShowImage<span style="color: #009900;">&#40;</span>window_name<span style="color: #339933;">,</span> frame<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* wait delay and check for the quit key */</span>
        key <span style="color: #339933;">=</span> cvWaitKey<span style="color: #009900;">&#40;</span>delay<span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">==</span><span style="color: #ff0000;">'q'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span>;
	<span style="color: #808080; font-style: italic;">/* load and check next frame*/</span>
        frame <span style="color: #339933;">=</span> cvQueryFrame<span style="color: #009900;">&#40;</span>video<span style="color: #009900;">&#41;</span>;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>frame<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;error loading frame.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* detect faces */</span>
        CvSeq <span style="color: #339933;">*</span>faces <span style="color: #339933;">=</span> cvHaarDetectObjects<span style="color: #009900;">&#40;</span>
            frame<span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* image to detect objects in */</span>
            cascade<span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* haar classifier cascade */</span>
            storage<span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* resultant sequence of the object candidate rectangles */</span>
            <span style="color:#800080;">1.1</span><span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* increse window by 10% between the subsequent scans*/</span>
            <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* 3 neighbors makes up an object */</span>
            <span style="color:#800080;">0</span> <span style="color: #808080; font-style: italic;">/* flags CV_HAAR_DO_CANNY_PRUNNING */</span><span style="color: #339933;">,</span>
            cvSize<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">40</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">40</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">/* for each face found, draw a red box */</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> i <span style="color: #339933;">=</span> <span style="color:#800080;">0</span> ; i <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span> faces <span style="color: #339933;">?</span> faces<span style="color: #339933;">-&gt;</span>total <span style="color: #339933;">:</span> <span style="color:#800080;">0</span> <span style="color: #009900;">&#41;</span> ; i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             CvRect <span style="color: #339933;">*</span>r <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> CvRect<span style="color: #339933;">*</span> <span style="color: #009900;">&#41;</span>cvGetSeqElem<span style="color: #009900;">&#40;</span> faces<span style="color: #339933;">,</span> i <span style="color: #009900;">&#41;</span>;
             cvRectangle<span style="color: #009900;">&#40;</span> frame<span style="color: #339933;">,</span>
                  cvPoint<span style="color: #009900;">&#40;</span> r<span style="color: #339933;">-&gt;</span>x<span style="color: #339933;">,</span> r<span style="color: #339933;">-&gt;</span>y <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                  cvPoint<span style="color: #009900;">&#40;</span> r<span style="color: #339933;">-&gt;</span>x <span style="color: #339933;">+</span> r<span style="color: #339933;">-&gt;</span>width<span style="color: #339933;">,</span> r<span style="color: #339933;">-&gt;</span>y <span style="color: #339933;">+</span> r<span style="color: #339933;">-&gt;</span>height <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                  CV_RGB<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span> <span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p><small>Yeah, I know the code needs a few adjustments. ¬¬</small></p>
<p>To compile it in a well configured OpenCV development environment:</p>
<blockquote><p>gcc faceplayer.c  -o faceplayer `pkg-config opencv &#8209;&#8209;libs &#8209;&#8209;cflags`</p></blockquote>
<p>To run it you have to put in the same directory of the binary the XML classifier (haarcascade_frontalface_alt.xml) that comes with OpenCV sources at OpenCV-2.0.0/data/haarcascades/. And so:</p>
<blockquote><p>./faceplayer video.avi</p></blockquote>
<p>The results I got so far is that it works well for faces but sometimes its also detects more than faces. And here a video of it working live.</p>
<p><center><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/es_O3c-Kc-Q&#038;hl=pt_BR&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/es_O3c-Kc-Q&#038;hl=pt_BR&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></center></p>
<p>A example of good result:</p>
<p style="text-align: center;"><img class="size-full wp-image-2988 aligncenter" title="rick roll face detection" src="http://silveiraneto.net/wp-content/uploads/2009/12/rickroll_face_detection.jpg" alt="rick roll face detection" width="400" height="240" /></p>
<p>A example of bad result:</p>
<p style="text-align: center;"><img src="http://silveiraneto.net/wp-content/uploads/2009/12/rickroll_face_detection_bad_result.jpg" alt="rick roll face detection bad result" title="rick roll face detection bad result" width="400" height="240" class="alignnone size-full wp-image-2991" /></p>
<p>Maybe with some adjustments it could performs even better. But was really easy to create it using OpenCV.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/12/01/simple-face-detection-player/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

