Install the latest cmake to Ubuntu

Step 1 : Download the latest and stable cmake from https://cmake.org/download/

I download the source of cmake with v3.7.1 to my Ubuntu 14.04.

Step2 : Extract the compressed file and build it

$ cd cmake-3.7.1
$ ./bootstrap --prefix=/usr
$ make
$ sudo make install

Step3 : Check it

$ cmake --version

Expected output:  cmake version 3.7.1


Make python program executable and compile for Windows exe on Linux

  This week, I spend some time to make one of my repositories, LablelImg,  on Github become an executable file. The LablelImg is implemented  in Python, and it has some dependencies like lxml and pyQt. In order to let other people use the tool easier without installing python and their dependencies, I decide to make it a standalone executable. I described as below about how I have done to compile it for Window exe and Linux binary on Ubuntu. In Python, there are some packages which can let python files become an executable file, e.g pyexe, pyinstaller, and so on.
Then, I decide to pick pyinstaller because its document and relevant reference are concise.

Environment : 

OS: Ubuntu 14.04
Necessary packages and tools :
  1.   wine (1.6.2)
  2.   pyinstaller (2.1)
  3.   virtual-wine (0.1)
  4.   python-2.7.8.msi
  5.   pywin32-218.win32-py2.7.exe 
  6.   PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe
  7.   lxml-2.3.win32-py2.7.exe
The steps to install or download them:
wine : $ apt-get install wine
pyinstaller : $ git clone https://github.com/pyinstaller/pyinstaller
virtual-wine : $ git clone https://github.com/htgoebel/virtual-wine.git
python-2.7.8 : Download from https://www.python.org/ftp/python/2.7.8/python-2.7.8.msi
pywin32-218.win32-py2.7 : Download from http://nchc.dl.sourceforge.net/project/pywin32/pywin32/Build%20218/pywin32-218.win32-py2.7.exe
PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe: https://www.riverbankcomputing.com/software/pyqt/download
lxml-2.3.win32-py2.7.exe : Download from  https://pypi.python.org/pypi/lxml/2.3/

Install packages to virtual env

Create a virtual wine environments using virtual-wine:
$ apt-get install scons
$ ./virtual-wine/vwine-setup venv_wine

Active virutal env:
$ . venv_wine/bin/activate

Use wine to install python packages to your virtual env: 
$ wine msiexec -i python-2.7.8.msi
$ wine pywin32-218.win32-py2.7.exe
$ wine PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe
$ wine lxml-2.3.win32-py2.7.exe

Build your python files using pyinstall under virtual environment

$ wine c:/Python27/python.exe pyinstaller/pyinstaller.py -D -F -n AppName -c "main.py" 
The exe file will be located under dist directory

Check out my scripts, you will be more clear

Check out my script to setup the environment and make pyQt executable.


Record Android touch event or other events

  Recently, I met a problem which I cannot use Android-unit-test to do some of the test cases. I browse through some of apps or tools, but they are not handy for me. So I wrote a simple python tool to record my Android events like touching, gyro, and so on. Then, I can use my tools on my PC to playback the events I recorded. It's very convenient for me to reproduce some issues.



[Ubuntu Network] Share internet connection from mobile phone to PC via USB


Go to Setting -> Network share -> Turn on USB network share


Configuring the PC that will connect to the network which is provided by Mobile phone. Open your Network Manager via the Network Icon on the Unity Panel.


Setup ssh connection on Ubuntu

Install necessary packages:

sudo apt-get update
sudo apt-get install openssh-server
sudo ufw allow 22
sudo apt-get install openssh-client

Connect usage:

ssh username@host


On the client side, create the host alias for ssh. Edit ~/.ssh/config, then copy the below pattern to the config file
Host workstation
User darrenl
Port 22
Then, we can simply the usage to connect to host
ssh workstation
Copy the public key to remote host using ssh-copy-id, thus, we didn't need to type password every time

ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host



Generate javadoc using gradle

In your build.gradle file, adding the below snipet of code can generate the java doc of your module

configurations {

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:support-annotations:${rootProject.ext.androidSupportSdkVersion}"    javadocDeps "com.android.support:support-annotations:${rootProject.ext.androidSupportSdkVersion}"}

task generateJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath()

    classpath += configurations.javadocDeps    failOnError false    destinationDir = file("../javaDoc/")
    exclude {


Auto-generating enum/constants for different languages like c++, java, python, and so on

  In the past, speaking of cross-language tools to serialize and auto-generate structured data, you might use Protobuf to do that, Recently, I start to use flatbuffers to serialize/deserialize and auto-generate my data structure. There are a lot of comparisons on Protobuf, json, and flatbuffers, you can refer to the below links:
Why consider flatbuffer over json
How much is flatbuffer faster protobuf
Primay differences between protbuf and flatbuffers

Today, I am going to demonstrate how to use flatbuffers to auto-generate enum/constants for different languages like c++, java, python, and so on.

Clone flatbuffers
git clone https://github.com/google/flatbuffers
cd flatbuffers
Depending on your platform, use one of e.g.
$ cmake -G "Unix Makefiles"
$ cmake -G "Visual Studio 10"
$ cmake -G "Xcode"
Start to build
$ make
After making it, there is one of executable files, called flatc. Now, we can use flatc to genereate different source files for different language using flatbuffers's interface definition language(IDL).

Create an IDL file
vi resultcode.fbs
namespace tzutalin.common;
enum ResultCode { SUCCESS = 0, TIME_OUT, UNKNOWN_ERROR }
Use the below command to generate its c++ header, python, and Java file.
$ ./flatc --cpp --python --java -b resultcode.fbs

After generating, it creates ./resultcode_generated.h, ./tzutalin/common/ResultCode.py, and ./tzutalin/common/ResultCode.java.

// automatically generated by the FlatBuffers compiler, do not modify
#include "flatbuffers/flatbuffers.h"
namespace tzutalin {
namespace common {
enum ResultCode {
  ResultCode_SUCCESS = 0,
  ResultCode_TIME_OUT = 1,
  ResultCode_UNKNOWN_ERROR = 2,
  ResultCode_MIN = ResultCode_SUCCESS,
  ResultCode_MAX = ResultCode_UNKNOWN_ERROR
inline const char **EnumNamesResultCode() {
  static const char *names[] = { "SUCCESS", "TIME_OUT", "UNKNOWN_ERROR", nullptr };
  return names;
inline const char *EnumNameResultCode(ResultCode e) { return EnumNamesResultCode()[static_cast<int>(e)]; }
}  // namespace common
}  // namespace tzutalin
# automatically generated by the FlatBuffers compiler, do not modify
# namespace: common
class ResultCode(object):
    SUCCESS = 0
    TIME_OUT = 1
// automatically generated by the FlatBuffers compiler, do not modify
package tzutalin.common;
public final class ResultCode {
  private ResultCode() { }
  public static final byte SUCCESS = 0;
  public static final byte TIME_OUT = 1;
  public static final byte UNKNOWN_ERROR = 2;
  public static final String[] names = { "SUCCESS", "TIME_OUT", "UNKNOWN_ERROR", };
  public static String name(int e) { return names[e]; }


Restore missing tools/status/menu bar in Ubuntu 16.04

  Recently, I upgraded my Ubuntu from 14.04 to 16.04. It works well after upgrading. But someday my toolbar and menu bar are missing after I updating some packages and rebooting. Then, I try to enable Unity Launcher again, my toolbar and menu are back. The below steps are what I do

1. $ sudo apt install compizconfig-settings-manager
2. $ ccsm
3. Enable Ubuntu Unity Plugin. It will ask some questions because enabling it conflicts with another one.


Use Rapidjson in cpp to read/write json file

  In C++, if you want to serialize, deserialize, prettify JSON, there are some libraries to allow you to do that, e.g. JsonCPP and RapidJson. Compare with JsonCpp and Rapidjon, Rapidjson is faster then JsonCPP. Besides, Rapidjson is a header-only library, so it is easy to include Rapidjon using the different build system, and I have tested and used Rapidjon on my Linux application and android native side.

  There is a snippet of code to serialize and deserialize Json file as bellow.

#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
#include <stdio.h>
#include <sys/stat.h>

using namespace rapidjson;
std::stringstream ss_date;
time_t t = time(0);
struct tm * now = localtime(&t);
ss_date << (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-'
        << now->tm_mday; 
StringBuffer s;
PrettyWriter<StringBuffer> writer(s);
// m_vWriteFilePath is a vector<std::string> which contains 0.mp3 1.mp3 ...
for (const auto& path : m_vWriteFilePath) {
std::ofstream of(m_indexFilePath);
of << s.GetString();
if (!of.good())
  throw std::runtime_error("Can't write the JSON string to the file!");
    "version": "1.0",
    "data": "2016-7-20",
    "file": [
using namespace rapidjson;
std::stringstream ss;
std::ifstream file(m_indexFilePath);
if (file) {
  ss << file.rdbuf();
} else {
  throw std::runtime_error("!! Unable to open json file");
Document doc;
if (doc.Parse<0>(ss.str().c_str()).HasParseError())
  throw std::invalid_argument("json parse error");
// Start parsing json string
std::string version = doc["version"].GetString();
std::string date = doc["data"].GetString();
const Value& array = doc["file"];
for (rapidjson::SizeType i = 0; i < array.Size(); i++) {


dx process limitation (dexOptions is specifying a maximum number of 2 concurrent dx processes, but the Gradle daemon was initialized with 4)

When I enable multidex and executing ./gradlew build command, I meet the problem about 'dx process limitation' when

Error message:

To initialize with a different maximum value, first stop the Gradle daemon by calling ‘gradlew —-stop’.
dexOptions is specifying a maximum number of 2 concurrent dx processes, but the Gradle daemon was initialized with 4.

To fix the problem, I change the maxProcessCount to 1 in my gradle file.

android {


  dexOptions {

        jumboMode = true // Eabled it to allow a larger number of strings in the dex files

        maxProcessCount 1 // The maximum number of concurrent processes that can be used to dex. Defaults to 4.

        threadCount 1 // Number of threads to use when running dx. Defaults to 4.

        dexInProcess false   //To disable dexing-in-process, add the following code to your module-level build.gradle file:

        preDexLibraries true // Whether to pre-dex libraries. This can improve incremental builds, but clean builds may be slower.



DEX 64K Reference Limit

When the source of your Android app grew too much or you use too much 3rd party libraries, you might meet DEX 64K Reference Limit. As you are building and install your APK, the error happens like below:

Conversion to Dalvik format failed:
Unable to execute dex: method ID not in [0, 0xffff]: 65536

What is DEX 64K Reference Limit 

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536(64K)—including Android framework methods, library methods, and methods in your own code.

How to resolve or avoid it

1. Use Proguard to shrinks, optimizes and obfuscates your code by removing unused code and renaming classes, fields and methods with semantically obscure names. I won't tell too in this article.

2. Enable multidex.Configure your app build process to generate more than one DEX file

3. Use Jar Jar Links utility repackage Java libraries, remove some unnecessary packages from 3rd parties libraries.



Fail to remount user/userdebug device after Andriod M

  After Android M, by default, Android OS will turn on system verified boot for user or userdebug build. It means it will fail to change or push any files under system partition.

  If your ROM is userdebug, you can use the below commands to remount system partition which will be able to read/write.
  $ adb root 
  $ adb disable-verity 
  $ adb reboot 
  $ adb wait-for-device 
  $ adb remount
adb disable-verity/enable-verit can only be executed if your ROM is userdebug, and you cannot remount system partition if your image is user build.

  If you can flash the image by yourself, you can build eng ROM which eng build will disable verified boot. Alternatively, you can disable verified boot by setting ro.secure to be 0 even if it is userdebug build. You can change the value of ro.secure in [AOSP]/build/core/main.mk, you can refer to the below screenshot.


Old versions of Android NDK and ndk download script


OpenCL on Android

Introduction and setup
  In android, Android/Google doesn't support OpenCL officially. Fortunately, many chip vendors like Qualquam90/ Nvidia/ Intel / MTK provide their libraries to support OpenCL on Android. 

  To use OpenCL on Android. If you want to use OpenCL, you need to check if there is OpenCL library on the device. You can download apps from Google Play to query OpenCL information like the version of OpenCL, device type, and benchmark tests. You can also go through List of Android Device with OpenCL support to see the benchmarks. 
The OpenCL libraries for the major chip vendors can be found in the devices. The followings are the location of the OpenCL library:

Qualquam(QUALCOMM Adreno)/Intel(HD Graphics)/Nvidia
or /system/lib/libOpenCL.so (older devices)
ARM Mali:
or /system/lib/egl/libGLES_mali.so
  1. Create NDK project to include OpenCL headers, compile your C/C++ code and link to CL shared library, and test them on the device as executable. Moreover, you can write JNI glue code and Java code to run on Java layer.

Quick setup and use Boost.Compute which is a GPU/parallel-computing library for C++ based on OpenCL.

You can refer to Boost.Compute-AndroidIf you like it, please give a star to this git repository.

Image annotation tool / Create bounding box for training images


Ubuntu 安裝新細明體


$ wget http://mingliu.myweb.hinet.net/MingLiu/MingLiU.zip ; uznip MingLiU.zip ;

$ sudo mkdir -p /usr/share/fonts/myfonts; sudo cp MingLiU.ttc /usr/share/fonts/myfont/新細明體.ttc

$ fc-cache -v /usr/share/fonts/myfonts

$ fc-list


Facial Landmarks implemented by DLib on Android

  In the past, Google had provided Vision API to detect facial landmark. However, if you would like to use that, it requires Android Play Services SDK level 26 or greater. Besides, the number of landmarks might not be enough for you. Luckily, after the release of dlib, v18.10, it includes a number of new minor features.  The main addition in that release is an implementation of an excellent paper from this year's Computer Vision and Pattern Recognition Conference:
One Millisecond Face Alignment with an Ensemble of Regression Trees by Vahid Kazemi and Josephine Sullivan
The implementation of facial landmark extraction is fast enough, and it has 68 landmarks. Therefore, I spent a while to implement this feature to Android platform. 

Hope it can be helpful to Android developers. If it is helpful to you, please give me stars on my Github repositories, dlib-android and dlib-android-app

Setup and install Web server on ubuntu

In the article, I will show simple commands to install apache web server for local development and run a web page on Ubuntu.

Install Apache
$ sudo apt-get install apache2

Open your browser, and go to http://localhost/

Now, you can see the HTML file in /var/www/html/. Then, you can replace html file with yours.

For example, I clone my own web page from my github, and display it on browser.

$ git clone https://github.com/tzutalin/tzutalin.github.io.git
$ cd tzutalin.github.io; sudo cp -rf . /var/www/html/

Finally, open your browser and type "localhost", then you can see the web page

If you would like to register your own domain name, you can find DNS providers like GoDaddy, Namecheap, 1&1 Internet, Dotster.com, etc.


Add Singleton Pattern to AndroidStudio Live Templates

AndroidStudio provides Live Templates to increase productivity for Android developers.

You can complete and insert code snippets into your code by typing their abbreviation and pressing tab. You can see and change those settings in the Editor section of the Preferences.

You can add your own templates. E.g. I add Singleton pattern, thus I can implement and add Singleton Pattern in a class quickly by type my defined abbreviation('singleton').

abbreviation : singleton 
description : Generate Singleton template for the current class
template text:
private $class$() {

private static class $class$LazyHolder {
   private static final $class$ INSTANCE = new $class$();

public static $class$ getInstance() {
   return $class$LazyHolder.INSTANCE;

Remember to let it be applicable in Java

Finally, in your java editor


The list of vision-based SLAM / Visual Odometry open source and papers


Source : https://github.com/tum-vision/lsd_slam
Publications :
LSD-SLAM: Large-Scale Direct Monocular SLAM, J. Engel, T. Schöps, D. Cremers, ECCV '14 
Semi-Dense Visual Odometry for a Monocular Camera, J. Engel, J. Sturm, D. Cremers, ICCV '13
Available on ROS : Yes

Source : https://github.com/raulmur/ORB_SLAM
Website: http://webdiis.unizar.es/~raulmur/orbslam/
Publications : ORB-SLAM: A Versatile and Accurate Monocular SLAM System
Available on ROS : Yes

Nister's Five Point Algorithm for Essential Matrix estimation, and FAST features, with a KLT tracker
Source : https://github.com/avisingh599/mono-vo
Website: http://avisingh599.github.io/vision/monocular-vo/
Publications: http://avisingh599.github.io/assets/ugp2-report.pdf
Available on ROS : No


OpenCV RGBD-Odometry (Visual Odometry based RGB-D images)

Dense Visual SLAM for RGB-D Cameras
Available on ROS : Yes

RTAB MAP - Real-Time Appearance-Based Mapping

Useful third parties

Basic library

Loop detection

Graph Optimization

Map library
Grip Map 

Other useful references

Openslam : Introduce some other SLAM systems and open sources
Kintinuous : Real-time large scale dense visual SLAM system
InfiniTAM : A Framework for the Volumetric Integration of Depth Images
ElasticFusion : Real-time dense visual SLAM system

RGB-D dataset download

TUM Universtiy 

KTTI Vision benchmark

RGB-D tools



Ubuntu 解決標楷體問題

安裝ubuntu14.04時, 如果選擇英語語系, 會幫你安裝中文套件, 預設字體是標楷體

   $ sudo vim /etc/fonts/conf.d/69-language-selector-zh-tw.conf


<string>WenQuanYi Zen Hei</string>
<string>WenQuanYi Micro Hei</string>
<string>WenQuanYi Micro Hei Mono</string>


Dense Visual SLAM for RGB-D Cameras ( dvo_slam setups )

What is DVO SLAM


Software: Ubuntu 12.04 using ROS Fuerte or Ubuntu 14.04 using ROS Indigo
Hardware: RGB-D cameras like RealSense r200, Asus Xtion, Kinect, etc.

If you use ubuntu 12.04 with ROS Fuerte and camera is Kinect or Xtion, you have to setup your camera first.

$ lsusb–v
$ sudo apt-get install ros-fuerte-openni-kinect

if it is 0601 not 0600(old verison)

$ sudo apt-get install --reinstall libopenni-sensor-primesense0
$ sudo gedit /etc/openni/GlobalDefaults.ini

Set `UsbInterface=2`

$ sudo reboot

After reboot, launch openni script, it will open your camera
$ roscore

$ roslaunch openni_launch openni.launch
Use image_view tool to see your RGB and depth images
$ rosrun image_view image_view image:=/camera/rgb/image_color

$ rosrun image_view image_view image:=/camera/depth/image

Clone the source

$ git clone https://github.com/jefftee/dvo_slam.git
$ rosmake dvo_core dvo_ros dvo_slam dvo_benchmark

Ubuntu 12.04 using ROS Fuerte:
$ git clone -b fuerte https://github.com/tum-vision/dvo_slam.git
or clone it from my repository (I add some launch files)
$ git clone -b fuerte git@bitbucket.org:TzuTaLin/dvo_slam.git
Build it


$ sudo apt-get install ros-fuerte-libg2o liblapack-dev libblas-dev freeglut3-dev libqglviewer-qt4-dev libsuitesparse-dev libx11-dev

$ rosmake dvo_core dvo_ros dvo_slam dvo_benchmark
$ roscd your_package_name && make clean
Run keyframe tracker
$ rosrun dvo_slam camera_keyframe_tracker

Run tracker without keyframe
$ rosrun dvo_ros camera_tracker

Run and show configure, and Visualize
$ roslaunch dvo_slam qucikstart.lauch

Run benchmark
Download the dataset:

Extract it and go the folder
$ associate.py rgb.txt depth.txt > assoc.txt

You can download the tool from https://vision.in.tum.de/data/datasets/rgbd-dataset/tools

Than in the dataset folder,  run: 
$ roslaunch dvo_benchmark benchmark.launch keep_alive 
$ roslaunch dvo_benchmark benchmark.launch

Debug (Optional)
$ rosrun rqt rq

Change the name for registerd topics (Optional)

Dataset download




SLAM Tools: