2012年12月24日月曜日

macportsメンテナンスルーチン

覚え書き
デフォルトのgccであることを最初に確認しておく。 また、python24に依存したportsを全てアンインストールするときは 特定のパッケージを無視するときは 参考サイト

[追記]2017/02/25
OSをmacOS Sierra v10.12にアップグレードしたあとこのサイトの項目「Migration procedure」の1と2だけを実行した。macports.confは触っていない。

2012年12月1日土曜日

std::listとstd::vectorのベンチマーク

isocppのサイトにstd::listとstd::vectorのベンチマークの記事が紹介されていました。
http://www.baptiste-wicht.com/2012/11/cpp-benchmark-vector-vs-list/

作者は実際に測定を行い、こう結論しています。
  1. std::vector is insanely faster than std::list to find an element
  2. std::vector performs always faster than std::list with very small data
  3. std::vector is always faster to push elements at the back than std::list
  4. std::list handles very well large elements, especially for sorting or inserting in the front
そして、実際にコードを書く際の指針を以下のように示しています。
  1. Number crunching: use std::vector
  2. Linear search: use std::vector
  3. Random Insert/Remove: use std::list (if data size very small (< 64B on my computer), use std::vector)
  4. Big data size: use std::list (not if intended for searching)
ここで、crunchingとはソートされたコンテナに乱数を挿入する操作のことです。

C++11を使ってOpenCV-2.4.3をコンパイルする。

CentOS5.8上でC++11(gcc-4.7.2)を使ってOpenCV-2.4.3をコンパイルしました。以下覚え書きとして記します。

.bashrcには以下の記述が既にあります。 すなわち、gcc-4.7.2へのパスをシステムは認識しています。
今いる場所はここ。 以下を実行。

C++11を使ってBoost-1.52.0をコンパイルする。

CentOS5.8上でC++11(gcc-4.7.2)を使ってBoost-1.52.0をコンパイルしました。以下覚え書きとして記します。

.bashrcには以下の記述が既にあります。 すなわち、gcc-4.7.2へのパスをシステムは認識しています。そして、今いる場所はここ。 ここに従ってboost.buildをインストールします。 PATHに/usr/local/boost.build/binを追加します。そして、以下を実行します。 しばらくすると、「pyconfig.hがない」と出ました。なのでこれを実行します。 あらためて 今度は「zlib.hがない」「bzlib.hがない」と出ました。これらをインストールします。 あらためて 出来ました。stageディレクトリの下にライブラリができています。これをcpコマンドを使って「手動で」目的の場所にコピーしました。

最初は手動ではなく、このコマンドを使ってインストール(コピー)を行いました。 このコマンドを実行すると、コピーだけでなくコンパイルも始めます。それもデフォルトのgcc(4.1.2)を使って。 コンパイルは終わってるはずです。よくわかりません。なので、上記のように「手動インストール」しました。

2012年11月29日木曜日

CentOS5.8にgcc-4.7.2をインストールする。

CentOS5.8上でgcc-4.7.2をコンパイルしました。 こちらのサイトを参考にしています。以下覚え書きとして記します。

前準備として、以下のパッケージをupdateします。gccだけでなく、gcc-c++も必要です。
  1. gcc
  2. gcc-c++
  3. binutils
  4. bzip2
  5. gzip
  6. m4
  7. make
  8. unzip
  9. zip
以下のサイトから、各ソースをダウンロードします。
  1. mpc
  2. mpfr
  3. gmp
  4. gcc
これらをgcc-4.7.2というディレクトリの下に置き、解凍します。
最初に、gmpをコンパイルします。 次に、mpfrをコンパイルします。 さらに、mpcをコンパイルします。 これでgccをコンパイルする準備が整いました。 make中にこんなエラーが発生しました。 LD_LIBRARY_PATHに/usr/local/gcc-4.7.2/lib(mpc,gmp,mpfrのライブラリがあるディレクトリ)を追加すれば良いです。 あらためて しばらくすると、また、エラーが発生しました(内容は...記録し忘れました)。 対処方法はこれです。 32ビット版のglibcのヘッダが必要です。configureの時に明示的に64ビットに限定しないと32ビットもコンパイルされるのですね。知りませんでした。 再度 できました。64ビット版のgccは--prefixで指定したディレクトリ、今の場合、/usr/local/gcc-4.7.2/lib64の下にあります。

2012年11月25日日曜日

Level Set Method

Introduction

Several years ago I implemented a command line application of the Level Set Method. In this page, I would like to introduce it.

Demo

I start with showing three demonstrations:
demo-1

demo-2

demo-3

 

Verification Environment(Mac)

  1. Mac OS X 10.8.2
  2. Processor:3.06 GHz Intel Core 2 Duo
  3. Memory:4GB
  4. Xcode4.5.2 with Apple LLVM 4.1(C++ Language Dialect → C++11, C++ Standard Library → libc++)
  5. boost-1.51.0 compiled by the above compiler (See also here)

Verification Environment(Windows)

  1. Windows XP Professional Version 2002 Service Pack 3
  2. Processor:Pentium(R) D CPU 3.20GHz
  3. Memory:3GB
  4. Visual Studio 2005
  5. boost-1.51.0 (binaries for the VS2005)

Source Code

Here is my source code. I verified it on the above two machines.

Usage

An execution file name is LevelSetMethod. In the case of Windows, it's named LevelSetMethod.exe. Running it without any arguments, it writes the following usage statements on the standard output: The Level Set Method is carried out by using some of these parameters. The procedure is as follows:
  1. see the size of an input image.
  2. set an initial closed curve.
  3. run the Level Set Method.
I will explain the detail of each process.

①Size of Image


In order to give the application an initial closed curve, we have to know the size of an input image. To do so, the following command is used. The output indicates the size of the input image(./input/sample3.jpg).

②Setting Initial Closed Curve


We can draw an circle with a center (X, Y) and a radius R by the following command. In this command, -C indicates color of the circle, whose range is [0,255]. The circle is drawn on the input image. It is saved in the directory(./output) with the name "initial_loop.jpg" (see the below image). The circle corresponds to the initial closed curve. We can put it either outside an object or inside one. If it is placed outside the object, the Level Set Method shrinks it. On the other hand, if it is placed inside the object, the Level Set Method expands it. We have to decide appropriate values (X, Y, R) through a trial and error process.

③Running Level Set Method


We have to make a setting file in which six parameters are described. The file name is arbitrary. In this page, we name it "params" to make the explanation easy. The sample of "params" is as follows: The meanings of the parameters are
  1. time_step: time step
  2. time_step_number: iteration of time evolution
  3. space_step: space step. the same value for both x-axis and y-axis
  4. constant_speed: a constant part of a speed function as we will discuss later
  5. epsilon: a value of ε which appears in the definition of a speed function
  6. sigma: a degree of the Gaussian blur
The speed function which the application uses is defined as,

where, is the curvature.
The parameter epsilon indicates and the parameter constant_speed corresponds to . If we shrink(expand) the curve, we set it to negative(positive) value. After making the setting file, we run the following command: After the argument -F, we type the path to "params." During execution, the progress bar is displayed. Under the above parameters, the time evolution is repeated up to 400 steps, and one image is saved per 10, which is a value after -T, time steps. The output directory is ./output and the file name is front_xxx.jpg, where xxx represents integer. The calculation time is displayed in the last line of the standard output. In the current parameters, 40 images are saved. I converted these images into a movie by use of ffmpeg to show the demonstration at the beginning of this page.

P.S. See also this page. 2013/01/25

Compilation of Boost by clang with C++11

My procedure is as follows: When using it on the Xcode, we need to add a variable DYLD_LIBRARY to "Product→Edit Scheme→Arguments→Environment Variables" and set the path to dylib to the variable.