tag:blogger.com,1999:blog-219547722024-03-08T19:33:41.530+08:00thk's noteSomething about my own studies, programming notes, and also English writing exercise.THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.comBlogger233125tag:blogger.com,1999:blog-21954772.post-24032857875431913242016-12-18T13:10:00.001+08:002016-12-18T13:15:30.626+08:00Invert the document colors in Okular with toggle shortcutI have <a href="http://hiankun.blogspot.tw/2010/02/sw-invert-documents-colors-in-okular.html">an old post about how to change the document colors in Okular</a>, and it gave no toggle options. Here I post an updated version for you who might be want to invert the colors of your PDF files in Okular (I myself always need this kind of toggling functions).<br />
<br />
By the way, my OS is Ubuntu 16.04 and the Okular's version is 0.24.2. Just for your reference.<br />
<br />
First, go to ``Settings --> Configure Shortcuts...''. In the setting window, you could search for the wanted options. I used ``color'' to find the ``Toggle Change Colors'' option as follows:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfzvIoxfDFlaDO_VAJQ6B7nkHxUQdy5AZ7NpI5n0-euUc3J2jsZJdP0uDIWJ0ppNvzyhvXgnhfNDYHH1F8iebkxt-t2paG0BzyEU3umsQJbaFxVameCelJgIJNoDfr51QtUSsr/s1600/Screenshot+from+2016-12-18+12-42-52.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfzvIoxfDFlaDO_VAJQ6B7nkHxUQdy5AZ7NpI5n0-euUc3J2jsZJdP0uDIWJ0ppNvzyhvXgnhfNDYHH1F8iebkxt-t2paG0BzyEU3umsQJbaFxVameCelJgIJNoDfr51QtUSsr/s1600/Screenshot+from+2016-12-18+12-42-52.png" /></a></div>
<br />
Choose ``Custom''. When you move your mouse to the ``None'' icon and wait for seconds, it popped out the instruction to add your own shortcut keybindings:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpfl16lZhFhWa9Smf1_Ompmn_rK5tdDUqkKM5QwbfNyzG_cuSRChRwZKvHK-YF-kW6pPaBl_FMxsS18NY26XbG4n1w_ye6Tj8VEDzbPbuhtRASxfGinCwVyiwE_OLOnB0e2QSm/s1600/Screenshot+from+2016-12-18+12-43-49.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpfl16lZhFhWa9Smf1_Ompmn_rK5tdDUqkKM5QwbfNyzG_cuSRChRwZKvHK-YF-kW6pPaBl_FMxsS18NY26XbG4n1w_ye6Tj8VEDzbPbuhtRASxfGinCwVyiwE_OLOnB0e2QSm/s1600/Screenshot+from+2016-12-18+12-43-49.png" /></a></div>
<br />
I used ``Ctrl+I'' as the shortcut:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW3vl6lRWX8mVGOLMirU-e0CGiB6ZaiEOgBlcoaBmTHL40yVsixPHOHwJQAq3rFksKpswz-tL-OucbtNuQeJUbBWlEPEv4uM_19QXogKNbO-3UZG1tqzMp8Ujr8wJhjZiMU0z5/s1600/Screenshot+from+2016-12-18+12-44-21.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW3vl6lRWX8mVGOLMirU-e0CGiB6ZaiEOgBlcoaBmTHL40yVsixPHOHwJQAq3rFksKpswz-tL-OucbtNuQeJUbBWlEPEv4uM_19QXogKNbO-3UZG1tqzMp8Ujr8wJhjZiMU0z5/s1600/Screenshot+from+2016-12-18+12-44-21.png" /></a></div>
<br />
After the setting, you can press ``Ctrl+I'' to toggle between the normal and the inverted color scheme:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW8_GqawoHKydqdDQD9JfKfraTe8j3cioBL08-c_TD9Xdb1BXkAVhredfD36wrBH05TR5LE2CD8-ylHkm3DRfWAohcYWrUwfxJPIRCZE7-SlQI7hVezxyBZvBTgoqP67Qky8fN/s1600/Screenshot+from+2016-12-18+12-41-31.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW8_GqawoHKydqdDQD9JfKfraTe8j3cioBL08-c_TD9Xdb1BXkAVhredfD36wrBH05TR5LE2CD8-ylHkm3DRfWAohcYWrUwfxJPIRCZE7-SlQI7hVezxyBZvBTgoqP67Qky8fN/s1600/Screenshot+from+2016-12-18+12-41-31.gif" /></a></div>
<br />THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com2tag:blogger.com,1999:blog-21954772.post-39826174411736181902015-09-11T15:50:00.003+08:002015-09-11T16:20:44.062+08:00Setup notes on Emacs and Common LispI recently thought about Lisp again, and found last time when I was planning to learn Lisp has been <a href="http://hiankun.blogspot.tw/2009/10/sw-emacs-and-slime-for-common-lisp.html" target="_blank">six years ago</a>... O__O<br />
<br />
This time I will not <a href="http://hiankun.blogspot.tw/2009/10/sw-learning-lsip-using-vim-as-editor.html" target="_blank">to learn Lisp with Vim</a>, but with Emacs.<br />
<br />
I am following<img border="0" src="http://www.assoc-amazon.com/e/ir?t=gigamonkeys-20&l=as2&o=1&a=1590592395" /> <i><a href="http://www.gigamonkeys.com/book/" target="_blank">Practical Common Lisp</a></i> and found there's a so-called <a href="https://common-lisp.net/project/lispbox/" target="_blank">Lisp in a Box</a> package, but I decided not to use it now. My plan is to set up a working environment in Ubuntu using more common approaches.<br />
<br />
Here are something I have done so far, and they are left here as a note.<br />
<br />
<ol>
<li>Installed Emacs, Slime, and CLisp:</li>
$sudo apt-get install emacs slime clisp<br />
<br />
<li>Created ~/.emacs.d/slime/ (to be checked...) </li>
<li>Add ~/.emacs with the content (copied from websites, some functions are not clear to me):</li>
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">;; MELPA </span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">(when (>= emacs-major-version 24) </span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> (require 'package)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> (add-to-list</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> 'package-archives</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> '("melpa" . "http://melpa.org/packages/")</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> t) </span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> (package-initialize))</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">(setq inferior-lisp-program "clisp")</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">;; Setup load-path, autoloads and your lisp system</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">(add-to-list 'load-path "~/.emacs.d/slime/")</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">(require 'slime-autoloads)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">;; Also setup the slime-fancy contrib</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">;;(add-to-list 'slime-contribs 'slime-fancy)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">;;(setq tab-always-indent 'complete)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">;;; for auto-complete</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">(require 'auto-complete)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">(global-auto-complete-mode t)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">;(add-to-list 'ac-modes 'lisp-mode)</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">(add-to-list 'completion-styles 'initials t)</span></span></blockquote>
<li>After adding MELPA, installed<span style="font-size: small;"> <span style="font-family: "Courier New",Courier,monospace;"><span style="color: blue;">auto-complete</span> </span>by<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: blue;">M-x package-</span></span><span style="color: blue;"><span style="font-family: "Courier New",Courier,monospace;">install</span></span></span></li>
<li>Also installed <span style="font-family: "Courier New",Courier,monospace;"><span style="color: blue;">evil</span></span> which enable ``evil-mode'' for Vim-like key strokes</li>
<li>Use <span style="font-family: "Courier New",Courier,monospace;"><span style="color: blue;">M-x slime</span></span> to start it and the clisp </li>
</ol>
<ol>
</ol>
THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-24760443430762212532015-06-16T12:47:00.004+08:002015-06-17T14:47:05.231+08:00Build PCL with OpenNI2 in Ubuntu 14.04I have built PCL from source and installed it in my Ubuntu 14.04. Everything was fine till these days.<br />
<br />
I wanted to rebuild one of my test code in which I used Xition as the input device and it needed OpenNI2. When running ``make'' the system complained that it couldn't find <span style="font-family: "Courier New",Courier,monospace;"><span style="background-color: #ffe599;">pcl/io/openni2_grabber.h</span></span>. I checked and found the head file was in the source package but not in the corresponding system folder. So it was something wrong with the make files.<br />
<br />
The solution is to turn on the flag <span style="font-family: Georgia,"Times New Roman",serif;"><span style="background-color: #ffe599;">BUILD_OPENNI2</span></span> which has <span style="font-family: Georgia,"Times New Roman",serif;"><span style="background-color: #ffe599;">OFF</span></span> as the default value[1]. I used<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ grep -r "BUILD_OPENNI2" .</span></blockquote>
to find it was in the file of <span style="background-color: #ffe599;"><span style="font-family: "Courier New",Courier,monospace;">CMakeCache.txt</span></span>. Then just changed the value of from <span style="background-color: #ffe599;"><span style="font-family: Georgia,"Times New Roman",serif;">OFF</span></span> to <span style="background-color: #ffe599;"><span style="font-family: Georgia,"Times New Roman",serif;">ON</span></span> and did <span style="background-color: #ffe599;"><span style="font-family: "Courier New",Courier,monospace;">make && sudo make install </span></span>again.THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-89320570075877884252015-01-05T09:55:00.003+08:002015-01-05T10:08:06.194+08:00My QuickBot test with IR sensorsBy following the <a href="https://www.coursera.org/" target="_blank">Coursera</a> course, <a href="https://www.coursera.org/course/conrob" target="_blank">Control of Mobile Robots</a>[1] by <a href="http://users.ece.gatech.edu/magnus/" target="_blank">Dr. Magnus Egerstedt</a>, I've built my first QuickBot in which the <a href="http://beagleboard.org/BLACK" target="_blank">BeagleBone Black</a> is the core.<br />
<br />
The course had been closed in several months ago, but I didn't get enough leisure time (and proper mood... maybe...) to complete the robot until these weeks. The following photos show the QuickBot:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX-GJFypO8CJ0Wt8mjMB_rjhcmw_u1eipCJ7Hr2ZKbFlPPcEQd35TEGW7IAKaMsD6LzO1_88BKOKHQsSyy9kx9T7fa7O3PLWVunBUxilkrVVmj4g9LBBf3K9yGCPX-LDWxwbfD/s1600/my_quickbot_01.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX-GJFypO8CJ0Wt8mjMB_rjhcmw_u1eipCJ7Hr2ZKbFlPPcEQd35TEGW7IAKaMsD6LzO1_88BKOKHQsSyy9kx9T7fa7O3PLWVunBUxilkrVVmj4g9LBBf3K9yGCPX-LDWxwbfD/s1600/my_quickbot_01.jpg" height="320" width="244" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Front view of my QuickBot</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvB8M63AxbGYXxwEVK8rtWZfzTjv-YgHga2KnG2tda0TTxfYo8dR6kdApV5vWiSgDf3_CZsUIPE6P3M67ibh9p1vI8J3rVNyvag6ZNx1CJMxlp26yX700-Y-OPkkcP54zUce86/s1600/my_quickbot_02.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvB8M63AxbGYXxwEVK8rtWZfzTjv-YgHga2KnG2tda0TTxfYo8dR6kdApV5vWiSgDf3_CZsUIPE6P3M67ibh9p1vI8J3rVNyvag6ZNx1CJMxlp26yX700-Y-OPkkcP54zUce86/s1600/my_quickbot_02.jpg" height="226" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Top view; the BBB is on the left side</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpYEqGQRArD7Z3flMv771T8kl2KZYR0YfpSSDAm3z7uQwoUtUgIVNyIgk1-hkEpeRb9L49BLZqZkxnt-4MsgECq0XCuwqJGEHJO_UcsDz5LuCtPnVNqERKvrwMk6n81mlt0K8O/s1600/my_quickbot_03.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpYEqGQRArD7Z3flMv771T8kl2KZYR0YfpSSDAm3z7uQwoUtUgIVNyIgk1-hkEpeRb9L49BLZqZkxnt-4MsgECq0XCuwqJGEHJO_UcsDz5LuCtPnVNqERKvrwMk6n81mlt0K8O/s1600/my_quickbot_03.jpg" height="180" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The mess of wires between the chassis</td></tr>
</tbody></table>
What I have done so far is to test the sensors and motors with the help of the testing code <a href="https://github.com/pgmmpk/qb_test" target="_blank">qb_test</a> written by <a href="https://github.com/pgmmpk" target="_blank">Mike Kroutikov</a>. Because I've used <span class="seohtagbold" itemprop="breadcrumb">the <a href="http://www.digikey.com/product-search/en?WT.z_header=search_go&lang=en&site=us&keywords=425-2819-ND&x=0&y=0&formaction=on" target="_blank">Sharp GP2Y0A41SK0F</a> IR sensors which are different from the ones assigned in the course, I am not sure whether the output is identical to that given in the comment of the test code.</span> Therefore, after some tests, I decided to modify the test code for the IR sensors to show the detected distances in centimetres[3].<br />
<br />
I searched and found some conversion formulas for Arduino[2]:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.dfrobot.com/wiki/images/e/e8/Formulas.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://www.dfrobot.com/wiki/images/e/e8/Formulas.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">source: <a href="http://www.dfrobot.com/wiki/index.php?title=File:Formulas.jpg">http://www.dfrobot.com/wiki/index.php?title=File:Formulas.jpg</a></td></tr>
</tbody></table>
<br />
The trend of the output seemed right, but the absolute values were far from accurate. I might have to do some tests to find my own formula.<br />
<br />
What I failed in the test was the communication between the host PC (running <a href="https://github.com/typograph/pysimiam" target="_blank">pysimiam</a>) and the QuickBot's BBB (running <a href="https://github.com/o-botics/quickbot_bbb" target="_blank">quickbot_bbb</a>). I have Wi-Fi adaptor connected to the BBB and it worked perfectly for accessing the internet, but I just couldn't connect the BBB wirelessly from my PC. I decided to postpone this part.<br />
<br />
My next plans are:<br />
<ul>
<li>To write some code to drive the motors with the IR readings as the reference;</li>
<li>to change the battery packs to the Li-Poly one.</li>
</ul>
<br />
---<br />
[1] Without signing up the course, you may not be able to view the content. Here is the play list on YouTube: <a href="https://www.youtube.com/playlist?list=PLp8ijpvp8iCvFDYdcXqqYU5Ibl_aOqwjr">https://www.youtube.com/playlist?list=PLp8ijpvp8iCvFDYdcXqqYU5Ibl_aOqwjr</a> . It has only the video course, however.<br />
<br />
[2] <a href="http://www.dfrobot.com/wiki/index.php/SHARP_GP2Y0A41SK0F_IR_ranger_sensor_%284-30cm%29_SKU:SEN0143">http://www.dfrobot.com/wiki/index.php/SHARP_GP2Y0A41SK0F_IR_ranger_sensor_%284-30cm%29_SKU:SEN0143</a><br />
<br />
[3] My modified code is here: <a href="https://github.com/hiankun/qb_test.git">https://github.com/hiankun/qb_test.git</a>THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-63941039059736307972014-11-14T16:35:00.001+08:002014-11-14T17:00:01.009+08:00OpenCV ORB feature matching testCode is available here: https://github.com/hiankun/orb_test<br />
<br />
Here was my test on feature matching with ORB. In the video, the target image was shown in the left side and the real-time video was in the up-right corner.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/j2fLqKvbgpM?feature=player_embedded' frameborder='0'></iframe></div>
<br />
The feature points on the target image matched to the target when there were no other textured objects. If any object has detected feature points, however, the matching relationship would be disturbed significantly.<br />
<br />
I have not test the matching approach by using SURF or SIFT features. This will be the next step.<br />
<br />
Furthermore, I will try to apply <a href="http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">findHomography()</span></a> and <a href="http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#getperspectivetransform" target="_blank"><span style="font-family: "Courier New",Courier,monospace;">getPerspectiveTransform()</span></a> to find the correct object.THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com1tag:blogger.com,1999:blog-21954772.post-34348582025002179332014-11-14T08:58:00.003+08:002014-11-14T08:58:53.337+08:00Adding my project to GitHubFinally, I pushed my own test project on GitHub!!<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg8B2cKzzXj7eRRGgQP1fXO3MEuTRA6c-bJ0qF0rmYl9EHwBfMSzQRZhlqqBr8WNDAirtCHEDWdMjeo-DYoe02KSpHnFtJwQqCZHWKYEZkkOyssuItqV40NNbJ1CUwNZ88OEmu/s1600/thk_github.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg8B2cKzzXj7eRRGgQP1fXO3MEuTRA6c-bJ0qF0rmYl9EHwBfMSzQRZhlqqBr8WNDAirtCHEDWdMjeo-DYoe02KSpHnFtJwQqCZHWKYEZkkOyssuItqV40NNbJ1CUwNZ88OEmu/s1600/thk_github.png" /></a></div>
<br />
Okay, I know it's not a big deal, but it's my first step to use git more than just a logging tool in local machines.<br />
<br />
Actually I was slightly scared by the complexity of git, especially its mystical jargon such as rebase, merge, cherry-pick and so on.<br />
<br />
I thought, however, the git shouldn't be just used as a logging tool locally. Also, I wanted to use GitHub as the code repository which would be convenient to people who want to check my code. By upload my code to GitHub, I don't need to copy and paste it in the blog post. That's a better and smarter approach to share source code.<br />
<br />
Oh, before I dived into GitHub, I found the following links helped a lot:<br />
1. <a href="https://try.github.io/levels/1/challenges/1" target="_blank">try Git</a>, an interactive tutorial to give you a basic understanding;<br />
2. <a href="https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/#platform-linux" target="_blank">Adding an existing project to GitHub using the command line</a>THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-8997336029486970002014-11-10T16:58:00.001+08:002014-11-11T13:35:09.137+08:00Test OpenCV on BeagleBone Black using Logitech C920<script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.js" type="text/javascript">
</script><script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shBrushCpp.js" type="text/javascript">
</script><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.css" rel="stylesheet" type="text/css"></link><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shThemeDefault.css" rel="stylesheet" type="text/css"></link>Here are some basic trials in which I tested OpenCV running on my BBB.<br />
<br />
The Logitech C920 webcam did some works which I don't know very well so that the loading on the BBB has been reduced significantly. Other webcams might too ``slow'' for the test program to run directly (I remember the terminal returned `select timeout' errors).<br />
<br />
[NOTE: the following videos were boring and showed nothing exciting... :-p]<br />
<strike>[Sorry for the small view of the videos. I will find how to enlarge them later...] </strike><br />
[I've uploaded the video clips so that you can view them with better resolution.]<br />
<br />
The first one was the result shown via VNC. The image stream was laggy, but the processing time showed it was about 100 to 200 ms.<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/ZBbD3ZFVQI8?feature=player_embedded' frameborder='0'></iframe></div>
<br />
<br />
The second one showed the result without cv::imshow() via VNC. The processing time seemed reduced, but not significantly.<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/oeijd8SyPzc?feature=player_embedded' frameborder='0'></iframe></div>
<br />
<br />
The last one showed the result without cv::imshow() via ssh. The processing time was no more than 100ms.<br />
<div class="separator" style="clear: both; text-align: center;">
<br /><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/umqqpH5aAu8?feature=player_embedded' frameborder='0'></iframe></div>
<br />
<br />
It seemed that the VNC costed most of the computing resource.<br />
<br />
<br />
The test code was:<br />
<br />
<pre class="brush:cpp">#include <stdio.h>
#include "opencv2/opencv.hpp"
int main() {
cv::VideoCapture cap(0);
if(!cap.isOpened())
return -1;
int64 e1,e2;
double time;
for(;;) {
e1 = cv::getTickCount();
cv::Mat frame;
cap >> frame;
cv::imshow("match result", frame);
e2 = cv::getTickCount();
time = (e2 - e1)/cv::getTickFrequency()*1000.;
printf("time: %f ms\n", time);
if(cv::waitKey(30) >= 0) break;
}
return 0;
}
</pre>
<script type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all()
</script>
THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-18468672085928792312014-11-10T15:59:00.003+08:002014-11-10T16:02:45.428+08:00BeagleBone Black Wifi connection and VNC settings (Debian)<div class="tr_bq">
As mentioned in my previous post (<a href="http://hiankun.blogspot.tw/2014/11/setting-up-wifi-connection-of.html" target="_blank">Setting up the Wifi connection of BeagleBone Black (Angstrom)</a>), I couldn't make Wifi connection with the Angsrom images, and decided to test Debian image again.</div>
<br />
[A brief note for my first test with the Debian image]<br />
Actually I installed the Debian image several days ago, and did set the Wifi connection successfully. When I tried to update the system, however, the terminal replied with error message said that my system had no enough space. So I went back to Angstrom. And now I'm back to Debian again.<br />
<br />
The Debian image was large. After the installation, I checked the disk usage by typing ``df -h''... 93% used... It's crazy.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYWHBdFU67jzgWpoY-gYWLBxqzO20RMar9YC4yjtGTXyykSkqJCvh_LYzBOAZ2m_0Tljsfh3u4D7BqOhbrnuYeiPonX2xbMlIbmQtkyvxA62LwThsYxDiks6MOyXjyr3FohhlP/s1600/bbb_debian_fresh_install.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYWHBdFU67jzgWpoY-gYWLBxqzO20RMar9YC4yjtGTXyykSkqJCvh_LYzBOAZ2m_0Tljsfh3u4D7BqOhbrnuYeiPonX2xbMlIbmQtkyvxA62LwThsYxDiks6MOyXjyr3FohhlP/s1600/bbb_debian_fresh_install.png" /></a></div>
<br />
<br />
So, after reflash the on-board eMMC of BBB, I removed something like /usr/share/doc, Chromium, and even Vim (there's vi for later usage). This time, the system updated without errors.<br />
<br />
The following paragraphs were my note on the Wifi settings of the BBB with Debian image, and then the VNC settings. Most of the steps were following the guide: <a href="http://inspire.logicsupply.com/2014/08/beaglebone-wifi-installation_5.html" target="_blank">BeagleBone Black Ubuntu WiFi Installation and Troubleshooting Guide</a>.<br />
<br />
<h3>
PART 1 Wifi settings</h3>
<br />
<u><b>Step 1:</b></u> Make sure the system know the Wifi adaptor. Use ``lsusb'' and the system return the detected devices. In my case, it's the line with ``Ralink Technology, Corp.''<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3xahb5D5Zfuh-fK6Xbi9CkgpkJIyrO_67CrQw6KWWgam7aJMsxPd5YdybLbXFHh2-n7uTDpGgNq39sGeaSQXVHeOwUm2LR86OpTNUcF26zGHip47DcVClXbUwuMs6s5G3Scdc/s1600/wifi_adaptor_detected.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3xahb5D5Zfuh-fK6Xbi9CkgpkJIyrO_67CrQw6KWWgam7aJMsxPd5YdybLbXFHh2-n7uTDpGgNq39sGeaSQXVHeOwUm2LR86OpTNUcF26zGHip47DcVClXbUwuMs6s5G3Scdc/s1600/wifi_adaptor_detected.png" /></a></div>
<br />
<u><b>Step 2:</b></u> Check ``/etc/rcn-ee.conf'' and make sure it contain the following settings:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyw0VBT5baHx9txe-2pRSOdHzxcFwK_eTqyUkQltMEm-hDN-vYbcj-mqecTwDcGdbDqvob1fTgWktcNmWFkfGMvAQ_YTkEgAOMaWTtC6g8YEmGlDJcosMabEGDzJiFPw0miltl/s1600/rcn_ee_conf.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyw0VBT5baHx9txe-2pRSOdHzxcFwK_eTqyUkQltMEm-hDN-vYbcj-mqecTwDcGdbDqvob1fTgWktcNmWFkfGMvAQ_YTkEgAOMaWTtC6g8YEmGlDJcosMabEGDzJiFPw0miltl/s1600/rcn_ee_conf.png" /></a></div>
<u><b>Step 3:</b></u> Edit ``/etc/network/interfaces'' with the following settings:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">auto ra0</span><br />
<span style="font-family: "Courier New",Courier,monospace;">iface ra0 inet dhcp </span><br />
<span style="font-family: "Courier New",Courier,monospace;">wpa-ssid your_network_name</span>
<br />
<span style="font-family: "Courier New",Courier,monospace;">wpa-psk your_hashed_password </span></blockquote>
Finally, restart the BBB system. <br />
<br />
<h3>
PART 2 VNC settings</h3>
This part was easy. All the steps were the same as that of my another previous post (<a href="http://hiankun.blogspot.tw/2014/11/connect-to-beaglebone-black-via-vnc.html" target="_blank">Connect to Beaglebone Black via VNC client in Ubuntu 12.04</a>). The only different setting was <a href="http://inspire.logicsupply.com/p/vnc-connection.html" target="_blank">the starting command of the VNC server</a> (the BBB):<br />
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;">x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/lightdm/root/:0 -forever</span></blockquote>
<br />THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-70917124134262006862014-11-07T09:03:00.000+08:002014-11-07T09:03:09.737+08:00Two copies of clang_complete makes vim throw error messagesRecently I found there was error messages when I open C/C++ files in Vim (see the following photo).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK-Khs6o51dyh07oujkfDIi6WBxJrFZJiRAW2C0a8u6Ypae5h2airNoesVFafCfpuAdVBduitVq1CN9j6O9F08MMJtcUfHr24HQT_0_hZiYWojLbL-5E10NUBCQQ5zP6wQ_PYA/s1600/tmp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK-Khs6o51dyh07oujkfDIi6WBxJrFZJiRAW2C0a8u6Ypae5h2airNoesVFafCfpuAdVBduitVq1CN9j6O9F08MMJtcUfHr24HQT_0_hZiYWojLbL-5E10NUBCQQ5zP6wQ_PYA/s1600/tmp.png" /></a></div>
<br />
So I googled, and installed so-called libclang-dev. After the installation, the error message became more terrible:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtAwnkrLirr7BktQOYIVcUwb-qO24d61oT8zGrhTEVQ4edzQLr5CIMcYsc_v8ROzEFrsNptqoTSWYhNT6hnnY_6cVv-nf1o-M7dGAso-FssA5K9Ge4mUrywZuI2nJ9BCzhEPPc/s1600/tmp2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtAwnkrLirr7BktQOYIVcUwb-qO24d61oT8zGrhTEVQ4edzQLr5CIMcYsc_v8ROzEFrsNptqoTSWYhNT6hnnY_6cVv-nf1o-M7dGAso-FssA5K9Ge4mUrywZuI2nJ9BCzhEPPc/s1600/tmp2.png" /></a></div>
<br />
XDD<br />
<br />
Fortunately, I spotted a thread of clang_complete in GitHub, and <a href="https://github.com/Rip-Rip/clang_complete/issues/158#issuecomment-13059971" target="_blank">the author's comment</a> was the solution for me. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4bZREyYbYnIbnHsl3lBDoXbS6H2bNfjdHOverWLMRjnIhnWsfdBKE6CJ_MNa_8VUaFLa88W5fLt9C2Km4th9CrV4PpMOdu5wiFjYst7Y-7jpX9ZC61VcJvm_XNaPFl6Iorq3t/s1600/clang_complete_author_comment.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4bZREyYbYnIbnHsl3lBDoXbS6H2bNfjdHOverWLMRjnIhnWsfdBKE6CJ_MNa_8VUaFLa88W5fLt9C2Km4th9CrV4PpMOdu5wiFjYst7Y-7jpX9ZC61VcJvm_XNaPFl6Iorq3t/s1600/clang_complete_author_comment.png" /></a></div>
<br />
I must had installed the clang_complete manually and then it has been installed again by Vundle. :-p<br />
<br />
---<br />
Other useful link found during the search:<br />
<a href="http://stackoverflow.com/a/10900872" target="_blank">clang_complete can be configured to use the clang executable or the clang library</a>THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-13967098102396281622014-11-04T16:10:00.001+08:002014-11-04T16:22:17.973+08:00Failed to ssh into Beaglebone BlackYesterday when I was trying to update the OpenCV in my BBB, a strange thing happened. After downloading and unzipping OpenCV 2.4.9 in BBB [1], I couldn't log into my BBB via ssh (but using <a href="http://beagleboard.org/getting-started#step3" target="_blank">the webpage</a> still worked). The terminal responded nothing, and it just hanged there without logging in.<br />
<br />
<a href="http://beagleboard.org/Support/bone101/#cloud9" target="_blank">The Cloud9 IDE</a> helped in the test. It connect to your BBB and allow you to do something with JavaScript (I tested two of them which will be listed below).<br />
<br />
I searched and tested, <a href="https://groups.google.com/forum/#!msg/beagleboard/Ya2qE4repSY/q8_WkLcH5TwJ" target="_blank">the first script given in the mail list </a>[2] didn't work to me. It returned ``it seems that you have another problem, sorry.''<br />
<br />
Then I tested <a href="https://groups.google.com/d/msg/beagleboard/Ya2qE4repSY/ihEP5n2BNGUJ" target="_blank">the second script </a>[3]. After running that script I logged in BBB via ssh again.<br />
<br />
Actually I still have no idea what'd happened. Maybe the resource of BBB had been run out after the downloading of OpenCV? Maybe something else caused the problem.<br />
<br />
---<br />
Edit:<br />
<br />
I read the mail list again and found the post which listed the second script had said something may be useful. It talked about <a href="https://groups.google.com/forum/#!searchin/beagleboard/journal|sort:date/beagleboard/1NguS-SK-G8/EdbLDWfl4IUJ" target="_blank">systemd-journal settings</a>.<br />
<br />
---<br />
[1] I wouldn't do it again. At the beginning, I was planning to build OpenCV 2.4.9 in my BBB. Later, I read <a href="http://vuanhtung.blogspot.tw/2014/04/and-updated-guide-to-get-hardware.html" target="_blank">VAT's article</a> and knew that I should use cross-compilation.<br />
<br />
[2] The script:<br />
<div style="background-color: #fafafa; border: 1px solid rgb(187,187,187); word-wrap: break-word;">
<code></code><br />
<div>
<code><span style="color: #660066;"></span></code><br />
<div>
<code><span style="color: #660066;">/* <a href="https://groups.google.com/forum/?fromgroups=#%21msg/beagleboard/Ya2qE4repSY/u4lvOjF66JEJ" target="_blank">https://groups.google.com/<wbr></wbr>forum/?fromgroups=#!msg/<wbr></wbr>beagleboard/Ya2qE4repSY/<wbr></wbr>u4lvOjF66JEJ</a> */</span></code></div>
<code><span style="color: #660066;">
</span></code>
<div>
<code><span style="color: #660066;"><br /></span></code></div>
<code><span style="color: #660066;">
<div>
var fs = require('fs');</div>
<div>
var destroyed_key_file = '/etc/dropbear/dropbear_rsa_<wbr></wbr>host_key';</div>
<div>
<span style="font-family: Arial,Helvetica,sans-serif;"><br />fs.readFile(destroyed_key_<wbr></wbr>file, function (err, data) {</span></div>
<div>
if (err) throw err;</div>
<div>
</div>
<div>
if( data===null || data.length===0 )</div>
<div>
{</div>
<div>
console.log("we have a corrupted host key file... try do delete it");</div>
<div>
fs.unlink(destroyed_key_file, function (err) {</div>
<div>
if (err) throw err;</div>
<div>
console.log('successfully deleted ' + destroyed_key_file);</div>
<div>
console.log('you should now reboot your beaglebone.');</div>
<div>
console.log('the /etc/init.d/dropbear script will create a new rsa host key file for you.');</div>
<div>
console.log('after the reboot you should be able to login over ssh');</div>
<div>
});</div>
<div>
} else {</div>
<div>
console.log("it seems that you have another problem, sorry");</div>
<div>
}</div>
<div>
}); </div>
</span></code></div>
<code>
</code></div>
<br />
[3] The script worked for me:<br />
<div style="background-color: #fafafa; border: 1px solid rgb(187,187,187); word-wrap: break-word;">
<code><span style="color: #660066;"><br /></span></code>
<div>
<code><span style="color: #660066;">var exec = require('child_process').exec;</span></code></div>
<code><span style="color: #660066;">
<div>
function puts(error, stdout, stderr) { console.log(error); console.log(stdout); console.log(stderr); }</div>
<div>
<br /></div>
<div>
// 1 - Clear journal space</div>
<div>
exec("df -h; rm -rf /var/log/journal/; df -h", puts);</div>
<div>
<br /></div>
<div>
// 2 - Remove Dropbear file</div>
<div>
exec("rm /etc/dropbear/dropbear_rsa_<wbr></wbr>host_key", puts);</div>
<div>
<br /></div>
<div>
// 3 - Stop Dropbear</div>
<div>
exec("/etc/init.d/dropbear stop", puts);</div>
<div>
<br /></div>
<div>
// 4 - Start Dropbear</div>
<div>
exec("/etc/init.d/dropbear start", puts);</div>
<div>
<br /></div>
</span></code></div>
THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-71225037078807943682014-11-03T11:48:00.000+08:002014-11-03T11:48:04.424+08:00Connect to Beaglebone Black via VNC client in Ubuntu 12.04<div class="tr_bq">
I am planning to run OpenCV sample code in the BBB, and some graphic outputs are necessary.</div>
<br />
After some searches and tests, I made it. Here is the minimal steps.<br />
<u><b><br /></b></u>
<u><b>Step 1</b></u>: Make sure there's <a href="http://en.wikipedia.org/wiki/X11vnc" target="_blank">x11vnc</a> in BBB which acts as the VNC server.<br />
<br />
<u><b>Step 2</b></u>: SSH to BBB and <a href="http://inspire.logicsupply.com/p/vnc-connection.html" target="_blank">run the following command</a>:<br />
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;">x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/gdm/auth-for-gdm*/database -display :0 -forever</span></blockquote>
The terminal will return the following message:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTcGx7tFQBcsuJ0e2lq1oAXlqbFbN462Qu4SttMo_ONUvwq8UQwXMoL4omvY37D4nazo5bUbZvu6j8uGCims0TvjkvGS4i3UEUq3Q02MdL8XwpSi0oZbhsAbfzvYr6njBZ0CmO/s1600/bbb_start_vnc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTcGx7tFQBcsuJ0e2lq1oAXlqbFbN462Qu4SttMo_ONUvwq8UQwXMoL4omvY37D4nazo5bUbZvu6j8uGCims0TvjkvGS4i3UEUq3Q02MdL8XwpSi0oZbhsAbfzvYr6njBZ0CmO/s1600/bbb_start_vnc.png" /></a></div>
<br />
<u><b>Step 3</b></u>: Install xvncviewer in Ubuntu as the client viewer.<br />
<br />
<u><b>Step 4</b></u>: Run xvncviewer and use ``192.168.7.2:5900'' to connect to BBB.<br />
<br />
Here is the desktop of BBB:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkcTJCPdEl0LPWtQ6k1uuf3ucXX2pSuE01i7e_sCtOugG0QpdGc9GD-UC-ei7QfSG3iTKGUpWVBoCYuWftECPkPZDjyKAIyYVGnyndbqHnA2_pgRoNAPzZ35Sk3L5SDPDlTaKZ/s1600/bbb_vnc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkcTJCPdEl0LPWtQ6k1uuf3ucXX2pSuE01i7e_sCtOugG0QpdGc9GD-UC-ei7QfSG3iTKGUpWVBoCYuWftECPkPZDjyKAIyYVGnyndbqHnA2_pgRoNAPzZ35Sk3L5SDPDlTaKZ/s1600/bbb_vnc.png" /></a></div>
<br />THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-1641014597194640982014-11-02T23:47:00.001+08:002014-11-02T23:47:38.692+08:00Some settings to enable the vim-airline<div class="tr_bq">
I've tried to add some plugins to make Vim a better IDE. The article has helped me alot: <a href="http://dustri.org/b/vim-packet-manager-vundle.html" target="_blank">vim + packet manager = Vundle</a></div>
<br />
Just several minutes ago, I added the <a href="http://jchain.github.io/blog/2013/07/17/fly-with-vim-airline/" target="_blank">vim-airline</a> and did something to make it work in my vim (not gvim).<br />
<br />
After some tests, the only thing I have to do was to add the following line in my .vimrc <a href="http://vim.wikia.com/wiki/256_colors_in_vim" target="_blank">to enable 256 colors in vim</a>:<br />
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;">set t_Co=256</span></blockquote>
Another useful setting was<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">set laststatus=2</span></blockquote>
which lets the vim-airline show the status bar even there's only one file opened.<br />
<br />
If you want to replace the symbols with some Unicode ones, then <a href="http://stackoverflow.com/a/19137142" target="_blank">the so-called patch fonts are needed</a>. They can be found in <a href="https://github.com/Lokaltog/powerline-fonts">https://github.com/Lokaltog/powerline-fonts</a>.<br />
<br />
After installing the patched fonts, you can add the following settings in the .vimrc to enable <a href="https://github.com/dougireton/mirror_pond/blob/master/plugin/settings/airline.vim" target="_blank">the symbols</a>:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
<span style="font-family: "Courier New",Courier,monospace;">if !exists('g:airline_symbols')</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> let g:airline_symbols = {}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">endif</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
<span style="font-family: "Courier New",Courier,monospace;">" unicode symbols</span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_left_sep = '»' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_left_sep = '▶' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_right_sep = '«' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_right_sep = '◀' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.linenr = '␊' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.linenr = '' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.linenr = '¶' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.branch = '⎇' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.paste = 'ρ' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.paste = 'Þ' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.paste = '∥' </span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_symbols.whitespace = 'Ξ' </span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
<span style="font-family: "Courier New",Courier,monospace;">set guifont=DejaVu\ Sans\ Mono\ 10</span><br />
<span style="font-family: "Courier New",Courier,monospace;">let g:airline_powerline_fonts = 1 </span></blockquote>
<br />
Here's my vim with the vim-airline:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQn_6YShY9Pgh4iCg_C4wGPaAeBK22o6tEJBfWFZ0vEhZyx3NR6swaP_w2kCKAZXJd7ihfh5hCvaRJQBFEXEIUJHNb8x2VGEFfTeaLXfZCnS2wPNzOJ65kRCfiO7ap1CpjwfYg/s1600/vim_airline_color.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQn_6YShY9Pgh4iCg_C4wGPaAeBK22o6tEJBfWFZ0vEhZyx3NR6swaP_w2kCKAZXJd7ihfh5hCvaRJQBFEXEIUJHNb8x2VGEFfTeaLXfZCnS2wPNzOJ65kRCfiO7ap1CpjwfYg/s1600/vim_airline_color.png" /></a></div>
<br />
<br />
<br />
<br />THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-68058995126957486252014-11-02T17:10:00.002+08:002014-11-10T16:02:20.050+08:00Setting up the Wifi connection of BeagleBone Black (Angstrom)<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSpMFlHNpsRR_qxfjo0zGXWkw-fb9WThcotgySsNPRoHqzL6QY8iX86dS5WjKSIFMUtYC_apwWA4SLybq7QykJVmS4WbXI_8hED6BG1rS6YwfLIbRNrtTccfGkghO_LmLB5Hl6/s1600/DSC_0385.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSpMFlHNpsRR_qxfjo0zGXWkw-fb9WThcotgySsNPRoHqzL6QY8iX86dS5WjKSIFMUtYC_apwWA4SLybq7QykJVmS4WbXI_8hED6BG1rS6YwfLIbRNrtTccfGkghO_LmLB5Hl6/s1600/DSC_0385.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Wifi adaptor was UWN200</td></tr>
</tbody></table>
<br />
Several months ago, I've followed the course of ``<a href="https://class.coursera.org/conrob-002" target="_blank">Control of Mobile Robots</a>'' on <a href="https://www.coursera.org/" target="_blank">Coursera</a>. Although I've finished the course, but the hardware part has been postponed for these months.<br />
<br />
I determined to record the tests on the hardware, and here is the first post on the topic.<br />
<br />
The following procedure based on the course lecture.<br />
<br />
Step 0: I used my mobile phone as the Wifi hotspot for the BBB internet connection.<br />
<br />
<u><b>Step 1</b></u>: Connect the USB cable between the BBB and the PC. Plug the Wifi adaptor as well.<br />
<br />
<u><b>Step 2</b></u>: Log in BBB using ssh. Just type the follows in the terminal of host PC:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">ssh 192.168.7.2 -l root</span></blockquote>
<br />
<br />
<u><b>Step 3</b></u>: (from now on, all the commands will be working in BBB) Use the following command to get the hashed string which will be pasted in the configuration file:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">wpa_passphrase "<b>your network name here</b>" '<b>your password here</b>'</span></blockquote>
<u><b>Step 4</b></u>: Paste the hashed string into /var/lib/connman/wifi.config. The content of the wifi.config looks like:<br />
<blockquote class="tr_bq">
[service_home]<br />
Type = wifi<br />
AutoConnect = true<br />
Favorite = true<br />
Name = your network name<br />
Passphrase = your hashed password</blockquote>
<br />
<br />
<i><b>Update:</b></i><br />
I have encountered problems in the Wifi connection when I reflash my eMMC with new Angstrom images. I tried the newest version (2013.09.04) and <a href="http://downloads.angstrom-distribution.org/demo/beaglebone/archive/" target="_blank">an old one</a>, but got no luck.<br />
<br />
The newer Angstrom could identify the Wifi adaptor (by using lsusb, the terminal returned a message with the Wifi adaptor's company name), but all the same settings just couldn't make BBB connecting to the internet.<br />
<br />
After trying for several days, I decided to go back to the Debian image again, and here is the note: <a href="http://hiankun.blogspot.tw/2014/11/beaglebone-black-wifi-connection-and.html">BeagleBone Black Wifi connection and VNC settings (Debian)</a>.<br />
<br />
<br />THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-23225662085396206822014-11-02T15:40:00.000+08:002014-12-04T16:35:37.120+08:00Installing OpenCV 3.0.0 in Ubuntu 12.04[This is a note for my own installation of OpenCV 3.0.0 in Ubuntu 12.04]<br />
<br />
The main steps have been listed in the guidance page:<br />
<a href="http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html">http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html</a><br />
<br />
But my cmake options were as the follows:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON <strike>-D BUILD_NEW_PYTHO<br />N_SUPPORT=ON</strike> -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=O<br />N -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_IPP=OFF <strike>-D BUILD_opencv_nonfree=ON</strike> ..</span></blockquote>
<br />
Note that the WITH_IPP option had been disabled or there would be errors (which I didn't have time to tackle).<br />
<br />
I also used <a href="http://www.binarytides.com/linux-cpu-information/" target="_blank">lscpu</a> to view my CPU information. Actually I didn't know anything about ``number of hardware threads,'' and I assumed it just equal to the number of CPU multiplied by ``Thread(s) per core.'' I typed ``<span style="font-family: "Courier New",Courier,monospace;">make -j16</span>'' during the installation.<br />
<br />
After the installation, I check the installed version by typing<br />
<blockquote class="tr_bq">
<span style="font-family: Arial,Helvetica,sans-serif;">pkg-config --modversion opencv</span></blockquote>
and it returned<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">3.0.0 </span></blockquote>
Also, in ipython, typed the following command to check the installed version:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">In [1]: import cv2</span><br />
<span style="font-family: "Courier New",Courier,monospace;">In [2]: print cv2.__version__</span><br />
<span style="font-family: "Courier New",Courier,monospace;">3.0.0-dev </span></blockquote>
But after installing the new version, I couldn't run <a href="http://docs.opencv.org/trunk/doc/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html#py-depthmap" target="_blank">the python example of generating stereo image</a> because there was no module named createStereoBM... O__Oa<br />
<br />
That's out of my expectation. I thought the example was under the location of OpenCV 3.0.0, so it should had no problem for me to run the sample code. Another bad news was that the old StereoBM module was also failed.<br />
<br />
---<br />
I just tried the ORB example, but the module was also disappeared from the 3.0.0 version.<br />
<br />
After reinstall OpenCV 2.4.9, everything was okay. So now I just have no idea where are the missing modules in OpenCV 3.0.0. THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com1tag:blogger.com,1999:blog-21954772.post-30960011899785843822014-08-29T15:02:00.003+08:002014-08-29T15:05:25.711+08:00Some settings in Visual Studio 2008 for exporting dll and lib(This is a working note.)<br />
<br />
Suppose that we have a <span style="font-family: "Courier New",Courier,monospace;">YourProject.cpp</span> and its head file <span style="font-family: "Courier New",Courier,monospace;">YourProject.h</span>, and we want to export it as <span style="font-family: "Courier New",Courier,monospace;">YourProject.dll</span> and <span style="font-family: "Courier New",Courier,monospace;">YourProject.lib</span> in VS2008.<br />
<br />
Also, suppose that we have some code to define the exporting flag in <span style="font-family: "Courier New",Courier,monospace;">YourProject.h</span>: <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1XPUAwjkvyeb7f9VINTk-07oG67JoxbGeTn6kYzlPkdHvcOdQQv7tze6g06D_d9Fi2ChmFg2-e4BxMsH6QAR-CELKpV9w_7ehYywmycdaMecXmcnoHZHbY3yzlHDhyq0sBb64/s1600/headfile.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1XPUAwjkvyeb7f9VINTk-07oG67JoxbGeTn6kYzlPkdHvcOdQQv7tze6g06D_d9Fi2ChmFg2-e4BxMsH6QAR-CELKpV9w_7ehYywmycdaMecXmcnoHZHbY3yzlHDhyq0sBb64/s1600/headfile.jpg" /></a></div>
<br />
<br />
The steps were as the follows:<br />
<br />
Step 1: In the existing solution, add a project for the source and head file (i.e., the <span style="font-family: "Courier New",Courier,monospace;">YourProject.cpp</span> and <span style="font-family: "Courier New",Courier,monospace;">YourProject.h</span>)<br />
<br />
Step 2: Make sure that you set the project's <span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">Configuration Type</span> to ``dll'':<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOw088KuKNHg6S2V2uxWCa68bVYCVgeqmH5HtpRKryDSvCGO47Z_uNNs796hnP7WzO5f6PppdsYnIMEw3Nu_7xwk2yR1PGNgJ-QvxyKe0KZ5yDjwpEMuhsiJmR5iJd7-V6anu_/s1600/configuration_type.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOw088KuKNHg6S2V2uxWCa68bVYCVgeqmH5HtpRKryDSvCGO47Z_uNNs796hnP7WzO5f6PppdsYnIMEw3Nu_7xwk2yR1PGNgJ-QvxyKe0KZ5yDjwpEMuhsiJmR5iJd7-V6anu_/s1600/configuration_type.jpg" /></a></div>
<br />
Step 3: Add ``DLL_EXPORTS'' in the <span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">Preprocessor Definitions</span>:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEl_r334gT5daLFYATqsLjEQctyRcDj5VtqmN220IcSmqG3xxyR7Vg-ESBZpSO5dwWPmO8RA_JSdcDnfYM5xzpvUvmkeLLF6WoT2OxMo__l1zcKCAV3BxToRAswj0Zhd4-3zwY/s1600/preprocessor_definitions.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEl_r334gT5daLFYATqsLjEQctyRcDj5VtqmN220IcSmqG3xxyR7Vg-ESBZpSO5dwWPmO8RA_JSdcDnfYM5xzpvUvmkeLLF6WoT2OxMo__l1zcKCAV3BxToRAswj0Zhd4-3zwY/s1600/preprocessor_definitions.jpg" /></a></div>
<br />THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-10623909888380173152014-07-18T13:37:00.002+08:002014-07-18T13:37:31.411+08:00How to customize the resolution of CrunchBang in VirtualBox of Windows 7<span style="background-color: orange;"><b>Before you reading...</b></span> here is a better solution to solve the problem of screen resolution:<br />
<a href="http://How to install the Guest Additions for CrunchBang in VirtualBox of Windows 7 " target="_blank"> How to install the Guest Additions for CrunchBang in VirtualBox of Windows 7 </a><br />
<br />
Host system: Windows 7 x64<br />
Guest system: CrunchBang 11 ``<span class="st">Waldorf'' x64</span><br />
<br />
<span class="st">I've just installed CrunchBang in VirtualBox two days ago, but the resolution was limited so it cannot fit my monitor properly. After some trials (including some struggles when installing the so-called Guest Additions), I successfully changed the resolution to my need.</span><br />
<br />
<span class="st">I mainly followed the instruction of the link: </span><a href="http://superuser.com/questions/716795/how-to-adjust-the-screen-resolution-in-debian">How to adjust the screen resolution in Debian?</a><br />
<br />
But there's some more work to do to make the change permanently. We need to add the following lines (from my own setting) in ``<span style="color: blue;"><span style="font-family: "Courier New",Courier,monospace;">~/.config/openbox/autostart</span></span>'':<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">xrandr --newmode "1920x1002" 159.50 1920 2040 2240 2560 1002 1005 1015 1040 -hsync +vsync</span><br />
<span style="font-family: "Courier New",Courier,monospace;">xrandr --addmode VBOX0 "1920x1002"</span><br />
<span style="font-family: "Courier New",Courier,monospace;">xrandr --output VBOX0 --mode "1920x1002"</span></blockquote>
THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-79849232941348323822014-07-18T13:36:00.000+08:002014-07-18T13:40:44.897+08:00How to install the Guest Additions for CrunchBang in VirtualBox of Windows 7<div class="tr_bq">
After my installation of CrunchBang in VirtualBox, some functions such as ``<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">Auto-resize Guest Display</span>'' and ``<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">Shared Clipboard</span>'' were not available.</div>
<br />
The key is to install the ``<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">Guest Additions</span>''.<br />
<br />
I tried some instructions found on Web and the steps are listed as follows:<br />
<br />
<h4>
To install the following packages</h4>
This was simple, just install them: <br />
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;">apt-get install dkms build-essential linux-headers-generic</span></blockquote>
<h4>
To mount the Guest Additions image</h4>
Actually this confused me and I'm not sure about every details. Here I just write down what I've done for your reference. <br />
<br />
The first thing I did was to insert the <span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">VBoxGuestAdditions.iso</span> image via the GUI (I've selected the iso file before, so it appeared in the list automatically):<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy68cXD-R_yzUvi4qA8SYVbLrJtP3AxoY3WwdXO_lzQHVaeb-u-pi9brDVKZJNyIFIU4OntHnDzO23zFVpTOGc8inpm1MHKctSD6hVOIgb3c6LSLVj4EwQnLVZ9OdophzzNhVW/s1600/2014_crunchbang_vbox_insert_CD_image.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy68cXD-R_yzUvi4qA8SYVbLrJtP3AxoY3WwdXO_lzQHVaeb-u-pi9brDVKZJNyIFIU4OntHnDzO23zFVpTOGc8inpm1MHKctSD6hVOIgb3c6LSLVj4EwQnLVZ9OdophzzNhVW/s1600/2014_crunchbang_vbox_insert_CD_image.jpg" /></a></div>
Then click the ``<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">Insert Guest Additions CD image...</span>'' or use the following command to mount the image:<br />
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;">mount /dev/sr0 /media/cdrom </span></blockquote>
Now we can find the ``<span style="font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;">VBoxLinuxAdditions.run</span>'' script and run it:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_P0FJ2EIFU1P5RKwpkLVe9XUF9VKsMsqp8g1N9h4Almjc9mQ52wx1tpk8qyc3G61Rlw1sH1TJtpl9pnq6SuCXZVnzdU-cZd1nirv4Y1UAEKWRIlpSKycgLRx6RFpczHUsSH8o/s1600/2014_crunchbang_vbox_run_bash.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_P0FJ2EIFU1P5RKwpkLVe9XUF9VKsMsqp8g1N9h4Almjc9mQ52wx1tpk8qyc3G61Rlw1sH1TJtpl9pnq6SuCXZVnzdU-cZd1nirv4Y1UAEKWRIlpSKycgLRx6RFpczHUsSH8o/s1600/2014_crunchbang_vbox_run_bash.jpg" /></a></div>
<br />
<br />
And the Guest Additions should be installed. :-)<br />
<br />
---<br />
Refs:<br />
More details could be found here: <a href="https://forums.virtualbox.org/viewtopic.php?f=29&t=15679">HOWTO: Install Linux Guest Additions + Xorg config</a><br />
and here: <a href="http://superuser.com/a/261862">http://superuser.com/a/261862</a> THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-3844376589256075762013-08-08T14:23:00.000+08:002013-08-08T14:24:59.691+08:00Downsampling images to speed up GrabCut<script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.js" type="text/javascript">
</script><script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shBrushCpp.js" type="text/javascript">
</script><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.css" rel="stylesheet" type="text/css"></link><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shThemeDefault.css" rel="stylesheet" type="text/css"></link>In the previous post [1] I've tried the GrabCut function of OpenCV, when I noticed it was time consuming but didn't try to check the exact processing time. But I was still wondering ``how slow'' did GrabCut could be. So, I started to add the clock() function to see the result [2].<br />
<br />
Later, I though of that the processing time was greatly affected by the image size, so I searched for functions which could reduce the images for speeding up GrabCut. What I found were<a href="http://docs.opencv.org/doc/tutorials/imgproc/pyramids/pyramids.html" target="_blank"> cv::pyrDown() and cv::pyrUp()</a> and they've been implemented in my test code (listed below).<br />
<br />
<pre class="brush:cpp">#include "opencv2/opencv.hpp"
#include <iostream>
#include <time.h>
using namespace std;
const bool DOWN_SAMPLED = true;
const unsigned int BORDER = 1;
const unsigned int BORDER2 = BORDER + BORDER;
int main( )
{
clock_t tStart_all = clock();
// Open another image
cv::Mat image;
image = cv::imread("sunflower02.jpg");
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
cv::Mat result; // segmentation result (4 possible values)
cv::Mat bgModel,fgModel; // the models (internally used)
if(DOWN_SAMPLED){
// downsample the image
cv::Mat downsampled;
cv::pyrDown(image, downsampled, cv::Size(image.cols/2, image.rows/2));
cv::Rect rectangle(BORDER,BORDER,downsampled.cols-BORDER2,downsampled.rows-BORDER2);
clock_t tStart = clock();
// GrabCut segmentation
cv::grabCut(downsampled, // input image
result, // segmentation result
rectangle,// rectangle containing foreground
bgModel,fgModel, // models
1, // number of iterations
cv::GC_INIT_WITH_RECT); // use rectangle
printf("Time taken by GrabCut with downsampled image: %f s\n", (clock() - tStart)/(double)CLOCKS_PER_SEC);
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// upsample the resulting mask
cv::Mat resultUp;
cv::pyrUp(result, resultUp, cv::Size(result.cols*2, result.rows*2));
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,resultUp); // bg pixels not copied
// display original image
cv::namedWindow("Image");
cv::imshow("Image",image);
// display downsampled image
cv::rectangle(downsampled, rectangle, cv::Scalar(255,255,255),1);
cv::namedWindow("Downsampled Image");
cv::imshow("Downsampled Image",downsampled);
// display downsampled mask
cv::namedWindow("Downsampled Mask");
cv::imshow("Downsampled Mask",result);
// display final mask
cv::namedWindow("Final Mask");
cv::imshow("Final Mask",resultUp);
// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);
}
else {
cv::Rect rectangle(BORDER,BORDER,image.cols-BORDER2,image.rows-BORDER2);
clock_t tStart = clock();
// GrabCut segmentation
cv::grabCut(image, // input image
result, // segmentation result
rectangle,// rectangle containing foreground
bgModel,fgModel, // models
1, // number of iterations
cv::GC_INIT_WITH_RECT); // use rectangle
printf("Time taken by GrabCut with original image: %f s\n", (clock() - tStart)/(double)CLOCKS_PER_SEC);
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,result); // bg pixels not copied
// display original image
cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1);
cv::namedWindow("Image");
cv::imshow("Image",image);
// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);
}
printf("Total processing time: %f s\n", (clock() - tStart_all)/(double)CLOCKS_PER_SEC);
cv::waitKey();
return 0;
}
</pre>
<script type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all()
</script>
<br />
<br />
The key idea was to downsample the image for GrabCut and then upsample the result (I thought it was a mask) to the original size. The result showed a remarkable speeding up in both the debug and the release mode. <br />
<br />
Here are the output images <b>with the downsampling strategy</b>:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC13gANBHjzKvI2QZJgNzwwqQkUulE-kv-kAndAcPZJirPTNhVkoySzZJiEhTBKoLAzvBhDVQD5XIe2IfZDh9Dv6hqFiua0etarMMMgXZuA_D9Y3WIyMKcN39QVbu4ZYwz2yvM/s1600/original_image.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC13gANBHjzKvI2QZJgNzwwqQkUulE-kv-kAndAcPZJirPTNhVkoySzZJiEhTBKoLAzvBhDVQD5XIe2IfZDh9Dv6hqFiua0etarMMMgXZuA_D9Y3WIyMKcN39QVbu4ZYwz2yvM/s1600/original_image.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig 1. Original image</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEr9iTic3-yFVHsOb2X3f0odU-R79yLa_t5c5RQ0y5uCR1ceBfe4IYK0w5ubLUERhg2n5ZAZSbATYqHTIGn3XR7t030EA9YnF3wd1hA2llLxkE1B887EA8CsipBcyLt96nbNRv/s1600/downsampled_image.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEr9iTic3-yFVHsOb2X3f0odU-R79yLa_t5c5RQ0y5uCR1ceBfe4IYK0w5ubLUERhg2n5ZAZSbATYqHTIGn3XR7t030EA9YnF3wd1hA2llLxkE1B887EA8CsipBcyLt96nbNRv/s1600/downsampled_image.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig 2. Downsampled image</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_NR56PTki4tVOaBbA5iegrFNZVj3jRtyxihab7buB1vd5IaNRHkXpmaYBpV7W4DgjbqEypr31T2jVMKgrPzvbX6_bMONNhRjnV5DwuaC7hn-6aUCyWZ01ttkJvn8XmO_XPJDa/s1600/mask.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_NR56PTki4tVOaBbA5iegrFNZVj3jRtyxihab7buB1vd5IaNRHkXpmaYBpV7W4DgjbqEypr31T2jVMKgrPzvbX6_bMONNhRjnV5DwuaC7hn-6aUCyWZ01ttkJvn8XmO_XPJDa/s1600/mask.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig 3. Mask obtained by using GrabCut</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhavgC1WYd0CqRxYOXn5_oIXiSVUX41vjWyGS-bnPh5iAa6irmwE8MxT1WiBWMdo-pFiadI3tUhVNDnMmVBOa3U3iFPHIy3nDtjk_caGjBJElmyUpK6JXLvCdUY4fvvoaDA97Ff/s1600/upsampled_mask.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhavgC1WYd0CqRxYOXn5_oIXiSVUX41vjWyGS-bnPh5iAa6irmwE8MxT1WiBWMdo-pFiadI3tUhVNDnMmVBOa3U3iFPHIy3nDtjk_caGjBJElmyUpK6JXLvCdUY4fvvoaDA97Ff/s1600/upsampled_mask.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig 4. Upsampled mask</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVzP34IgZucNw2BsEMuKNFz3_XTjGB1rZHjoDh9CCj3f5bZ-BtEj_AOq6Bo6lLN4xxrT8vFQCN_r2-wIm5AT-ka7e5U-zJwziWyuEM3Khs2wF790Ng3Gl-xogUSa5H7mC4z4JN/s1600/final_result.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVzP34IgZucNw2BsEMuKNFz3_XTjGB1rZHjoDh9CCj3f5bZ-BtEj_AOq6Bo6lLN4xxrT8vFQCN_r2-wIm5AT-ka7e5U-zJwziWyuEM3Khs2wF790Ng3Gl-xogUSa5H7mC4z4JN/s1600/final_result.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig 5. Final result</td></tr>
</tbody></table>
Here is the result <b>without the downsampling strategy</b>:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgc1FC5ELuNVVU1ZYxAy7uVynilRKITAENLkxYTxoP3Jqra8AgEtipXo6vCDI5LgBZKj2_B6xiNH72YJZ2OsTWedULGQoRnPF0nZPUm3QncrY8adySy4f0IeRYBU_gj_IOXMZ_1/s1600/final_result_wo_downsampling.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgc1FC5ELuNVVU1ZYxAy7uVynilRKITAENLkxYTxoP3Jqra8AgEtipXo6vCDI5LgBZKj2_B6xiNH72YJZ2OsTWedULGQoRnPF0nZPUm3QncrY8adySy4f0IeRYBU_gj_IOXMZ_1/s1600/final_result_wo_downsampling.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig 6. GrabCut result without downsampling</td></tr>
</tbody></table>
<br />
Comparing Figure 5 and 6, we can easily notice the differences between the segmented results. When applying the downsampling strategy, some image details were lost and the mask would be different and had rougher edges as well.<br />
<br />
Although the downsampling strategy has the drawback of losing image details, the benefit of reducing processing time was significant. The following table lists the processing time obtained by using above code with and without the downsampling strategy.<br />
<br />
<style type="text/css">
table.tableizer-table {
border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif
font-size: 12px;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #ccc;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style><br />
<table class="tableizer-table">
<tbody>
<tr class="tableizer-firstrow"><th></th><th>processing time (sec.)</th><th>without downsampling</th><th>with downsampling</th></tr>
<tr><td>debug mode</td><td>GrabCut</td><td>3.078</td><td>0.717</td></tr>
<tr><td></td><td>Total</td><td>3.101</td><td>0.756</td></tr>
<tr><td>release mode</td><td>GrabCut</td><td>0.599</td><td>0.123</td></tr>
<tr><td></td><td>Total</td><td>0.619</td><td>0.157</td></tr>
</tbody></table>
<br />
---<br />
[1] <a href="http://hiankun.blogspot.tw/2013/08/try-grabcut-using-opencv.html" target="_blank">Try GrabCut using OpenCV</a><br />
[2] <a href="http://stackoverflow.com/questions/3220477/how-to-use-clock-in-c" target="_blank">How to use clock() in C++</a>THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-19347878453374407302013-08-02T16:42:00.002+08:002013-08-02T16:42:37.855+08:00Building OpenCV libs and dlls using CMake in Windows 7(This is a simple note of my building process.)<br />
<br />
As mentioned in <a href="http://hiankun.blogspot.tw/2013/08/try-grabcut-using-opencv.html" target="_blank">the previous post</a>, in which I tried the GrabCut by using the OpenCV's library. Because I didn't have libs and dlls for debug mode, so I tried to use <a href="http://www.cmake.org/" target="_blank">CMake</a> to build them for my own usage.<br />
<br />
First I went to OpenCV website to <a href="http://opencv.org/downloads.html" target="_blank">download</a> the latest stable version 2.4.6. The source code for Windows were packed in a exe file. Don't worry about it, just download it and click it and the 7zip will extract the whole source package for you. In my case, the extracted folder was named ``opencv''. <br />
<br />
Then I lauched CMake GUI, chose the location where the extracted folder was located, and chose the build directory for the building files.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhklUAnHHNvcFjnK4JolHMoH1_K9CoumyfYV5rHSdBBVOSkSelf9Pz2rJBKvWrM3dnTpUKfw9nDzNHYi3AsGCGY6CiTFTX6zs__FMOHTnlUIlrglK87hyphenhyphen5kOcR5UF0kSYo0-kVx/s1600/cmake_gui.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhklUAnHHNvcFjnK4JolHMoH1_K9CoumyfYV5rHSdBBVOSkSelf9Pz2rJBKvWrM3dnTpUKfw9nDzNHYi3AsGCGY6CiTFTX6zs__FMOHTnlUIlrglK87hyphenhyphen5kOcR5UF0kSYo0-kVx/s1600/cmake_gui.jpg" /></a></div>
<br />
<br />
Click the ``Configure'' button and if everything is okay then the ``Generate'' button. In my case, I'd chosen the generator as ``Visual Studio 2005'' (at a certain step I didn't rememberd0, so the generating result contained an <span style="font-family: "Courier New",Courier,monospace;"><b>OpenCV.sln</b></span> in the build folder.<br />
<br />
The final step was just click the <span style="font-family: "Courier New",Courier,monospace;"><b>OpenCV.sln</b></span> to launch the Visual Studio and then Build the project for Debug and Release mode. The products were located in the <span style="font-family: "Courier New",Courier,monospace;">build/bin</span> and <span style="font-family: "Courier New",Courier,monospace;">build/lib</span> directories.THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-72929345005760135512013-08-02T16:20:00.000+08:002013-08-08T13:47:50.094+08:00Try GrabCut using OpenCV<script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.js" type="text/javascript">
</script><script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shBrushCpp.js" type="text/javascript">
</script><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.css" rel="stylesheet" type="text/css"></link><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shThemeDefault.css" rel="stylesheet" type="text/css"></link>
I was considering using <a href="http://research.microsoft.com/en-us/um/cambridge/projects/visionimagevideoediting/segmentation/grabcut.htm" target="_blank">GrabCut</a> to cut out the target in one of my working project. After <a href="https://github.com/Itseez/opencv/blob/master/samples/python2/grabcut.py" target="_blank">testing it using Python</a>, I thought it's necessary to try it in C++ code. Therefore I started to find some example code and picked one for my test [1].<br />
<br />
Here is my test code, the sample photo, and the result:<br />
<br />
<pre class="brush:cpp">#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
// Open another image
Mat image;
image = cv::imread("sunflower02.jpg");
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
// define bounding rectangle
int border = 20;
int border2 = border + border;
cv::Rect rectangle(border,border,image.cols-border2,image.rows-border2);
cv::Mat result; // segmentation result (4 possible values)
cv::Mat bgModel,fgModel; // the models (internally used)
// GrabCut segmentation
cv::grabCut(image, // input image
result, // segmentation result
rectangle,// rectangle containing foreground
bgModel,fgModel, // models
1, // number of iterations
cv::GC_INIT_WITH_RECT); // use rectangle
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,result); // bg pixels not copied
// draw rectangle on original image
cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1);
cv::namedWindow("Image");
cv::imshow("Image",image);
// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);
waitKey();
return 0;
}
</pre>
<script type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all()
</script>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif3NYEp5PxOcFlbPx-UEeBFAFhi0K-dzwZ8cPLBle8yLEI2vx8gNXO9aTqQSFnwfQnB-bx9CuKzj7-jxs-WLUA_yixebVj8nQGLX1DfzEF1o_FaWtf4jaAz7N1BtQ3O-bvRMJN/s1600/sunflower02.jpg" style="margin-left: auto; margin-right: auto;" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The sample photo used in the test</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjoVPP4pY5WnURiWbddSupO2q5Kwbeda5Ub1iXgAW6w6fSggn6idqGbSAUYqowfFoVfGM_tHdgJHn3FDOif2Kbma3Sd4OsTLYNvsTG4tN-iynUPj8a6UGhUtyraWwW4Fw9RWj1/s1600/grabcut_sunflower.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjoVPP4pY5WnURiWbddSupO2q5Kwbeda5Ub1iXgAW6w6fSggn6idqGbSAUYqowfFoVfGM_tHdgJHn3FDOif2Kbma3Sd4OsTLYNvsTG4tN-iynUPj8a6UGhUtyraWwW4Fw9RWj1/s1600/grabcut_sunflower.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The result of applying GrabCut</td></tr>
</tbody></table>
<br />
During the test, I encountered an old problem to me, which had been some odd runtime bugs for the debug mode when using OpenCV. The solution might be NOT to mix up the debug and release libraries [2].<br />
<br />
Oh, by the way, the processing time of the GrabCut was too long (about 2 seconds in the test case), and I thought it's not feasible for realtime applications. Orz<br />
<br />
---<br />
[1] <a href="http://stackoverflow.com/questions/15536222/opencv-grabcut-algorithm-example-not-working">http://stackoverflow.com/questions/15536222/opencv-grabcut-algorithm-example-not-working</a><br />
[2] <a href="http://stackoverflow.com/a/2590795/1024813">http://stackoverflow.com/a/2590795/1024813</a> THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com1tag:blogger.com,1999:blog-21954772.post-73743160570305852362013-08-01T11:04:00.001+08:002013-08-01T11:05:31.157+08:00cv2.waitKey bug<script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.js" type="text/javascript">
</script><script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shBrushPython.js" type="text/javascript">
</script><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.css" rel="stylesheet" type="text/css"></link><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shThemeDefault.css" rel="stylesheet" type="text/css"></link>
I was trying a <a href="http://research.microsoft.com/en-us/um/cambridge/projects/visionimagevideoediting/segmentation/grabcut.htm" target="_blank">Grabcut</a> <a href="https://github.com/Itseez/opencv/blob/98960bf201f6ec51f28dfda067d670bb9f85c31b/samples/python2/grabcut.py" target="_blank">sample code (don't use this version)</a> written in Python by <a href="http://www.opencvpython.blogspot.tw/" target="_blank">abid rahman</a> and stuck at a strange problem: the cv2.waitKey() didn't work normally!<br />
<br />
Yesterday I searched the problem on Google and found nothing useful (according to my skill level, I might overlooked something that could be hints), so I decided to ask in the <a href="https://plus.google.com/communities/103393744324769547228" target="_blank">G+ Python community</a> [1].<br />
<br />
Based on <a class="Sg Ob qm" href="https://plus.google.com/103907784711341411465" rel="nofollow">Brett Ponsler</a>'s helpful suggestion, I tried to rewrite my test code and also went <a href="https://github.com/Itseez/opencv/blob/master/samples/python2/grabcut.py" target="_blank">to download the Grabcut sample code again (this version is fine)</a>. This time, the sample code was running successfully.<br />
<br />
Then I noticed a magic word ``0xFF'' in the new downloaded sample code. Using the hint, I finally found <a href="http://code.opencv.org/issues/2910" target="_blank">the bug report</a> about cv2.waitKey() and came up with a tiny test code:<br />
<br />
<pre class="brush:py; highlight: [17,18]">import cv2
import numpy as np
cv2.namedWindow('test')
while True:
#key = cv2.waitKey(33) #this won't work
#key = 0xFF & cv2.waitKey(33) #this is ok
key = np.int16(cv2.waitKey(33)) #this is ok [2]
if key == 27:
break
else:
print key, hex(key), key % 256
cv2.destroyAllWindows()
</pre>
---<br />
[1] The question I posted in the Python community: <a href="https://plus.google.com/117911423781149907976/posts/CdvQ3vWVV19">https://plus.google.com/117911423781149907976/posts/CdvQ3vWVV19</a><br />
[2] <a href="http://jiaxihu.blogspot.tw/2013/02/opencv-python-64bit-waitkey.html">http://jiaxihu.blogspot.tw/2013/02/opencv-python-64bit-waitkey.html</a>
<script type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all()
</script>THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-85240136788203958482013-07-31T10:01:00.000+08:002013-07-31T10:03:31.341+08:00Trying sklearn for machine learning (with the face recognition sample)I was trying to evaluate the feasibility of a project, and Python of course was my first choice. During the build-up of the developing environment, however, I was frustrated due to the installation of <a href="http://scikit-learn.org/stable/" target="_blank">scikit-learn</a> package.<br />
<br />
<span style="color: blue;"><i>Quick tip: download the latest stable version (0.14a1) of scikit-learn and play with the sample code given in the source package. </i></span><br />
<br />
<b><span style="font-size: large;">
Installation by pip (failed)</span></b><br />
<br />
The first frustration might be caused by my stupidity.<br />
<br />
I followed <a href="http://scikit-learn.org/stable/install.html" target="_blank">the instruction on the scikit-learn page</a> and used pip to complete the installation. Then I googled <a href="http://www.tp.umu.se/~nylen/pylect/advanced/scikit-learn/index.html#putting-it-all-together-face-recognition" target="_blank">an example code</a> and found it couldn't be run successfully. The Python interpreter always complained with<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">ImportError: cannot import name scikits.learn</span></blockquote>
I googled for the solution again and again, and found all the <a href="http://stackoverflow.com/questions/13212987/cannot-import-scikits-learn-even-though-it-seems-to-be-installed" target="_blank">answer</a>s pointed to ``multiple versions of Python installed in the system.'' But I have only Python 2.7 in my Ubuntu!<br />
<br />
What I had done was uninstall the scikit-learn and reinstall. Also I tried to install it from the source, but nothing changed.<br />
<br />
Then I thought of something and tried to find some sample code on the scikit-learn page. It turned out that the module should be <span style="color: blue;"><b>sklearn</b></span> instead of <span style="color: red;"><b>scikits.learn</b></span>... Orz<br />
<br />
So what I had found was a sample code using old module names.<br />
<br />
<br />
<b><span style="font-size: large;">
Using version 0.13.1 (failed)</span></b><br />
<br />
I am not sure whether this is a bug. I could not run the example code (fa_recognition.py) located in the source package of version 0.13.1. When my scikit-learn modules were also the version 0.13.1. The error message was:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">ImportError: cannot import name column_or_1d</span></blockquote>
and I found ``import sklearn.datasets'' would trigger this error.<br />
<br />
I also tried to follow the traceback message given by the interpreter but only knew it was due to an importing of label.py. My skill on debugging couldn't bring me further.<br />
<br />
<br />
<b><span style="font-size: large;">
Verion 0.14a1 (Succeeded)</span></b><br />
<br />
Okay, I'd run out my approaches... I almost gave up, but then I thought of the possibility of using the latest version to solve the problem. So I downloaded the source of version 0.14a1 and installed it. Finally, I got the sample code run with expected outputs.<br />
<br />
<b><span style="font-size: large;">
Face recognition example test</span></b><br />
<br />
If you have downloaded the source package, you can find the example in the path of: <span style="font-family: "Courier New",Courier,monospace;">YOUR_FOLDER/scikit-learn-0.14a1/examples/applications/face_recognition.py</span>.<br />
<br />
Frankly, I have no idea about the output yet, but I would like to post the text output of running <span style="font-family: "Courier New",Courier,monospace;">face_recognition.py</span> with the figures of result.<br />
<br />
<h3>
Text output</h3>
<br />
<pre>===================================================
Faces recognition example using eigenfaces and SVMs
===================================================
The dataset used in this example is a preprocessed excerpt of the
"Labeled Faces in the Wild", aka LFW_:
http://vis-www.cs.umass.edu/lfw/lfw-funneled.tgz (233MB)
.. _LFW: http://vis-www.cs.umass.edu/lfw/
Expected results for the top 5 most represented people in the dataset::
precision recall f1-score support
Gerhard_Schroeder 0.91 0.75 0.82 28
Donald_Rumsfeld 0.84 0.82 0.83 33
Tony_Blair 0.65 0.82 0.73 34
Colin_Powell 0.78 0.88 0.83 58
George_W_Bush 0.93 0.86 0.90 129
avg / total 0.86 0.84 0.85 282
2013-07-31 08:04:43,243 Downloading LFW metadata: http://vis-www.cs.umass.edu/lfw/pairsDevTrain.txt
2013-07-31 08:04:46,028 Downloading LFW metadata: http://vis-www.cs.umass.edu/lfw/pairsDevTest.txt
2013-07-31 08:04:46,740 Downloading LFW metadata: http://vis-www.cs.umass.edu/lfw/pairs.txt
2013-07-31 08:04:48,140 Downloading LFW data (~200MB): http://vis-www.cs.umass.edu/lfw/lfw-funneled.tgz
2013-07-31 08:11:24,620 Decompressing the data archive to /home/thk/scikit_learn_data/lfw_home/lfw_funneled
2013-07-31 08:11:33,822 Loading LFW people faces from /home/thk/scikit_learn_data/lfw_home
2013-07-31 08:11:33,981 Loading face #00001 / 01288
2013-07-31 08:11:36,218 Loading face #01001 / 01288
Total dataset size:
n_samples: 1288
n_features: 1850
n_classes: 7
Extracting the top 150 eigenfaces from 966 faces
done in 0.806s
Projecting the input data on the eigenfaces orthonormal basis
done in 0.065s
Fitting the classifier to the training set
done in 16.244s
Best estimator found by grid search:
SVC(C=1000.0, cache_size=200, class_weight=auto, coef0=0.0, degree=3,
gamma=0.001, kernel=rbf, max_iter=-1, probability=False,
random_state=None, shrinking=True, tol=0.001, verbose=False)
Predicting people's names on the test set
done in 0.049s
precision recall f1-score support
Ariel Sharon 0.67 0.78 0.72 18
Colin Powell 0.77 0.80 0.78 61
Donald Rumsfeld 0.71 0.76 0.73 29
George W Bush 0.90 0.89 0.89 134
Gerhard Schroeder 0.71 0.63 0.67 27
Hugo Chavez 0.93 0.58 0.72 24
Tony Blair 0.69 0.83 0.75 29
avg / total 0.81 0.80 0.80 322
[[ 14 2 1 1 0 0 0]
[ 3 49 1 3 0 1 4]
[ 1 3 22 2 0 0 1]
[ 2 6 4 119 1 0 2]
[ 1 1 1 4 17 0 3]
[ 0 3 1 0 5 14 1]
[ 0 0 1 3 1 0 24]]
</pre>
<br />
<h3>
Figures</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlHgl-23Zs_IiQFrlxaXrYW1___pzrRTaHrlY5tb86Z-R4IFXsUOBBJA53r6vYLKw4FmKrJ0gWFW2xg8WeFjBzrCHAybnpDFX9KySJl8ADdi_3uNN_xzp1vWN4FekJAPePPvvz/s1600/Figure1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlHgl-23Zs_IiQFrlxaXrYW1___pzrRTaHrlY5tb86Z-R4IFXsUOBBJA53r6vYLKw4FmKrJ0gWFW2xg8WeFjBzrCHAybnpDFX9KySJl8ADdi_3uNN_xzp1vWN4FekJAPePPvvz/s640/Figure1.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinbhxKUoNrFKxy6yzHhXii6iGpZn9dey92baqcfBaa_hG4xs60uzDonMPj3o-Y_fF0v_fH-PHCBjqwSHE591QCgfR37PUOn3gH7bFAF1hw26I_sPGw0kY3tkNQYmtXaPDNkOuM/s1600/Figure2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinbhxKUoNrFKxy6yzHhXii6iGpZn9dey92baqcfBaa_hG4xs60uzDonMPj3o-Y_fF0v_fH-PHCBjqwSHE591QCgfR37PUOn3gH7bFAF1hw26I_sPGw0kY3tkNQYmtXaPDNkOuM/s640/Figure2.png" width="640" /></a></div>
<br />THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0tag:blogger.com,1999:blog-21954772.post-37174662970466532482013-07-31T08:20:00.001+08:002013-07-31T08:21:06.169+08:00Compiling NiSimpleViewer -- from Kinect OpenNI sample code<script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.js" type="text/javascript">
</script><script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shBrushCpp.js" type="text/javascript">
</script><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.css" rel="stylesheet" type="text/css"></link><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shThemeDefault.css" rel="stylesheet" type="text/css"></link>(This was an old article kept in draft state for about four months) <br />
<br />
In previous post I installed the OpenNI SDK and tested some of its samples [1]. I am trying to study something from the sample code and what I've chosen now is the <span style="font-family: "Courier New",Courier,monospace;">NiSimpleViewer</span> example (which can be found in <span style="font-family: "Courier New",Courier,monospace;">openni/Samples/NiSimpleViewer</span>).<br />
<br />
To avoid messing up the original sample code, I copied the whole directory of <span style="font-family: "Courier New",Courier,monospace;">NiSimpleViewer</span> and renamed it to <span style="font-family: "Courier New",Courier,monospace;">mySimpleViewer</span>.<br />
<br />
The first work was to compile the source code. Of course the samples included makefiles but they were used for more general and more complicated cases. What I needed was just a simple and self-contained makefile. My first attempt was to simplify the makefile, but unfortunately it's too complicate for me to understand or even to modify it. So I wrote a simple one as the follows (I knew it's unnecessary to do so for such a simple case, but I just wanted to do a bit of exercise on writing makefiles.) :<br />
<br />
<pre class="brush:cpp">CC = g++
CFLAGS = -g -Wall
LDFLAGS = -lglut -lOpenNI -I /usr/include/ni
EXECUTABLE = mySimpleViewer
SOURCES = $(EXECUTABLE).cpp
OBJECTS = $(EXECUTABLE).o
all:
$(CC) $(CFLAGS) -o $(EXECUTABLE) $(SOURCES) $(LDFLAGS)
</pre>
<br />
<br />
After running <span style="font-family: "Courier New",Courier,monospace;">mySimpleViewer</span>, the program complained that the file <span style="font-family: "Courier New",Courier,monospace;">SamplesConfig.xml</span> cannot be found. I checked the source code as well as the files in related directories and found the path should be changed from<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">../../Config/SamplesConfig.xml</span></blockquote>
to<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">../Config/SamplesConfig.xml</span></blockquote>
In fact the relative path for the source code to find the xml file is ``../Config'' but not ``../../Config''. This was because the original Makefile putted the binaries in openni/Samples/Bin/Release/ which was one more directory deeper than my test example (thanks to my colleague's reminder).<br />
<br />
Also, I modified some #define macros to const type. Based on my knowledge, this would be more ``c++ style''.
<br />
<pre class="brush:cpp">const XnChar* SAMPLE_XML_PATH = "../Config/SamplesConfig.xml";
const int GL_WIN_SIZE_X = 1280;
const int GL_WIN_SIZE_Y = 1024;
const unsigned int DISPLAY_MODE_OVERLAY = 1;
const unsigned int DISPLAY_MODE_DEPTH = 2;
const unsigned int DISPLAY_MODE_IMAGE = 3;
const unsigned int DEFAULT_DISPLAY_MODE = DISPLAY_MODE_DEPTH;
</pre>
<script type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all()
</script>
---<br />
[1] <a href="http://hiankun.blogspot.tw/2013/03/test-kinect-in-ubuntu-1204.html" target="_blank">Test Kinect in Ubuntu 12.04</a>
THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com2tag:blogger.com,1999:blog-21954772.post-75585737092148389232013-07-15T01:57:00.004+08:002013-07-15T01:59:31.569+08:00Network problems of Linux MintI have installed and used Linux Mint (Maya) on my Toshiba Satellite for several months. The network setting has always troubled and annoyed me, especially the wireless one.<br />
<br />
I had encountered three problems:<br />
<ol>
<li>If the cable doesn't connect to the laptop or the network is not working, the system always wait for a long time with the messages read:<br /><blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">``Waiting for network configuration...''<br />
``Waiting up to 60 more seconds for network configuration...''</span></blockquote>
</li>
<li>When the network is interrupted, it won't recover automatically.So every time I close the laptop lid to sleep the system and open it to resume it, I have to open the terminal and type ``<span style="font-family: "Courier New",Courier,monospace;">sudo pon dsl-provider</span>'' to get the network connection back.</li>
<li>I couldn't connect to my wireless network at home, and found nowhere to get the settings done. My wireless network has been set as hidden, and I have added it in the Network Connections. But when I tried to connect it, the icon always showed the processing state and the connection was never done.</li>
</ol>
Today I got all these problems solved and I am happy now.<br />
<br />
Here are the solutions I found and tested successfully:<br />
<ol>
<li>Edit the file: <b>/etc/init/failsafe.conf</b><br />
Find the lines with ``<span style="font-family: "Courier New",Courier,monospace;">sleep</span>'' and comment out the two which related to the system messages just mentioned above.</li>
<li>Reinstall network-manager by<br /><blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">sudo apt-get --reinstall install network-manager</span></blockquote>
and use the following command to start the manager:<br /><blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">sudo /etc/init.d/network-manager restart</span></blockquote>
</li>
<li>Edit the file: <b>/etc/NetworkManager/NetworkManager.conf</b><br />
change ``<span style="font-family: "Courier New",Courier,monospace;">managed=false</span>'' to ``<span style="font-family: "Courier New",Courier,monospace;">managed=true</span>''<br />
restart the network manager by<br /><blockquote>
<span style="font-family: "Courier New",Courier,monospace;">
sudo /etc/init.d/network-manager restart</span></blockquote>
After doing these, the available wireless network will show up. My hidden wireless network still couldn't be connected so I tried to click its icon and a window popped out for me to enter the password. I inputed the password and everything went as expected as shown in the figure:<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisQaJIFY7IwvvyMYkOaE3QxMLdSwI_BmIoWZVJ_9tpRgjzoZpARowgXOp-ol-KxnuuDfBQopAxqyP3REaYC7JyGdZ8uDYKHLrskfVsNqJZwlTgWNuQ3IQ6_6pDg_o6fLiUxeae/s1600/network.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisQaJIFY7IwvvyMYkOaE3QxMLdSwI_BmIoWZVJ_9tpRgjzoZpARowgXOp-ol-KxnuuDfBQopAxqyP3REaYC7JyGdZ8uDYKHLrskfVsNqJZwlTgWNuQ3IQ6_6pDg_o6fLiUxeae/s320/network.png" width="320" /></a></div>
</li>
</ol>
--- <br />
ref:<br />
<a href="http://forums.linuxmint.com/viewtopic.php?f=150&t=110218">http://forums.linuxmint.com/viewtopic.php?f=150&t=110218</a><br />
<a href="http://ubuntuforums.org/showthread.php?t=1528695&p=9575190#post9575190" target="_blank">http://ubuntuforums.org/showthread.php?t=1528695&p=9575190#post9575190</a>THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com6tag:blogger.com,1999:blog-21954772.post-20746598162249830092013-05-20T14:40:00.001+08:002013-05-20T14:54:26.398+08:00i3 -- a tiling window manager<script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.js" type="text/javascript">
</script><script src="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shBrushBash.js" type="text/javascript">
</script><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shCore.css" rel="stylesheet" type="text/css"></link><link href="https://sites.google.com/site/hiankun/home/syntaxhighlighter/shThemeDefault.css" rel="stylesheet" type="text/css"></link>
I had used <a href="https://code.google.com/p/wmii/" target="_blank">wmii</a> for several months, and almost forgot it till today when my Ubuntu 12.04 stuck. I launched <a href="http://en.wikipedia.org/wiki/Top_(software)" target="_blank">top</a> and found the <a href="http://www.compiz.org/" target="_blank">compiz</a> consumed most of the resource of my PC. Of course I didn't find out the cause (due to my time and my skill level) and finally restart the system in command line mode.<br />
<br />
So I recalled wmii the wonderful and lightweight window manager.<br />
<br />
But I also recalled some reasons which prevented me using wmii as my main window manager:<br />
<br />
<ol>
<li>I didn't know how to make wmii show the system panel (that was the gnome panel) which keeps something like volume controls and daemon icons of <a href="http://code.google.com/p/ibus/" target="_blank">ibus</a> and <a href="https://www.google.com/search?client=ubuntu&channel=fs&q=Dropbox&ie=utf-8&oe=utf-8" target="_blank">Dropbox</a>, etc.</li>
<li>I have had two monitors and didn't know how to make wmii work with dual-monitor setting</li>
</ol>
<br />
I did some quick search and found an interesting article written by Tanguy: <a href="http://tanguy.ortolo.eu/blog/article85/tiling-wm" target="_blank">Tiling window managers</a>.<br />
<br />
The article listed three tilting window managers among which I've only used wmii. I heard of <a href="http://awesome.naquadah.org/" target="_blank">awesome</a> but haven’t try it yet. After reading Tanguy's introduction, I decided to try i3.<br />
<br />
I also did some more search about the system panel and finally got what I want. I listed some setting in my i3 configuration file (~/.i3/config):<br />
<br />
<pre class="brush:bash"># start-ups
exec unity-2d-panel
exec nm-applet
exec ibus-daemon
exec dropbox start -i
exec ~/Downloads/copy/x86/CopyAgent
# for dual-monitor
exec xrandr --output DVI-I-1 --auto --left-of DVI-I-2
</pre>
<br />
where the DVI-I-1 and DVI-I-2 are my monitors detected by using the command <a href="http://linux.die.net/man/1/xrandr" target="_blank">xrandr</a>.<br />
<br />
Here is my working monitors with i3 as the window manager:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_schUUosuvrkOz-jGTDcq1zgJhSM2fBz3Ayo_2P7mAFhcPC5x_Y6hxaEN_l1ELj-yDiHZu3l24IsKQnFZHV-XBYnQU8rDGCwP5qGEVo97EIasArt5tzE46_PgMWxZC6S7RW4Z/s1600/i3_dual_monitor.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_schUUosuvrkOz-jGTDcq1zgJhSM2fBz3Ayo_2P7mAFhcPC5x_Y6hxaEN_l1ELj-yDiHZu3l24IsKQnFZHV-XBYnQU8rDGCwP5qGEVo97EIasArt5tzE46_PgMWxZC6S7RW4Z/s1600/i3_dual_monitor.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Using i3 window manager with dual monitors.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBKQHN6HtZDUzGzY-W97sMNv1_LDRKXrz6VYS56_hYbmKkok9_GAR4MsJa5AwD9gY6H5KZrFYZIWb5dToIZuT9wI_aGbiD3jVLmXfwlUWubrfTOhugvCPjed7rG9vxERIbcA88/s1600/i3_dual_monitor_unity_panel.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBKQHN6HtZDUzGzY-W97sMNv1_LDRKXrz6VYS56_hYbmKkok9_GAR4MsJa5AwD9gY6H5KZrFYZIWb5dToIZuT9wI_aGbiD3jVLmXfwlUWubrfTOhugvCPjed7rG9vxERIbcA88/s1600/i3_dual_monitor_unity_panel.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Close-up of the Unity panel.</td></tr>
</tbody></table>
<br />
I am not sure whether I got the dual-monitor setting right. In my case, the monitors show two different workspace but not a single workspace with extension monitor.<br />
<script type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all()
</script>THKhttp://www.blogger.com/profile/10803822820165706025noreply@blogger.com0