Friday, November 14, 2014

OpenCV ORB feature matching test

Code is available here:

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.

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.

I have not test the matching approach by using SURF or SIFT features. This will be the next step.

Furthermore, I will try to apply findHomography() and getPerspectiveTransform() to find the correct object.

Adding my project to GitHub

Finally, I pushed my own test project on GitHub!!

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.

Actually I was slightly scared by the complexity of git, especially its mystical jargon such as rebase, merge, cherry-pick and so on.

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.

Oh, before I dived into GitHub, I found the following links helped a lot:
1. try Git, an interactive tutorial to give you a basic understanding;
2. Adding an existing project to GitHub using the command line

Monday, November 10, 2014

Test OpenCV on BeagleBone Black using Logitech C920

Here are some basic trials in which I tested OpenCV running on my BBB.

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).

[NOTE: the following videos were boring and showed nothing exciting... :-p]
[Sorry for the small view of the videos. I will find how to enlarge them later...]
[I've uploaded the video clips so that you can view them with better resolution.]

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.

The second one showed the result without cv::imshow() via VNC. The processing time seemed reduced, but not significantly.

The last one showed the result without cv::imshow() via ssh. The processing time was no more than 100ms.

It seemed that the VNC costed most of the computing resource.

The test code was:

#include <stdio.h>
#include "opencv2/opencv.hpp"                                                                         
int main() {                                                                                          
    cv::VideoCapture cap(0);
        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;                                                                                         

BeagleBone Black Wifi connection and VNC settings (Debian)

As mentioned in my previous post (Setting up the Wifi connection of BeagleBone Black (Angstrom)), I couldn't make Wifi connection with the Angsrom images, and decided to test Debian image again.

[A brief note for my first test with the Debian image]
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.

The Debian image was large. After the installation, I checked the disk usage by typing ``df -h''... 93% used... It's crazy.

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.

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: BeagleBone Black Ubuntu WiFi Installation and Troubleshooting Guide.

PART 1 Wifi settings

Step 1: 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.''

Step 2: Check ``/etc/rcn-ee.conf'' and make sure it contain the following settings:
Step 3: Edit ``/etc/network/interfaces'' with the following settings:
auto ra0
iface ra0 inet dhcp 
wpa-ssid your_network_name
wpa-psk your_hashed_password 
Finally, restart the BBB system.

PART 2 VNC settings

This part was easy. All the steps were the same as that of my another previous post (Connect to Beaglebone Black via VNC client in Ubuntu 12.04). The only different setting was the starting command of the VNC server (the BBB):
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/lightdm/root/:0 -forever

Friday, November 07, 2014

Two copies of clang_complete makes vim throw error messages

Recently I found there was error messages when I open C/C++ files in Vim (see the following photo).

So I googled, and installed so-called libclang-dev. After the installation, the error message became more terrible:


Fortunately, I spotted a thread of clang_complete in GitHub, and the author's comment was the solution for me.

I must had installed the clang_complete manually and then it has been installed again by Vundle. :-p

Other useful link found during the search:
clang_complete can be configured to use the clang executable or the clang library

Tuesday, November 04, 2014

Failed to ssh into Beaglebone Black

Yesterday 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 the webpage still worked). The terminal responded nothing, and it just hanged there without logging in.

The Cloud9 IDE 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).

I searched and tested, the first script given in the mail list [2] didn't work to me. It returned ``it seems that you have another problem, sorry.''

Then I tested the second script [3]. After running that script I logged in BBB via ssh again.

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.


I read the mail list again and found the post which listed the second script had said something may be useful. It talked about systemd-journal settings.

[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 VAT's article and knew that I should use cross-compilation.

[2] The script:

var fs = require('fs');
var destroyed_key_file = '/etc/dropbear/dropbear_rsa_host_key';

fs.readFile(destroyed_key_file, function (err, data) {
  if (err) throw err;
  if( data===null || data.length===0 )
    console.log("we have a corrupted host key file... try do delete it");
    fs.unlink(destroyed_key_file, function (err) {
    if (err) throw err;
        console.log('successfully deleted ' + destroyed_key_file);
        console.log('you should now reboot your beaglebone.');
        console.log('the /etc/init.d/dropbear script will create a new rsa host key file for you.');
        console.log('after the reboot you should be able to login over ssh');
  } else {
      console.log("it seems that you have another problem, sorry");

[3] The script worked for me:

var exec = require('child_process').exec;
function puts(error, stdout, stderr) { console.log(error); console.log(stdout); console.log(stderr); }

// 1 - Clear journal space
exec("df -h; rm -rf /var/log/journal/; df -h", puts);

// 2 - Remove Dropbear file
exec("rm /etc/dropbear/dropbear_rsa_host_key", puts);

// 3 - Stop Dropbear
exec("/etc/init.d/dropbear stop", puts);

// 4 - Start Dropbear
exec("/etc/init.d/dropbear start", puts);

Monday, November 03, 2014

Connect to Beaglebone Black via VNC client in Ubuntu 12.04

I am planning to run OpenCV sample code in the BBB, and some graphic outputs are necessary.

After some searches and tests, I made it. Here is the minimal steps.

Step 1: Make sure there's x11vnc in BBB which acts as the VNC server.

Step 2: SSH to BBB and run the following command:
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/gdm/auth-for-gdm*/database -display :0 -forever
The terminal will return the following message:

Step 3: Install xvncviewer in Ubuntu as the client viewer.

Step 4: Run xvncviewer and use ``'' to connect to BBB.

Here is the desktop of BBB:

Sunday, November 02, 2014

Some settings to enable the vim-airline

I've tried to add some plugins to make Vim a better IDE. The article has helped me alot: vim + packet manager = Vundle

Just several minutes ago, I added the vim-airline and did something to make it work in my vim (not gvim).

After some tests, the only thing I have to do was to add the following line in my .vimrc to enable 256 colors in vim:
set t_Co=256
Another useful setting was
set laststatus=2
which lets the vim-airline show the status bar even there's only one file opened.

If you want to replace the symbols with some Unicode ones, then the so-called patch fonts are needed. They can be found in

After installing the patched fonts, you can add the following settings in the .vimrc to enable the symbols:

if !exists('g:airline_symbols')
    let g:airline_symbols = {}

" unicode symbols
let g:airline_left_sep = '»'
let g:airline_left_sep = '▶'
let g:airline_right_sep = '«'
let g:airline_right_sep = '◀'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = '␤'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.paste = 'Þ'
let g:airline_symbols.paste = '∥'
let g:airline_symbols.whitespace = 'Ξ'

set guifont=DejaVu\ Sans\ Mono\ 10
let g:airline_powerline_fonts = 1

Here's my vim with the vim-airline:

Setting up the Wifi connection of BeagleBone Black (Angstrom)

The Wifi adaptor was UWN200

Several months ago, I've followed the course of ``Control of Mobile Robots'' on Coursera. Although I've finished the course, but the hardware part has been postponed for these months.

I determined to record the tests on the hardware, and here is the first post on the topic.

The following procedure based on the course lecture.

Step 0: I used my mobile phone as the Wifi hotspot for the BBB internet connection.

Step 1: Connect the USB cable between the BBB and the PC. Plug the Wifi adaptor as well.

Step 2: Log in BBB using ssh. Just type the follows in the terminal of host PC:
ssh -l root

Step 3: (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:
wpa_passphrase "your network name here" 'your password here'
Step 4: Paste the hashed string into /var/lib/connman/wifi.config. The content of the wifi.config looks like:
Type = wifi
AutoConnect = true
Favorite = true
Name = your network name
Passphrase = your hashed password

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 an old one, but got no luck.

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.

After trying for several days, I decided to go back to the Debian image again, and here is the note: BeagleBone Black Wifi connection and VNC settings (Debian).

Installing 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]

The main steps have been listed in the guidance page:

But my cmake options were as the follows:

Note that the WITH_IPP option had been disabled or there would be errors (which I didn't have time to tackle).

I also used lscpu 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 ``make -j16'' during the installation.

After the installation, I check the installed version by typing
pkg-config --modversion opencv
and it returned
Also, in ipython, typed the following command to check the installed version:
In [1]: import cv2
In [2]: print cv2.__version__
But after installing the new version, I couldn't run the python example of generating stereo image because there was no module named createStereoBM... O__Oa

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.

I just tried the ORB example, but the module was also disappeared from the 3.0.0 version.

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.

Friday, August 29, 2014

Some settings in Visual Studio 2008 for exporting dll and lib

(This is a working note.)

Suppose that we have a YourProject.cpp and its head file YourProject.h, and we want to export it as YourProject.dll and YourProject.lib in VS2008.

Also, suppose that we have some code to define the exporting flag in YourProject.h:

The steps were as the follows:

Step 1: In the existing solution, add a project for the source and head file (i.e., the YourProject.cpp and YourProject.h)

Step 2: Make sure that you set the project's Configuration Type to ``dll'':

Step 3: Add ``DLL_EXPORTS'' in the Preprocessor Definitions:

Friday, July 18, 2014

How to customize the resolution of CrunchBang in VirtualBox of Windows 7

Before you reading... here is a better solution to solve the problem of screen resolution:
How to install the Guest Additions for CrunchBang in VirtualBox of Windows 7

Host system: Windows 7 x64
Guest system: CrunchBang 11 ``Waldorf'' x64

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.

I mainly followed the instruction of the link: How to adjust the screen resolution in Debian?

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 ``~/.config/openbox/autostart'':

xrandr --newmode "1920x1002"  159.50  1920 2040 2240 2560  1002 1005 1015 1040 -hsync +vsync
xrandr --addmode VBOX0 "1920x1002"
xrandr --output VBOX0 --mode "1920x1002"

How to install the Guest Additions for CrunchBang in VirtualBox of Windows 7

After my installation of CrunchBang in VirtualBox, some functions such as ``Auto-resize Guest Display'' and ``Shared Clipboard'' were not available.

The key is to install the ``Guest Additions''.

I tried some instructions found on Web and the steps are listed as follows:

To install the following packages

This was simple, just install them:
apt-get install dkms build-essential linux-headers-generic

To  mount the Guest Additions image

Actually this confused me and I'm not sure about every details. Here I just write down what I've done for your reference.

The first thing I did was to insert the VBoxGuestAdditions.iso image via the GUI (I've selected the iso file before, so it appeared in the list automatically):

Then click the ``Insert Guest Additions CD image...'' or use the following command to mount the image:
mount /dev/sr0 /media/cdrom
Now we can find the ``'' script and run it:

And the Guest Additions should be installed. :-)

More details could be found here: HOWTO: Install Linux Guest Additions + Xorg config
and here: