<?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; universe</title>
	<atom:link href="http://silveiraneto.net/tag/universe/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Mon, 19 Jul 2010 21:59:29 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</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>0</slash:comments>
		</item>
	</channel>
</rss>
