<?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>Elegant Code &#187; openCV</title>
	<atom:link href="http://elegantcode.com/tag/opencv/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +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 cvLoadImage IOError</title>
	<atom:link href="http://elegantcode.com/tag/opencv/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +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>Elegant Code &#187; openCV</title>
	<atom:link href="http://elegantcode.com/tag/opencv/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +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 cvLoadImage IOError</title>
		<link>http://elegantcode.com/2009/12/03/opencv-cvloadimage-ioerror/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=opencv-cvloadimage-ioerror</link>
		<comments>http://elegantcode.com/2009/12/03/opencv-cvloadimage-ioerror/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 16:31:26 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[openCV]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/12/03/opencv-cvloadimage-ioerror/</guid>
		<description><![CDATA[I’ve been working on a project that involves computer vision algorithms.&#160; Fortunately, really smart people have done all the hard work and produced OpenCV.&#160; Even better, there are a set of Python bindings, which makes a big difference because my project is written using Python. The bad news:&#160; I’m writing this on a Windows box [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been working on a project that involves computer vision algorithms.&#160; Fortunately, really smart people have done all the hard work and produced <a href="http://opencv.willowgarage.com/wiki/" target="_blank">OpenCV</a>.&#160; Even better, there are a set of Python bindings, which makes a big difference because my project is written using Python.</p>  <p>The bad news:&#160; I’m writing this on a Windows box and support for some things is sketchy or just non-existent.&#160; Also, using Python vs. this C library puts a big distance between “what you think is happening” and “what is happening,” so debugging leaves you wondering if the problem is your code, Eclipse somehow messing things up, Python, the Python bindings, somewhere within openCV, or just broken or incomplete support for Windows.</p>  <p>So imagine my confusion when this simple program:</p>  <pre class="csharpcode">import cv
img = cv.LoadImage(<span class="str">&quot;img.tif&quot;</span>)</pre>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>Generates <span class="csharpcode">IOError: [Errno 2] No such file or directory: 'img.tif'</span>

<p>I mean, what’s simpler than just loading a file from disk?!&#160; </p>

<p>I found many people reporting this error, but no solutions other than “The file or directory doesn’t exist or isn’t readable…”</p>

<p>So, after checking (and rechecking) that the file does indeed exist, and then after using the full path to the file and getting the same error, I tried to find where the error was originating through all these layers.</p>

<p>I tried opening the image file using <a href="http://www.pythonware.com/products/pil/" target="_blank">PIL</a> and then converting the image over to OpenCV format, which did not generate an error, except that the resulting image wouldn’t quite survive the process – so I guess that doesn’t count as “working.”&#160; Displaying the image using Windows Photo Viewer worked fine.&#160; Out of desperation I grabbed a random image off of the Internet and tried to open it with OpenCV --- and it worked.</p>

<p>Hmm, where did my original images come from?&#160; I screen-grabbed them off of another application, and then to save time - rather than waiting for Gimp to open - I just used MSPAINT.EXE to … oh, damn.&#160; “Short Cuts make for Long Journeys.”&#160; The original file was corrupt, just enough so that openCV would be unable to load it, but not so much that other programs and libs couldn’t load “something.”</p>

<p>So, <em>ignore the text of that error message </em>and read it as “openCV, for some reason that it won’t describe, could not load your image.&#160; Maybe the file is not there, or maybe you messed it up by being sloppy?”&#160; </p>

<p>Re-capturing the image using Gimp and PNG fixed the problem.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/12/03/opencv-cvloadimage-ioerror/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

