<?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>Damiles</title>
	<atom:link href="http://blog.damiles.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.damiles.com</link>
	<description>Blender, OpenCV, OpenCV, Tutorials and more...</description>
	<lastBuildDate>Mon, 26 Dec 2011 09:45: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>Removing .svn folders from project</title>
		<link>http://blog.damiles.com/2011/06/removing-svn-folders-from-project/</link>
		<comments>http://blog.damiles.com/2011/06/removing-svn-folders-from-project/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 16:49:27 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[other]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=314</guid>
		<description><![CDATA[A loft of times some people send me project with subversion, and when you  upload to production, sometime you don&#8217;t want upload .svn folder, looking for in google i found this. A good miracle command for me XD, and sure a stupid command for a lot of people. rsync -r &#8211;exclude=.svn /home/user/progname/ /home/user/progname.copy Regards David.]]></description>
			<content:encoded><![CDATA[<p>A loft of times some people send me project with subversion, and when you  upload to production, sometime you don&#8217;t want upload .svn folder, looking for in google i found this. A good miracle command for me XD, and sure a stupid command for a lot of people.</p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">rsync -r &#8211;exclude=.svn /home/user/progname/ /home/user/progname.copy</span></p>
<p>Regards David.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2011/06/removing-svn-folders-from-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Segmentation and feature extraction. Contours and blob detection.</title>
		<link>http://blog.damiles.com/2010/12/segmentation-and-feature-extraction-contours-and-blob-detection/</link>
		<comments>http://blog.damiles.com/2010/12/segmentation-and-feature-extraction-contours-and-blob-detection/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 15:14:45 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=292</guid>
		<description><![CDATA[In BasiOCR tutorial i explain  how to preprocess, extract features and clasify a handwritten number, and a lot of people ask me how to segment an image where contains several numbers or objects. In this tutorial I want explain how to segment an image and detect each object inside image, in this tutorial we can [...]]]></description>
			<content:encoded><![CDATA[<p>In BasiOCR tutorial i explain  how to preprocess, extract features and clasify a handwritten number, and a lot of people ask me how to segment an image where contains several numbers or objects.</p>
<p>In this tutorial I want explain how to segment an image and detect each object inside image, in this tutorial we can detect objects from plate (the numbers) or each object draw into a paper.</p>
<p><a href="http://blog.damiles.com/wp-content/uploads//2010/12/result.jpg"><img class="aligncenter size-full wp-image-295" title="result" src="http://blog.damiles.com/wp-content/uploads//2010/12/result.jpg" alt="" width="434" height="127" /></a><span id="more-292"></span></p>
<p>We can define three steps to do this task: preprocess image, find countours, and calculate bounding rect. With this three steps we have each object separatly and then we can use each object to classify it with basicocr sample.</p>
<p>For preprocessing task we use:</p>
<ol>
<li>Smooth filter to simple noise elimination.</li>
<li>Threshold image to get binary image</li>
<li>Morphologic filter, erode and dilate to eliminate noise.</li>
</ol>
<p><a href="http://blog.damiles.com//wp-content/uploads/2010/12/preprocess_seg.png"><img title="preprocess segmentation" src="http://blog.damiles.com//wp-content/uploads/2010/12/preprocess_seg.png" alt="" width="421" height="480" /></a></p>
<p>Once we have preprocessed our input image we look for the contours in our binary image with cvFindContours, and optimize its with approxpoly.</p>
<pre class="brush: cpp;">

//Search countours in preprocesed image
 cvFindContours( img_contornos, storage, &amp;contour, sizeof(CvContour),
 CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0) );
 //Optimize contours, reduce points
 contourLow=cvApproxPoly(contour, sizeof(CvContour), storage,CV_POLY_APPROX_DP,1,1);
</pre>
<p>Then for each searched contour we calculate the bounding rect.</p>
<pre class="brush: cpp;">

//For each contour found
 for( ; contourLow != 0; contourLow = contourLow-&gt;h_next )
 {

...

CvRect rect;

rect=cvBoundingRect(contourLow, NULL);
</pre>
<p>We can now draw his contour and/or bounding rect.</p>
<pre class="brush: cpp;">

pt1.x = rect.x;
 pt2.x = (rect.x+rect.width);
 pt1.y = rect.y;
 pt2.y = (rect.y+rect.height);
 cvRectangle(imagen_color, pt1,pt2, color, 1, 8, 0);
//or
cvDrawContours( imagen_color, contourLow, color, color, -1, 0, 8, cvPoint(0,0) );
</pre>
<p style="text-align: center;"><a href="http://blog.damiles.com/wp-content/uploads//2010/12/result1.png"><img class="aligncenter size-full wp-image-301" title="segmentation result" src="http://blog.damiles.com/wp-content/uploads//2010/12/result1.png" alt="" width="446" height="89" /></a></p>
<p>Now we have each object differenciate, now we can use this to get characteristics to classificate, for example  the 7 invariant hu moments.</p>
<pre class="brush: cpp;">

CvMoments moments;
CvHuMoments humoments;

//First calculate object moments
 cvMoments(contourLow, &amp;moments, 0);
 //Now calculate hu moments
 cvGetHuMoments(&amp;moments, &amp;humoments);
</pre>
<p><a class="downloadSource" href="http://www.artresnet.com/david/resource.jsp?f=16" target="_blank">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/12/segmentation-and-feature-extraction-contours-and-blob-detection/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>OpenCV and CMake</title>
		<link>http://blog.damiles.com/2010/09/opencv-and-cmake/</link>
		<comments>http://blog.damiles.com/2010/09/opencv-and-cmake/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 12:42:11 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[other]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CMake]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=286</guid>
		<description><![CDATA[From OpenCV 2.1 version we can use CMake to create and manage our OpenCV projects. CMake is a cross-platform and open-source build system, and it&#8217;s used to control our compilation process, using a simple text files for define compilation process with independent platform and compiler. Thanks to CMake we can create our project in our [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.damiles.com/wp-content/uploads//2010/09/opencvcmake.png"><img class="aligncenter size-full wp-image-308" title="opencvcmake" src="http://blog.damiles.com/wp-content/uploads//2010/09/opencvcmake.png" alt="" width="645" height="240" /></a>From OpenCV 2.1 version we can use CMake to create and manage our OpenCV projects.</p>
<p><a title="CMake" href="http://www.cmake.org/" target="_blank">CMake</a> is a cross-platform and open-source build system, and it&#8217;s used to control our compilation process, using a simple text files for define compilation process with independent platform and compiler.</p>
<p>Thanks to CMake we can create our project in our operating system as linux compile and work in it, and then use it to compile a new version in other os as windows, osx, &#8230;, even create a visual studio project, xcode project or eclipse.</p>
<p>To create a basic project with 1 main.c file with cmake and opencv we must create a new file called CMakeList.txt.<br />
<span id="more-286"></span><br />
In this file we go to define the compiler process and his requeriments.</p>
<p>First we need create a project name:</p>
<pre class="brush: cpp;">
PROJECT( project_name )
</pre>
<p>We need find OpenCV libraries. OpenCV is required by our project and it&#8217;s defined with REQUIRED statement:</p>
<pre class="brush: cpp;">
FIND_PACKAGE( OpenCV REQUIRED )
</pre>
<p>Then we must defined our executable, his  name and the dependent files, in our example only main.c, and we go to use the project name for the executable name. This name is stored in ${PROJECT_NAME} variable.</p>
<pre class="brush: cpp;">
ADD_EXECUTABLE( ${PROJECT_NAME} main.c )
</pre>
<p>To finish, we must link OpenCV to our executable, to do this only need call TARGET_LINK_LIBRARIES statement, with the project name and OpenCV library.</p>
<pre class="brush: cpp;">
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} {OpenCV_LIBS} )
</pre>
<p>The CMakeList.txt was defined, then we can compile our project. To do this only need create a directory where we want get our executable. Then  we call cmake with the directory where  CMakeList.txt and main.c files are saved.</p>
<p>When cmake finish whe can call make to compile our project under unix.</p>
<p>If we want create a VisualStudio project under Windows, only need open CMake Gui and select the source code and build directories and cmake detect our visualstudio version and with generate button create our VisualStudio project.</p>
<p>Sample Code:</p>
<pre class="brush: cpp;">
PROJECT( Nombre_del_proyecto )
FIND_PACKAGE( OpenCV REQUIRED )
ADD_EXECUTABLE( ${PROJECT_NAME} main.c )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} {OpenCV_LIBS} )
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/09/opencv-and-cmake/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CvFileStorage. How to save our custom structures with OpenCV functions</title>
		<link>http://blog.damiles.com/2010/02/cvfilestorage-how-to-save-our-custom-structures-with-opencv-functions/</link>
		<comments>http://blog.damiles.com/2010/02/cvfilestorage-how-to-save-our-custom-structures-with-opencv-functions/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 14:29:54 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=262</guid>
		<description><![CDATA[In this tutorial we go to show how to save our custom structures with opencv functions. We go to imagine we have this structure in our program. typedef struct { float var1; unsigned char var2[255]; }MyStructure; Opencv can save data in two formats: XML or YAML. This formats are markup languages. For write or read [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_311" class="wp-caption aligncenter" style="width: 655px"><a href="http://blog.damiles.com/wp-content/uploads//2010/02/opencvGeneric.png"><img class="size-full wp-image-311" title="opencvGeneric" src="http://blog.damiles.com/wp-content/uploads//2010/02/opencvGeneric.png" alt="OpenCV" width="645" height="240" /></a>
<p class="wp-caption-text">OpenCV</p>
</div>
<p>In this tutorial we go to show how to save our custom structures with opencv functions.</p>
<p>We go to imagine we have this structure in our program.<span id="more-262"></span></p>
<pre class="brush: cpp;">typedef struct
{
	float var1;
	unsigned char var2[255];
}MyStructure;</pre>
<p>Opencv can save data in two formats: XML or YAML. This formats are markup languages.</p>
<p>For write or read a file, we go to use cvOpenFileStorage function, the functions returns  a CvFileStorage structure pointer. This pointer we use to read or write values into.</p>
<p>We can open a file in two ways: for read or write. The function to open file is <a title="cvOpenFileStorage - OpenCV Wiki" href="http://opencv.willowgarage.com/documentation/xml/yaml_persistence.html?highlight=cvopenfilestorage#cvOpenFileStorage" target="_blank">cvOpenFileStorage</a></p>
<pre class="brush: cpp;">CvFileStorage* storage = cvOpenFileStorage( file, 0, CV_STORAGE_WRITE_TEXT );</pre>
<p>One time we have our CvFileStorage initialized then we can save our data. To save the data we need create Nodes. XML and YAML are markup languages, and they are defined with nodes.</p>
<p>First we go to create one node that contains all structure data. And inside of this node we need create one node for each variable.</p>
<p>For create a node we need open and close this node, as we do with xml, then we use <a href="http://opencv.willowgarage.com/documentation/xml/yaml_persistence.html#startwritestruct" target="_blank">cvStartWriteStruct</a> and <a href="http://opencv.willowgarage.com/documentation/xml/yaml_persistence.html#endwritestruct" target="_blank">cvEndWriteStruct</a>.</p>
<pre class="brush: cpp;">cvStartWriteStruct(storage, &quot;MyStructure&quot;, CV_NODE_MAP, NULL, cvAttrList(0,0));
...
cvEndWriteStruct(storage);</pre>
<p>Between the start and end node we go to insert each new node with asigned variable. The variable we must save as some of this types: int, raw (array), real or string with this functions:</p>
<ul>
<li><a href="http://opencv.willowgarage.com/documentation/xml/yaml_persistence.html#writeint" target="_blank"><tt>cvWriteInt</tt></a></li>
<li><a href="http://opencv.willowgarage.com/documentation/xml/yaml_persistence.html#writerawdata" target="_blank"><tt>cvWriteRawData</tt></a></li>
<li><a href="http://opencv.willowgarage.com/documentation/xml/yaml_persistence.html#writereal" target="_blank"><tt>cvWriteReal</tt></a></li>
<li><a href="http://opencv.willowgarage.com/documentation/xml/yaml_persistence.html#writestring" target="_blank"><tt>cvWriteString</tt></a></li>
</ul>
<p>Then for save our structure we go to create this code:</p>
<pre class="brush: cpp;">
//Open file
CvFileStorage* storage = cvOpenFileStorage( file, 0, CV_STORAGE_WRITE_TEXT );
//Create our node for structure
cvStartWriteStruct(storage, &quot;MyStructure&quot;, CV_NODE_MAP, NULL, cvAttrList(0,0));
//Write our float
cvWriteReal( storage, &quot;var1&quot;, MyStructure-&gt;var1 );

//Write our array
cvStartWriteStruct(storage, &quot;var2&quot;, CV_NODE_SEQ, NULL, cvAttrList(0,0));
cvWriteRawData(storage, MyStructure-&gt;var2,255,&quot;u&quot;);
cvEndWriteStruct(storage);

//End node structure
cvEndWriteStruct(storage);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/02/cvfilestorage-how-to-save-our-custom-structures-with-opencv-functions/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Pseudocolor implementation with OpenCV.</title>
		<link>http://blog.damiles.com/2010/01/pseudocolor-implementation-with-opencv/</link>
		<comments>http://blog.damiles.com/2010/01/pseudocolor-implementation-with-opencv/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 21:19:56 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cvFileNode]]></category>
		<category><![CDATA[cvWriteRawData]]></category>
		<category><![CDATA[HighGui]]></category>
		<category><![CDATA[Pseudocolor]]></category>
		<category><![CDATA[Save]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=244</guid>
		<description><![CDATA[In Computer Vision works in a lot of cases with gray images because there are a lot of motives. But human vision don&#8217;t perceives the gray levels so well as color levels. Then if we need show a image to a person, we can color it. But, how is the best way to coloring gray [...]]]></description>
			<content:encoded><![CDATA[<p>In Computer Vision works in a lot of cases with gray images because there are a lot of motives. But human vision don&#8217;t perceives the gray levels so well as color levels.</p>
<p>Then if we need show a image to a person, we can color it. But, how is the best way to coloring gray image?</p>
<p>There are 3 ways to do it: Manually, automatically and colored by ranges.</p>
<p>In this tutorial, i go to develop the way most common automatic for gray image coloring.</p>
<p>To do it we need know we go to receive a gray level and we need return 3 values, one for red, one for blue and other for green.</p>
<p>We go to use this function:</p>
<p><img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%7B%20s%28x%2Cy%29%3D%5Cvert%20sin%28r%28x%2Cy%29%2Ap%2API%20%2B%20%5CTheta%2API%29%5Cvert%7D&#038;bg=T&#038;fg=000000&#038;s=0' alt='\displaystyle{ s(x,y)=\vert sin(r(x,y)*p*PI + \Theta*PI)\vert}' title='\displaystyle{ s(x,y)=\vert sin(r(x,y)*p*PI + \Theta*PI)\vert}' class='latex' /></p>
<p>And r(x,y) is the gray level and p is the number of repetitions and <img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%7B%20%5CTheta%20%7D&#038;bg=T&#038;fg=000000&#038;s=0' alt='\displaystyle{ \Theta }' title='\displaystyle{ \Theta }' class='latex' /> is the displacement.</p>
<p>Then we only need define the p and <img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%7B%20%5CTheta%20%7D&#038;bg=T&#038;fg=000000&#038;s=0' alt='\displaystyle{ \Theta }' title='\displaystyle{ \Theta }' class='latex' /> for each channel.</p>
<p>If we create a plot with this function with this parameters for red, green and blue ((2,0),(2,-0.1),(2,-0.3)) we get:</p>
<div id="attachment_253" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.damiles.com/wp-content/uploads//2010/01/graph.gif"><img class="size-medium wp-image-253 " title="graph" src="http://blog.damiles.com/wp-content/uploads//2010/01/graph-300x218.gif" alt="Pseudocolor Graph" width="300" height="218" /></a>
<p class="wp-caption-text">Pseudocolor Graph with red(p=2,theta=0) green(2,-0.1) and blue(2,-0.3)</p>
</div>
<p>Then we only need set the gray level in range 0 to 1 and the sine returns values from 0 to 1 we interpret as float image values or we set in range 0 to 255.</p>
<p>To finish this is the result:</p>
<div id="attachment_255" class="wp-caption aligncenter" style="width: 397px"><a href="http://blog.damiles.com/wp-content/uploads//2010/01/pseudocolor.jpg"><img class="size-medium wp-image-255" title="pseudocolor" src="http://blog.damiles.com/wp-content/uploads//2010/01/pseudocolor-300x238.jpg" alt="Pseudocolor Result" width="387" height="308" /></a>
<p class="wp-caption-text">Pseudocolor Result</p>
</div>
<p><a title="Code" href="http://www.artresnet.com/david/resource.jsp?f=14" target="_blank">Download the code.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/01/pseudocolor-implementation-with-opencv/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Neuroph, Java/Netbeans tutorial.</title>
		<link>http://blog.damiles.com/2010/01/neuroph-javanetbeans-tutorial/</link>
		<comments>http://blog.damiles.com/2010/01/neuroph-javanetbeans-tutorial/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 08:23:49 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[clasification]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[neuroph]]></category>
		<category><![CDATA[recognition]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=242</guid>
		<description><![CDATA[Neuroph is a Neural network for image recognition in java. In netbeans dzone are a netbeans/java tutorial for image recognition with neuroph library.]]></description>
			<content:encoded><![CDATA[<p><a href="http://neuroph.sourceforge.net/" target="_blank">Neuroph</a> is a Neural network for image recognition in java. In <a href="http://netbeans.dzone.com/articles/neuroph-smart-java-apps-neural-1" target="_blank">netbeans dzone</a> are a netbeans/java tutorial for image recognition with neuroph library.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/01/neuroph-javanetbeans-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chamilo. The new e-learning platform</title>
		<link>http://blog.damiles.com/2010/01/chamilo-the-new-e-learning-platform/</link>
		<comments>http://blog.damiles.com/2010/01/chamilo-the-new-e-learning-platform/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 10:32:02 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[e-learning]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=241</guid>
		<description><![CDATA[Today is born the new e-learning platform. Chamilo! Chamilo is a new project that opts for open source in a radical way. It aims at bringing you the best e-learning and collaboration platform in the open source world.]]></description>
			<content:encoded><![CDATA[<p>Today is born the new e-learning platform. <a href="http://www.chamilo.org/" target="_blank">Chamilo!</a></p>
<p>Chamilo is a new project that opts for open source in a radical way. It aims at bringing you the best e-learning and collaboration platform in the open source world.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/01/chamilo-the-new-e-learning-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Segmentation &amp; object detection by color.</title>
		<link>http://blog.damiles.com/2010/01/segmentation-object-detection-by-color/</link>
		<comments>http://blog.damiles.com/2010/01/segmentation-object-detection-by-color/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 20:40:09 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[cvDrawContours]]></category>
		<category><![CDATA[cvFindContours]]></category>
		<category><![CDATA[cvMorphologyEx]]></category>
		<category><![CDATA[pixel]]></category>
		<category><![CDATA[segmentation]]></category>
		<category><![CDATA[threshold]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=205</guid>
		<description><![CDATA[In this tutorial i go to explain how to image segmentation or detect objects byred color, in this case by red color. This task is simple, but there are some things we must known. Now i go to explain and get a demo code for segmentation, how to determine if each image pixel is red [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial i go to explain how to image segmentation or detect objects byred color, in this case by red color.</p>
<p>This task is simple, but there are some things we must known.</p>
<p>Now i go to explain and get a demo code for segmentation, how to determine if each image pixel is red or no, and then, i go to explain how we  can detect object, it&#8217;s similar but with diferent concept.<span id="more-205"></span></p>
<p>In first moment, we can decide get the red channel of image  and get the values, if it&#8217;s a higher value then we have a red pixel otherwise no.</p>
<p>This is incorrect. Why?, imagine we have a pixel and in his red channel have a 255 value, this is the higher value, then we decide this is a red pixel, but if in green and blue channel have 255 value too then we have a white pixel instead a red pixel. Then how we determine if a pixel is red or no?</p>
<p>Ok, we go to get some color values and determine how we decide if is red or no.</p>
<p><a href="http://blog.damiles.com/wp-content/uploads//2010/01/colors.jpg"><img class="aligncenter size-full wp-image-206" title="colors" src="http://blog.damiles.com/wp-content/uploads//2010/01/colors.jpg" alt="" width="440" height="138" /></a></p>
<p>Then we can decide that higher red value, and  lower values of blue and green can be defined as red color. Moreover the green and blue values don&#8217;t have a higher difference between his values.</p>
<p>We go to construct simple graph with some values to see better.</p>
<p><a href="http://blog.damiles.com/wp-content/uploads//2010/01/histo_colors.jpg"><img class="aligncenter size-full wp-image-207" title="histo_colors" src="http://blog.damiles.com/wp-content/uploads//2010/01/histo_colors.jpg" alt="" width="300" height="325" /></a></p>
<p>We see in this graph that the red value is higher than a max value and there are a min value for green and blue.</p>
<p>The min and max we go to name as blue green threshold and red threshold (bg_threshold, r_threshold).</p>
<p>This code compute for each pixel if it&#8217;s red or no, and create a black/white image, this is our segmentation image, and with this image we can use to label each object, we use a cvFindContours to retreive the contours of each object detected on our image.</p>
<pre class="brush: cpp;">
 for(y=0;yheight; y++)
 {
 red=((uchar*)(img-&gt;imageData + img-&gt;widthStep*y))[x*3+2];
 green=((uchar*)(img-&gt;imageData + img-&gt;widthStep*y))[x*3+1];
 blue=((uchar*)(img-&gt;imageData + img-&gt;widthStep*y))[x*3];
 uchar* temp_ptr=&amp;((uchar*)(img_result_threshold-&gt;imageData + img_result_threshold-&gt;widthStep*y))[x];

 if((red&gt;threshold)&amp;&amp;(green &lt; BG_threshold) &amp;&amp; (blue &lt; BG_threshold) &amp;&amp; (abs(green-blue)&lt; BG_diff)){
 temp_ptr[0]=255;//White to greater of threshold
 }else{
 temp_ptr[0]=0;//Black other
 }
 }
 }

 cvMorphologyEx(img_result_threshold, img_morph, img_temp, NULL, CV_MOP_CLOSE, 6);

 cvNamedWindow( &quot;Threshold&quot;, 1 );
 cvShowImage( &quot;Threshold&quot;, img_morph );

 cvFindContours( img_morph, storage, &amp;contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );

 for( ; contour != 0; contour = contour-&gt;h_next )
 {
 CvScalar color = CV_RGB( rand()&amp;255, rand()&amp;255, rand()&amp;255 );
 cvDrawContours( img, contour, color, color, -1, 3, 8, cvPoint(0,0) );
 }
</pre>
<p>And this is the result, whe can see in the image a color border with detected red objects, the system detect two objects. The notebook and the notebook corner</p>
<p><a href="http://blog.damiles.com/wp-content/uploads//2010/01/captura.jpg"><img class="aligncenter size-medium wp-image-217" title="captura" src="http://blog.damiles.com/wp-content/uploads//2010/01/captura-300x156.jpg" alt="" width="300" height="156" /></a><a href="http://www.artresnet.com/david/resource.jsp?f=13" target="_blank">Demo Source</a></p>
<p>This is perfect to image segmentation by color, but imagine we have objects ofone image, and we want get each object and know if this object have a predominant red color or no.</p>
<p>The theory is same but applied to the object histogram, and use the median to determine the thresholds</p>
<p><a href="http://blog.damiles.com/wp-content/uploads//2010/01/histo_1.jpg"><img class="aligncenter size-full wp-image-218" title="histo_1" src="http://blog.damiles.com/wp-content/uploads//2010/01/histo_1.jpg" alt="" width="400" height="143" /></a></p>
<p>But with this we don&#8217;t have enough, because we can get a gray image as we can see in the second histogram, then we need use another parameter more, the dispersion of each channel.</p>
<p><a href="http://blog.damiles.com/wp-content/uploads//2010/01/histo_2.jpg"><img class="aligncenter size-full wp-image-219" title="histo_2" src="http://blog.damiles.com/wp-content/uploads//2010/01/histo_2.jpg" alt="" width="400" height="185" /></a></p>
<p>We can see that in this first histogram we can ensure this object have a predominant red, and in the second histogram no.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/01/segmentation-object-detection-by-color/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>VIM how to remove ^M at the end of lines</title>
		<link>http://blog.damiles.com/2010/01/vim-how-to-remove-m-at-the-end-of-lines/</link>
		<comments>http://blog.damiles.com/2010/01/vim-how-to-remove-m-at-the-end-of-lines/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 08:37:17 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=189</guid>
		<description><![CDATA[In unix the end of line is different than other systems. More times we edit windows files and when open in VI/VIM we see the ^M character at end of lines. We can remove this characters with a simply search and replace of vim with this command: :%s/^M//g The ^M character is not valid write [...]]]></description>
			<content:encoded><![CDATA[<p>In unix the end of line is different than other systems. More times we edit windows files and when open in VI/VIM we see the ^M character at end of lines.</p>
<p>We can remove this characters with a simply search and replace of vim with this command:</p>
<blockquote><p><code>:%s/^M//g</code></p></blockquote>
<p>The ^M character is not valid write first ^ character and then M it&#8217;s not the valid character. To write correctly this we must push <strong>Control+v </strong>and<strong> Contro+M</strong> keys, then appear our ^M Character.</p>
<p>Take care with this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2010/01/vim-how-to-remove-m-at-the-end-of-lines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compile Opencv with Mac os Snow Leopard 10.6</title>
		<link>http://blog.damiles.com/2009/09/compile-opencv-with-mac-os-snow-leopard-106/</link>
		<comments>http://blog.damiles.com/2009/09/compile-opencv-with-mac-os-snow-leopard-106/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 13:47:41 +0000</pubDate>
		<dc:creator>damiles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.damiles.com/?p=181</guid>
		<description><![CDATA[Today i try install OpenCv in my MacOs Snow Leopard 10.6 and have this error: error: CPU you selected does not support x86-64 instruction set The searching in google have the solution go to opencv folder and edit configure file, searchi prescott and replace the line DEFAULT_CXXFLAGS=&#8221;-g -march=prescott -ffast-math -fomit-frame-pointer $DEFAULT_CXXFLAGS&#8221; with this: DEFAULT_CXXFLAGS=&#8221;-g -march=i686 [...]]]></description>
			<content:encoded><![CDATA[<p>Today i try install OpenCv in my MacOs Snow Leopard 10.6 and have this error:</p>
<p><span> <span class="highlight">error</span>: <span class="highlight">CPU</span> <span class="highlight">you</span> <span class="highlight">selected</span> <span class="highlight">does</span> <span class="highlight">not</span> <span class="highlight">support</span> <span class="highlight">x86</span>-<span class="highlight">64</span> <span class="highlight">instruction</span> <span class="highlight">set</span></span></p>
<p>The searching in google have the solution</p>
<p>go to opencv folder and edit configure file, searchi prescott and replace the line</p>
<p>DEFAULT_CXXFLAGS=&#8221;-g -march=prescott -ffast-math -fomit-frame-pointer $DEFAULT_CXXFLAGS&#8221;</p>
<p>with this:</p>
<p>DEFAULT_CXXFLAGS=&#8221;-g -march=i686 -m32 -ffast-math -fomit-frame-pointer $DEFAULT_CXXFLAGS&#8221;</p>
<p>But when i try to compile i have other error i now looking for how to resolve it</p>
<p><strong>Now i can install opencv lib with macport!!!<span id="more-181"></span><br />
</strong></p>
<p>1.- i have old macport then first i need clean and delete it.</p>
<div class="wp_syntax">
<div class="code">
<pre class="c" style="font-family:monospace;">port installed <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> myports.<span style="color: #202020;">txt</span>
&nbsp;
sudo port clean installed
&nbsp;
sudo port <span style="color: #339933;">-</span>f uninstall installed</pre>
</div>
</div>
<p>2.- Install ports you need you can see myports.txt to know the old ports you have installed before clean.</p>
<p>3.- Patch the opencv port: see http://trac.macports.org/ticket/21014 and download the patch <a title="View attachment" href="http://trac.macports.org/raw-attachment/ticket/21014/Portfile-sl_64bit_21014.diff">Portfile-sl_64bit_21014.diff</a></p>
<p>4.- Follow the instruction in post of patch</p>
<blockquote><p>Check where you installed <span class="searchword0">macport</span>s, that is usually /opt/local/ Locate the Portfile for <span class="searchword1">OpenCV</span>, for me that is at</p>
<p>/opt/local/var/<span class="searchword0">macport</span>s/sources/rsync.macports.org/release/ports/graphics/<span class="searchword1">opencv</span></p>
<p>now apply the third patch (Portfile-sl_64bit_21014.diff) by executing</p>
<p>sudo patch Portfile -i ~/Downloads/Portfile-sl_64bit_21014.diff</p>
<p>in the above directory (adjust the last path accordingly to your download location)</p>
<p>When you execute port variants <span class="searchword1">opencv</span> you should see the sl_64bit_21014 variant. Now install opencv with</p>
<p>sudo port install <span class="searchword1">opencv</span> +sl_64bit_21014</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.damiles.com/2009/09/compile-opencv-with-mac-os-snow-leopard-106/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

