Thursday, October 17, 2013

Install OpenCV 2.6.4 on Ubuntu 12.04

I can still remember the time I was installing OpenCV library three years ago. It's not easy for the first time to install such a large library onto my own IDE. Knowledges about "Makefiles", system PATH, pkg-config, etc. are required to setup OpenCV. Also, you may also be familiar with your IDF, so that you can find where to fill in the right settings.

Here, take a common environment as example, is the way to install OpenCV 2.6.4 (or any other latest version) on Ubuntu 12.04. This is simple thanks for the script written by jayrambhia.

  1. git clone
  2. cd Install-OpenCV/Ubuntu
  3. chmod +x
  4. ./

These steps ask the machine to download the script from jayrambhia's github, then run the script in it. Remember you may be asked to type in your password in order to run the "sudo" commands. After running the four commands, you'll completely installed OpenCV on your Ubuntu machine.

Sunday, October 13, 2013


There's some notes about "Naming" which I learned from "The Practice of Programming" by Brian W. Kernighan and Rob Pike. It's base on the book "The C Programming Language".
  • use descriptive names for globals, short names for locals
  • local variable
    • i and j for loop indices
    • p and q for pointers
    • s and t for strings
  • Programmers are often encourage to use long variable names regardless of context. This is a mistake: clarity is often achieved through brevity. (清楚與否需要透果簡潔以實現)
  • initial capital letters for Globals, all capitals for CONSTANTS
  • be consistent
  • use active names for functions
    • ex. getTime(), putChat()
    • bool functions: isoctal()
  • be accurate

Wednesday, October 9, 2013

STM32 Development Environment Setup on Ubuntu


During the class in "I/O and Drivers", I learned how to setup the environment on Windows including ARM GCC Tool Chain, GNUmake, and ST-Link Utility so that I can install our own code into the board, STM32.

Back to my home, I don't have any Windows machine. Then, I tried to build the same environment on Ubuntu or Mac OS X, which turned out that it’s much easier to setup the environment on Ubuntu. This report will cover the things I've done in order to install our own program on STM32 using Ubuntu.

Note: I'm using Ubuntu 12.04.

My Environment

  1. install the libraries or other dependencies we need
    • bash> sudo apt-get install build-essential git flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo libtool libftdi-dev libusb-1.0-0-dev && sudo apt-get build-dep gcc-4.5
  2. install ARM toolchain
  3. add the bin files to system PATH
    • echo 'export PATH=/home/YOUR_USER/sat/bin:$PATH' > ~/.bashrc
  4. install QSTLink2 (this program burns the bin files into the board)
    • install its dependencies: bash> sudo apt-get install qt4-qmake libqt4-dev libqt4-gui libqt4-xml qt4-designer qtcreator libusb-0.1-4 libusb-1.0-0-dev
    • download QSTLink2 source code:
    • unzip QSTLink2 source code
    • install QSTLink2: bash> qmake-qt4 && make && sudo make install && sudo reload udev

Run & Burn the Code

  1. make
  2. open QSTLink2
  3. connect
  4. select bin file
  5. send to the board

Tuesday, October 8, 2013

This post is my class note for 1.2: The Power of Prototyping

Why Prototype

  1. 在短時間內得到feedback
  2. 解決難以預測的情況

Rights for Prototype

  1. 不被要求是具有完整功能的
  2. 容易被修改的
  3. 一定會被換掉

Main Point

"Prototypes are questions, ask lots of them."

Saturday, October 5, 2013

Finite Automata

Few notes from my reading of Introduction to the Theory of Computation chapter 1.1:

Definition of Finite Automaton

A finite automaton is a 5-tuple (Q, Σ, δ, q0, F), where
  1. Q is a finite set called the states,
  2. Σ is a finite set called the alphabet,
  3. δ: Q × Σ → Q is the transition function,
  4. q0 ∈ Q is the start state, and
  5. F ⊆ Q is the set of accept states (final states).

Definition of Regular Language

A language is called a regular language if some finite automaton recognizes it.

Definition of Regular Operatioins

Let A and B be languages. We define the regular operations union, concatenation, and start as follows.
  • Union: A ∪ B = { x | x∈A or x∈B }
  • Concatenation: A ○ B = { xy | x∈A and y∈B }
  • Star: A* = {x1 x2 ... xk | k ≧ 0 and each xi ∈ A}
  • the concatenation operation attaches a string from A in front of a string from B in all possible ways to get the strings in the new language
  • the star operation is a unary operation instead of a binary operation
  • because "any number" includes 0 as a possibility, the empty string ε is always a member of A*, no matter what A is

Friday, October 4, 2013

constraintsWithVisualFormat, the most interesting coding style I've ever seen

WWDC 2012的演講中,介紹了auto layout,相對於其他文件,這關於排版的程式設計透過影片能比較快的學起來,其中最酷的是一個constraintsWithVisualFormat的函式,讓我們感覺到除了在裝置、界面設計上別出心裁的Apple,在開發者這端也有很有趣的設計。

Apple在iOS 5之後的開發平台上提供auto layout的功能,可以在點選storyboard點選某個view後,於右側的選單中開啓這功能(多已經預設),而constraints就是其中最重要的機制,不會複雜,說穿了,constraint就是一個一維線性代數(y = ax + b),裡頭的y和x分別是某個物件中的某個位置或長度,a和b就是個常數,於是乎,auto layout就是透過這些constraints對於物件擺放的敘述而排版,好的敘述會讓版面不論縮放、旋轉後都是好看的。

constraints可以用一般的函式一一輸入 y = ax + b,但是Apple在設計時候可能是發現這樣太麻煩了,一個constraint的函式表示要六、七行以上呢!所以提出Visual Format這樣的東西,是透過視覺化程式碼,對於喜歡ASCII Art的人的一大福音!

以下是WWDC 2012演講簡報中部分的內容,很酷!