<?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; Computer Vision</title>
	<atom:link href="http://silveiraneto.net/tag/computer-vision/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: 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>
	</channel>
</rss>

