<?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>depth first search &#187; opencv</title>
	<atom:link href="http://www.depthfirstsearch.net/blog/tag/opencv/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.depthfirstsearch.net/blog</link>
	<description>“We can only see a short distance ahead, but we can see plenty there that needs to be done.&#34;</description>
	<lastBuildDate>Fri, 03 Feb 2012 04:22:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>OpenCV and Bumblebee2 Stereo</title>
		<link>http://www.depthfirstsearch.net/blog/2009/06/18/opencv-and-bumblebee2-stereo/</link>
		<comments>http://www.depthfirstsearch.net/blog/2009/06/18/opencv-and-bumblebee2-stereo/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 18:34:31 +0000</pubDate>
		<dc:creator>JS</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[vision]]></category>

		<guid isPermaLink="false">http://www.depthfirstsearch.net/blog/?p=1213</guid>
		<description><![CDATA[Well, I just finished adding support for a Bumblebee2 camera to OpenCV. I wish I could give the code away, but it depends on Triclops, Point Grey&#8217;s proprietary library and I don&#8217;t really know how to submit a patch to OpenCV anyway. For those of you who are interested in accessing stereo vision capabilities for [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I just finished adding support for a Bumblebee2 camera to OpenCV. I wish I could give the code away, but it depends on Triclops, Point Grey&#8217;s proprietary library and I don&#8217;t really know how to submit a patch to OpenCV anyway. For those of you who are interested in accessing stereo vision capabilities for this type of camera through OpenCV, let me know and I can send you some patches or point you in the right direction.</p>
<p>The main useful source of information turned out to be this <a href="http://image.diku.dk/mediawiki/index.php?title=BumbleBee&amp;printable=yes">wiki</a> on how to setup the Triclops library and the more important libpgrlibdcstereo. The latter is distributed with examples for reading right and left stereo channels using the library and computing disparities, which formed the basis for my OpenCV code. I followed the structure of cvcap*.cpp code and used calls to pgrstereolib to actually perform the capture.</p>
<p>[I noticed that support for Videre stereo cameras was already included. I suppose that must be what they use at Willow Garage. I was able to read from my Bumblebee2 camera without any code changes, but could not figure out how to access the channels separately or compute disparities.]</p>
<p>The tricky part is getting everything into OpenCV. This required adding a small number of carefully placed lines of code to the CMake files and a small number of careful #defines in the highgui source. The project is mature enough, and the patterns consistent enough, that doing so really just meant looking for how other&#8217;s did it for other, similar features.</p>
<p>ASIDE: For some weird reason libpgrlibstereo comes with an LGPL license, which might be compatible with OpenCV, but makes calls to Triclops, which doesn&#8217;t seem to have any license other than &#8220;you bought our very expensive camera so you get this library.&#8221; That, as I understand things, sort of nullifies the use of libpgrlibstereo in any setting where we would normally like to use LGPL library code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.depthfirstsearch.net/blog/2009/06/18/opencv-and-bumblebee2-stereo/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Weird Compiler Error of the Day</title>
		<link>http://www.depthfirstsearch.net/blog/2009/06/17/weird-compiler-error-of-the-day/</link>
		<comments>http://www.depthfirstsearch.net/blog/2009/06/17/weird-compiler-error-of-the-day/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 17:23:54 +0000</pubDate>
		<dc:creator>JS</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.depthfirstsearch.net/blog/?p=1202</guid>
		<description><![CDATA[I got the following error when trying to compile the latest svn version of opencv: error: invalid controlling predicate A quick Google search yielded this gem of a compiler bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38650. The offending loop: #ifdef _OPENMP #pragma omp for schedule(static, 1) #endif /* _OPENMP */ for&#40; i = first; &#40;i &#60; first + count&#41; &#38;&#38; [...]]]></description>
			<content:encoded><![CDATA[<p>I got the following error when trying to compile the latest svn version of opencv:</p>
<blockquote><p>error: invalid controlling predicate</p></blockquote>
<p>A quick Google search yielded this gem of a compiler bug: <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38650">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38650</a>.</p>
<p>The offending loop:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifdef _OPENMP</span>
<span style="color: #339933;">#pragma omp for schedule(static, 1)</span>
<span style="color: #339933;">#endif /* _OPENMP */</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> i <span style="color: #339933;">=</span> first<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> first <span style="color: #339933;">+</span> count<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> next<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span></pre></div></div>

<p>That is all.</p>
<p>UPDATE: Turns out I was using a stale configuration file from svn for this build. It seems like OpenCV has entirely too many build systems. They should ditch autoconf and go with cmake exclusively.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.depthfirstsearch.net/blog/2009/06/17/weird-compiler-error-of-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenCV and Python</title>
		<link>http://www.depthfirstsearch.net/blog/2008/09/22/opencv-and-python/</link>
		<comments>http://www.depthfirstsearch.net/blog/2008/09/22/opencv-and-python/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 20:04:34 +0000</pubDate>
		<dc:creator>JS</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[opencv]]></category>

		<guid isPermaLink="false">http://www.depthfirstsearch.net/blog/?p=595</guid>
		<description><![CDATA[You may have come across the following issue with OpenCV Python bindings: image = cv.cvCreateImage&#40;size, cv.IPL_DEPTH_8U, 3&#41; image.imageData = data # set some data Trying to set the &#8220;data&#8221; of an OpenCV image directly fails. The problem is in the underlying SWIG code that attempts to make the imageData field available for writing at the [...]]]></description>
			<content:encoded><![CDATA[<p>You may have come across the following issue with OpenCV Python bindings:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">image = cv.<span style="color: black;">cvCreateImage</span><span style="color: black;">&#40;</span>size, cv.<span style="color: black;">IPL_DEPTH_8U</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>
image.<span style="color: black;">imageData</span> = data <span style="color: #808080; font-style: italic;"># set some data</span></pre></div></div>

<p>Trying to set the &#8220;data&#8221; of an OpenCV image directly fails. The problem is in the underlying SWIG code that attempts to make the imageData field available for writing at the python level. You can see in <a href="http://opencvlibrary.cvs.sourceforge.net/opencvlibrary/opencv/interfaces/swig/python/imagedata.i?r1=1.3&amp;r2=1.4">CVS</a> that the code gets fixed <strong>immediately after</strong> the 1.0 release.</p>
<p>But wait! Doesn&#8217;t OpenCV come with an adaptors.py that is supposed to provide methods for translating between various Python data types (NumPy &lt; =&gt; PIL &lt; =&gt; IplImage) ?</p>
<p>A quick look at the code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> PIL2Ipl<span style="color: black;">&#40;</span><span style="color: #008000;">input</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Converts a PIL image to the OpenCV/IPL CvMat data format.
&nbsp;
    Supported input image formats are:
        RGB
        L
        F
    &quot;&quot;&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span>, PIL.<span style="color: black;">Image</span>.<span style="color: black;">Image</span><span style="color: black;">&#41;</span>:
       <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">TypeError</span>, <span style="color: #483d8b;">'must be called with PIL.Image.Image!'</span>
&nbsp;
    size = cv.<span style="color: black;">cvSize</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span>.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #008000;">input</span>.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># mode dictionary:</span>
    <span style="color: #808080; font-style: italic;"># (pil_mode : (ipl_depth, ipl_channels, color model, channel Seq)</span>
    mode_list = <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">&quot;RGB&quot;</span> : <span style="color: black;">&#40;</span>cv.<span style="color: black;">IPL_DEPTH_8U</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>,
        <span style="color: #483d8b;">&quot;L&quot;</span>   : <span style="color: black;">&#40;</span>cv.<span style="color: black;">IPL_DEPTH_8U</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>,
        <span style="color: #483d8b;">&quot;F&quot;</span>   : <span style="color: black;">&#40;</span>cv.<span style="color: black;">IPL_DEPTH_32F</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
        <span style="color: black;">&#125;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> mode_list.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span>.<span style="color: black;">mode</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">ValueError</span>, <span style="color: #483d8b;">'unknown or unsupported input mode'</span>
&nbsp;
    modes = mode_list<span style="color: black;">&#91;</span><span style="color: #008000;">input</span>.<span style="color: black;">mode</span><span style="color: black;">&#93;</span>
&nbsp;
    result = cv.<span style="color: black;">cvCreateImage</span><span style="color: black;">&#40;</span>
        size,
        modes<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #808080; font-style: italic;"># depth</span>
        modes<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>  <span style="color: #808080; font-style: italic;"># channels</span>
        <span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># set imageData</span>
    result.<span style="color: black;">imageData</span>=<span style="color: #008000;">input</span>.<span style="color: black;">tostring</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#FAIL!</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> result</pre></div></div>

<p>As you can see, adaptors.py tries to set imageData as well, and so fails to convert from any format into IplImage. Your options are to work from the repository version of OpenCV or to back port the change from the repository to your local installation. Both require compiling from source and so as you may imagine, neither case is convenient when working with libcv as installed from your favorite package manager of choice.</p>
<p>A third option is to back port the changes from the repository to your own custom swig module whose only goal is to implement a function that sets the imageData field properly. That&#8217;s the approach I took, and though it took a considerable amount of time to implement (because I don&#8217;t really understand SWIG), the end result did not require many lines of code. Here&#8217;s my iplimage.i file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>module iplimage
<span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>
<span style="color: #339933;">#include &quot;cv.h&quot;</span>
<span style="color: #993333;">void</span> set<span style="color: #009900;">&#40;</span>CvMat <span style="color: #339933;">*</span>self<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>string<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> set<span style="color: #009900;">&#40;</span>CvMat <span style="color: #339933;">*</span>self<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>string<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And here&#8217;s iplimage.c copied with minor changes directly out of the repository for OpenCV:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;cv.h&quot;</span>
&nbsp;
<span style="color: #993333;">void</span> set<span style="color: #009900;">&#40;</span>CvMat <span style="color: #339933;">*</span> self<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>string<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> depth <span style="color: #339933;">=</span> CV_MAT_DEPTH<span style="color: #009900;">&#40;</span>self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>type<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> cn <span style="color: #339933;">=</span> CV_MAT_CN<span style="color: #009900;">&#40;</span>self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>type<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> step <span style="color: #339933;">=</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>step <span style="color: #339933;">?</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>step <span style="color: #339933;">:</span> CV_ELEM_SIZE<span style="color: #009900;">&#40;</span>self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>type<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>cols<span style="color: #339933;">;</span>
	<span style="color: #993333;">long</span> line<span style="color: #339933;">;</span>
	<span style="color: #993333;">long</span> pixel<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>depth <span style="color: #339933;">==</span> CV_8U <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> cn<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: #666666; font-style: italic;">// RGB case</span>
		<span style="color: #666666; font-style: italic;">// The data is reordered beause OpenCV uses BGR instead of RGB</span>
&nbsp;
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> line <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>rows<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>line<span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>pixel <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> pixel <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>cols<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>pixel<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// In OpenCV the beginning of the lines are aligned</span>
				<span style="color: #666666; font-style: italic;">// to 4 Bytes. So use step instead of cols.</span>
				<span style="color: #993333;">long</span> position <span style="color: #339933;">=</span> line<span style="color: #339933;">*</span>step <span style="color: #339933;">+</span> pixel<span style="color: #339933;">*</span><span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
				<span style="color: #993333;">long</span> sourcepos <span style="color: #339933;">=</span> line<span style="color: #339933;">*</span>self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>cols<span style="color: #339933;">*</span><span style="color: #0000dd;">3</span> <span style="color: #339933;">+</span> pixel<span style="color: #339933;">*</span><span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
				self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data.<span style="color: #202020;">ptr</span><span style="color: #009900;">&#91;</span>position  <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> string<span style="color: #009900;">&#91;</span>sourcepos<span style="color: #339933;">+</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data.<span style="color: #202020;">ptr</span><span style="color: #009900;">&#91;</span>position<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> string<span style="color: #009900;">&#91;</span>sourcepos<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data.<span style="color: #202020;">ptr</span><span style="color: #009900;">&#91;</span>position<span style="color: #339933;">+</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> string<span style="color: #009900;">&#91;</span>sourcepos  <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>depth <span style="color: #339933;">==</span> CV_8U <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> cn<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Grayscale 8bit case</span>
&nbsp;
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> line <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>rows<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>line<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// In OpenCV the beginning of the lines are aligned</span>
			<span style="color: #666666; font-style: italic;">// to 4 Bytes. So use step instead of cols.</span>
			memcpy
				<span style="color: #009900;">&#40;</span>
				 self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data.<span style="color: #202020;">ptr</span> <span style="color: #339933;">+</span> line<span style="color: #339933;">*</span>step<span style="color: #339933;">,</span>
				 string <span style="color: #339933;">+</span> line<span style="color: #339933;">*</span>self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>cols<span style="color: #339933;">,</span>
				 step
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> depth <span style="color: #339933;">==</span> CV_32F <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// float (32bit) case</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> line <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>rows<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>line<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// here we don not have to care about alignment as the Floats are</span>
			<span style="color: #666666; font-style: italic;">// as long as the alignment</span>
			memcpy
				<span style="color: #009900;">&#40;</span>
				 self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data.<span style="color: #202020;">ptr</span> <span style="color: #339933;">+</span> line<span style="color: #339933;">*</span>step<span style="color: #339933;">,</span>
				 string <span style="color: #339933;">+</span> line<span style="color: #339933;">*</span>self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>cols<span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				 step
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> depth <span style="color: #339933;">==</span> CV_64F <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// double (64bit) case</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> line <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>rows<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>line<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// here we don not have to care about alignment as the Floats are</span>
			<span style="color: #666666; font-style: italic;">// as long as the alignment</span>
			memcpy
				<span style="color: #009900;">&#40;</span>
				 self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data.<span style="color: #202020;">ptr</span> <span style="color: #339933;">+</span> line<span style="color: #339933;">*</span>step<span style="color: #339933;">,</span>
				 string <span style="color: #339933;">+</span> line<span style="color: #339933;">*</span>self<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>cols<span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				 step
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>An example makefile that works on my system:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">CFLAGS</span>= <span style="color: #000000; font-weight: bold;">`</span>pkg-config <span style="color: #660033;">--cflags</span> opencv<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">LDFLAGS</span>= <span style="color: #000000; font-weight: bold;">`</span>pkg-config <span style="color: #660033;">--libs</span> opencv<span style="color: #000000; font-weight: bold;">`</span> -L.
<span style="color: #007800;">CXX</span>=<span style="color: #c20cb9; font-weight: bold;">g++</span>
&nbsp;
_iplimage.so: iplimage.c
	swig <span style="color: #660033;">-python</span> iplimage.i
	$<span style="color: #7a0874; font-weight: bold;">&#40;</span>CXX<span style="color: #7a0874; font-weight: bold;">&#41;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>CFLAGS<span style="color: #7a0874; font-weight: bold;">&#41;</span> -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>python2.5 <span style="color: #660033;">-c</span> iplimage.c iplimage_wrap.c
	$<span style="color: #7a0874; font-weight: bold;">&#40;</span>CXX<span style="color: #7a0874; font-weight: bold;">&#41;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>LDFLAGS<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-shared</span> iplimage.o iplimage_wrap.o <span style="color: #660033;">-o</span> _iplimage.so</pre></div></div>

<p>If you manage to build the module, you can then invoke it from python using a call to <em>iplimage.set(image,data)</em> to set the imageData field for real. You can use the default OpenCV Python bindings that come with your package manager and simply install this small additional module. Hopefully, we&#8217;ll see a new release of OpenCV soon that negates the need for any of these acrobatics.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.depthfirstsearch.net/blog/2008/09/22/opencv-and-python/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>My First SWIG Experience</title>
		<link>http://www.depthfirstsearch.net/blog/2008/07/11/my-first-swig-experience/</link>
		<comments>http://www.depthfirstsearch.net/blog/2008/07/11/my-first-swig-experience/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 22:27:14 +0000</pubDate>
		<dc:creator>JS</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[swig]]></category>

		<guid isPermaLink="false">http://www.depthfirstsearch.net/blog/?p=486</guid>
		<description><![CDATA[A day of reading the SWIG manual and grokking the examples resulted in the following interface file. What does it do? It adds this to Python. %module blobs &#160; %exception &#123; try &#123; $action &#125; catch &#40;...&#41; &#123; return NULL; &#125; &#125; &#160; &#160; %include &#34;exception.i&#34; &#160; %typemap&#40;in&#41; IplImage * &#40;IplImage header&#41;&#123; void * vptr; [...]]]></description>
			<content:encoded><![CDATA[<p>A day of reading the SWIG manual and grokking the examples resulted in the following interface file. What does it do? It adds <a href="http://opencvlibrary.sourceforge.net/cvBlobsLib">this</a> to Python.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #000040;">%</span>module blobs
&nbsp;
<span style="color: #000040;">%</span>exception
    <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">try</span> <span style="color: #008000;">&#123;</span> $action <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span>...<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000040;">%</span>include <span style="color: #FF0000;">&quot;exception.i&quot;</span>
&nbsp;
<span style="color: #000040;">%</span>typemap<span style="color: #008000;">&#40;</span>in<span style="color: #008000;">&#41;</span> IplImage <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span>IplImage header<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> vptr<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> res <span style="color: #000080;">=</span> SWIG_ConvertPtr<span style="color: #008000;">&#40;</span>$input, <span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>vptr<span style="color: #008000;">&#41;</span>, $descriptor<span style="color: #008000;">&#40;</span> CvMat <span style="color: #000040;">*</span> <span style="color: #008000;">&#41;</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> res <span style="color: #000080;">==</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
		SWIG_exception<span style="color: #008000;">&#40;</span> SWIG_TypeError, <span style="color: #FF0000;">&quot;%%typemap(in) IplImage * : could not convert to CvMat&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		SWIG_fail<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	$<span style="color:#800080;">1</span> <span style="color: #000080;">=</span> cvGetImage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>CvMat <span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>vptr, <span style="color: #000040;">&amp;</span>header<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #000040;">%</span>typemap<span style="color: #008000;">&#40;</span>in<span style="color: #008000;">&#41;</span> IplImage <span style="color: #000040;">*</span>mask<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>$input <span style="color: #000080;">==</span> Py_None<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	   $<span style="color:#800080;">1</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		SWIG_exception<span style="color: #008000;">&#40;</span> SWIG_TypeError, <span style="color: #FF0000;">&quot;%%typemap(in) IplImage *mask : masks not supported yet.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		SWIG_fail<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #000040;">%</span>typecheck<span style="color: #008000;">&#40;</span>SWIG_TYPECHECK_POINTER<span style="color: #008000;">&#41;</span> IplImage <span style="color: #000040;">*</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span>ptr<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>SWIG_ConvertPtr<span style="color: #008000;">&#40;</span>$input, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span> <span style="color: #000040;">**</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>ptr, $descriptor<span style="color: #008000;">&#40;</span> CvMat <span style="color: #000040;">*</span> <span style="color: #008000;">&#41;</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    $<span style="color:#800080;">1</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    PyErr_Clear<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
    $<span style="color:#800080;">1</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #000040;">%</span><span style="color: #008000;">&#123;</span>
<span style="color: #339900;">#include &quot;BlobResult.h&quot;</span>
<span style="color: #339900;">#include &quot;Blob.h&quot;</span>
<span style="color: #000040;">%</span><span style="color: #008000;">&#125;</span>
<span style="color: #000040;">%</span>include <span style="color: #FF0000;">&quot;BlobResult.h&quot;</span>
<span style="color: #000040;">%</span>include <span style="color: #FF0000;">&quot;Blob.h&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.depthfirstsearch.net/blog/2008/07/11/my-first-swig-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/21 queries in 0.652 seconds using disk: basic
Object Caching 450/494 objects using disk: basic

Served from: www.depthfirstsearch.net @ 2012-02-05 06:10:59 -->
