<?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>iXce's blog &#187; OpenCV</title>
	<atom:link href="http://guillaume.segu.in/blog/category/code/opencv/feed/" rel="self" type="application/rss+xml" />
	<link>http://guillaume.segu.in/blog</link>
	<description>Stuff that doesn’t matter</description>
	<lastBuildDate>Mon, 28 Feb 2011 22:28:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Debugging cvCanny on x86_64</title>
		<link>http://guillaume.segu.in/blog/code/178/debugging-cvcanny-on-x86_64/</link>
		<comments>http://guillaume.segu.in/blog/code/178/debugging-cvcanny-on-x86_64/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 22:45:47 +0000</pubDate>
		<dc:creator>iXce</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[canny]]></category>
		<category><![CDATA[cast]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[long]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://guillaume.segu.in/blog/?p=178</guid>
		<description><![CDATA[There&#8217;s an outstanding bug right now which makes that cvCanny edge detector function in OpenCV currently segfaults on x86_64 systems. This post is an open attempt to track my debugging process Bug encountered. I know it&#8217;s x86_64 specific since I ran the same code on an i686 machine a few hours ago (with a home [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s an <a href="https://code.ros.org/trac/opencv/ticket/157">outstanding bug</a> right now which makes that cvCanny edge detector function in OpenCV currently segfaults on x86_64 systems. This post is an open attempt to track my debugging process <img src='http://guillaume.segu.in/blog/wp-includes/images/smilies/smile.png' alt=':)' class='wp-smiley' /> </p>
<ul>
<li>Bug encountered. I know it&#8217;s x86_64 specific since I ran the same code on an i686 machine a few hours ago (with a home compiled OpenCV, though).</li>
<li>Googled it : found reports on both <a href="https://code.ros.org/trac/opencv/ticket/157">OpenCV</a> and <a href="https://bugzilla.redhat.com/show_bug.cgi?id=531695">RedHat</a> bugtrackers.</li>
<li>Installed debug symbols, ran under gdb : all values I may need are optimized out.</li>
<li>Fetched OpenCV source, compiled it in debug mode.</li>
<li>CvCanny works great in debug mode.</li>
<li>Recompiled in release (optimized) mode to check if it is a distro-specific bug (both reports are from Fedora users).</li>
<li>Woha, release mode compilation is so slow <img src='http://guillaume.segu.in/blog/wp-includes/images/smilies/sad.png' alt=':(' class='wp-smiley' />  But bug confirmed&nbsp;: it segfaults again. Time to instrument the code.</li>
<li>Filled cvCanny function with printfs and fflushs to track the function execution. Looks like it tries to access an element at index -514. Hugh. What&#8217;s even more frightening is that it <em>successfully</em> achieves that on another array.</li>
<li>After running the same instrumented code on my i686 machine, it appears that the indexes are right and that the same indexes are accessed without any problem in optimized mode in the i686 build.</li>
<li>Reading the code tells me that the accesses at negative indexes are legit since the array origin is shifted from the actual allocated memory blob start. Well, that&#8217;s good, since it explains why it works well in debug mode or on i686 setups, but that&#8217;s pretty bad because it&#8217;s going to be awful to narrow down.</li>
<li>Ok, doing the access by hand (i.e. doing _map[-514] instead of _map[j - mapstep]) works. This is getting crazy. Doing k = j &#8211; mapstep and accessing _map[k] segfaults as well. Huh.</li>
<li>After an hour of heavy fprintfs, I figured that long k = j &#8211; mapstep; gave me a k which wasn&#8217;t the int value (-514) but rather the unsigned int value (4294966782), while doing int k = -514; long k2 = k; printf (&#8220;%d %ld\n&#8221;, k, k2); in a very simple code gives out -514 -514, even with -O3 or -O5 and all the options used for OpenCV release build. Since we are working with 64 bits pointers (i.e. of the size of long integers), this is probably the issue&nbsp;: when accessing _map[k], it unreferences the value at _map + k, which fails since it unreferences _map + 4294966782 instead of _map &#8211; 514.</li>
<li>Doing volatile int k = j &#8211; mapstep; and accessing _map[k] works, and cvCanny runs great now. Though this isn&#8217;t a real fix, just a workaround. There&#8217;s most likely a compiler bug underneath.</li>
<li>Posted a summary of my findings and the workaround on the bug report on the OpenCV tracker.</li>
</ul>
<p>Patch against latest svn (it should apply nicely to the 2.0.0 release as well)&nbsp;:</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">Index: cvcanny.cpp
===================================================================
<span style="color: #888822;">--- cvcanny.cpp	<span style="">&#40;</span>révision 2908<span style="">&#41;</span></span>
<span style="color: #888822;">+++ cvcanny.cpp	<span style="">&#40;</span>copie de travail<span style="">&#41;</span></span>
<span style="color: #440088;">@@ -239,7 +239,8 @@</span>
                 <span style="">&#123;</span>
                     if<span style="">&#40;</span> m &gt; _mag<span style="">&#91;</span>j-<span style="">1</span><span style="">&#93;</span> &amp;&amp; m &gt;= _mag<span style="">&#91;</span>j+<span style="">1</span><span style="">&#93;</span> <span style="">&#41;</span>
                     <span style="">&#123;</span>
<span style="color: #991111;">-                        if<span style="">&#40;</span> m &gt; high &amp;&amp; !prev_flag &amp;&amp; _map<span style="">&#91;</span>j-mapstep<span style="">&#93;</span> != 2 <span style="">&#41;</span></span>
<span style="color: #00b000;">+                        volatile int k = j - mapstep;</span>
<span style="color: #00b000;">+                        if<span style="">&#40;</span> m &gt; high &amp;&amp; !prev_flag &amp;&amp; _map<span style="">&#91;</span>k<span style="">&#93;</span> != 2 <span style="">&#41;</span></span>
                         <span style="">&#123;</span>
                             CANNY_PUSH<span style="">&#40;</span> _map + j <span style="">&#41;</span>;
                             prev_flag = <span style="">1</span>;
<span style="color: #440088;">@@ -253,7 +254,8 @@</span>
                 <span style="">&#123;</span>
                     if<span style="">&#40;</span> m &gt; _mag<span style="">&#91;</span>j+magstep2<span style="">&#93;</span> &amp;&amp; m &gt;= _mag<span style="">&#91;</span>j+magstep1<span style="">&#93;</span> <span style="">&#41;</span>
                     <span style="">&#123;</span>
<span style="color: #991111;">-                        if<span style="">&#40;</span> m &gt; high &amp;&amp; !prev_flag &amp;&amp; _map<span style="">&#91;</span>j-mapstep<span style="">&#93;</span> != 2 <span style="">&#41;</span></span>
<span style="color: #00b000;">+                        volatile int k = j - mapstep;</span>
<span style="color: #00b000;">+                        if<span style="">&#40;</span> m &gt; high &amp;&amp; !prev_flag &amp;&amp; _map<span style="">&#91;</span>k<span style="">&#93;</span> != 2 <span style="">&#41;</span></span>
                         <span style="">&#123;</span>
                             CANNY_PUSH<span style="">&#40;</span> _map + j <span style="">&#41;</span>;
                             prev_flag = <span style="">1</span>;
<span style="color: #440088;">@@ -268,7 +270,8 @@</span>
                     s = s &lt; <span style="">0</span> ? -<span style="">1</span> : <span style="">1</span>;
                     if<span style="">&#40;</span> m &gt; _mag<span style="">&#91;</span>j+magstep2-s<span style="">&#93;</span> &amp;&amp; m &gt; _mag<span style="">&#91;</span>j+magstep1+s<span style="">&#93;</span> <span style="">&#41;</span>
                     <span style="">&#123;</span>
<span style="color: #991111;">-                        if<span style="">&#40;</span> m &gt; high &amp;&amp; !prev_flag &amp;&amp; _map<span style="">&#91;</span>j-mapstep<span style="">&#93;</span> != 2 <span style="">&#41;</span></span>
<span style="color: #00b000;">+                        volatile int k = j - mapstep;</span>
<span style="color: #00b000;">+                        if<span style="">&#40;</span> m &gt; high &amp;&amp; !prev_flag &amp;&amp; _map<span style="">&#91;</span>k<span style="">&#93;</span> != 2 <span style="">&#41;</span></span>
                         <span style="">&#123;</span>
                             CANNY_PUSH<span style="">&#40;</span> _map + j <span style="">&#41;</span>;
                             prev_flag = <span style="">1</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://guillaume.segu.in/blog/code/178/debugging-cvcanny-on-x86_64/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rant of the day : OpenCV-python 2.0 package on Fedora 13</title>
		<link>http://guillaume.segu.in/blog/code/175/rant-of-the-day-opencv-python-2-0-package-on-fedora-13/</link>
		<comments>http://guillaume.segu.in/blog/code/175/rant-of-the-day-opencv-python-2-0-package-on-fedora-13/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 00:46:08 +0000</pubDate>
		<dc:creator>iXce</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[fedora 13]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://guillaume.segu.in/blog/?p=175</guid>
		<description><![CDATA[Today I&#8217;ve been looking at opencv-python for a quick project (I&#8217;d like to practice OpenCV a little bit). Installed the opencv-python package on Fedora 13, headed to the samples directory (/usr/share/opencv/samples/python/), started running one of them and&#8230; boum, segfault. Tried another one (the inpainting one), and it worked. A third one&#8230; segfault. Most of the [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve been looking at <a href="http://opencv.willowgarage.com/documentation/python/index.html">opencv-python</a> for a quick project (I&#8217;d like to practice OpenCV a little bit). Installed the opencv-python package on Fedora 13, headed to the samples directory (/usr/share/opencv/samples/python/), started running one of them and&#8230; boum, segfault. Tried another one (the inpainting one), and it worked. A third one&#8230; segfault. Most of the samples in there segfaulted, mostly with SWIG errors about wrong parameters, always mentioning int64 (I&#8217;m using a x86_64 kernel &#038; distribution).</p>
<p>After half an hour of failure on trying to get opencv.i686 work alongside my x86_64 python, I went back to the OpenCV website to check if there was some known heavy problems with x86_64 systems and&#8230; I discovered that&nbsp;:</p>
<blockquote><p>Starting with release 2.0, OpenCV has a new Python interface. (The previous Python interface is described in SwigPythonInterface.)</p></blockquote>
<p>Wait wait wait, you mean that during all this time I was running the OLD, pre-2.0 Python interface&nbsp;? Why the hell does the opencv-python 2.0 package provides both the new and the old interfaces&nbsp;? (well, I know the answer : backwards compatibility). Meh <img src='http://guillaume.segu.in/blog/wp-includes/images/smilies/sad.png' alt=':(' class='wp-smiley' />  Anyway, I wish the old samples would get ported to the new interface&#8230; At the moment there&#8217;s no sample using it at all&nbsp;:/</p>
]]></content:encoded>
			<wfw:commentRss>http://guillaume.segu.in/blog/code/175/rant-of-the-day-opencv-python-2-0-package-on-fedora-13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

