Bag of ML Words

ML = Machine Learning, Music Love, and Miscellaneous things in daily Livings

LaTeX: 図に対する文章の回り込み

普通に真ん中とかに図を置くのじゃなくて、絵の周りに文字が回り込むようにするには、wrapfigureを使えば良いよ。

 

lkj;lkj;lkj;lkじじょmどkめj;lkぽ

------------------  asdfkjlkjlkjlkdsjfoijl

----  figure -----   akjlkjlkjlkjljeiljfljhljkj

------------------  ぃじゃえk;おkふ

;kjぽjん;lkj;lkj;lkj;lkjl;kjlklkj

 

こんな感じ。

¥usepackage{wrapfig}

 

¥begin{wrapfigure}{position}{width}

¥includegraphics{hoge.eps}

¥caption

¥label

¥end{wrapfigure}

positionはl, rで図を紙面のどこに配置するか。

widthは回り込みを含めた図領域の幅です。

 

OpenCV python(anaconda)でインストール Ubuntu 14.04

(前のエントリの日本語バージョン)

Ubuntu14.04でOpenCV pythonラッパをインストールしました。

普通のpythonライブラリじゃなくてAnacondaを使ってるので、それようにオプションとか変えないといけないところで主にハマってました。 

参考となるページ

1. Installing OpenCV 2.2 in Ubuntu 11.04 – Sebastian Montabone

2. LIBTIFF_4.0 link errors - OpenCV Q&A Forum

 

やりかた 

準備

まずはOpenCVのインストールパッケージを手に入れます。今回はOpenCV-2.4.10を使いました。

unzipして、中にビルド用のディレクトリを切ります。作業はそこでします。 

unzip opencv-2.4.10.zip

cd opencv-2.4.10

mkdir build

cd build

つづいて、上記ref1. を参考に必要なライブラリをapt-getします。

ただ、その前に"libopencv*"をremoveしておいたほうが安全です。 

cmake

続いて、cmakeでmakefileを生成します。

私の場合は下記のオプションでインストールに成功しました。

 

cmake -D BUILD_EXAMPLES=ON -D CMAKE_BUILD_TYPE=RELEASE \ 

-D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_1394=OFF \ 

-D WITH_IPP=ON -D WITH_TBB=ON -D WITH_V4L=OFF \ 

-D PYTHON_EXECUTABLE=(anaconda dir path)/bin/python

-D PYTHON_LIBRARY=(anaconda dir path)/lib/libpython2.7.so \

-D PYTHON_INCLUDE=(anaconda dir path)/include/python2.7 \ 

-D PYTHON_PACKAGES_PATH=(anaconda dir path)/lib/python2.7/site-packages \ 

-D BUILD_TIFF=ON \ 

-D CMAKE_C_COMPILER=/usr/bin/gcc

-D CMAKE_CXX_COMPILER=/usr/bin/g++ ../

 

makeがうまくいかない場合はエラーメッセージを良くみて必要なライブラリなどを整備しましょう。 

make and make install

makeしてmake installします。makeはけっこう時間かかります。 

make

sudo make install

Test

まずはanaconda/bin/pythonを起動して、モジュールのimportをします。

import cv2

もしダメな場合はPYTHONPATHなどを確認しましょう。

 

続いて、実際にOpenCVの関数を使った簡単プログラムを書くべきです。これは私も経験したのですが、「make通ってモジュールimportできても、肝心のバイナリができていない」ことが結構あるからです。

 

GLIBC with libm.so.6で問題が出た場合は、/lib/x86_64-linux-gunu/libm.so.6 をanadonda/bin/../lib/にコピーするとうまくいくことが多いです。ただし、かならずバックアップをとってからやりましょう! 

Import Error: `GLIBC_2.15' not found - OpenCV Q&A Forum

 

おしまい. 

OpenCV python wrapper install on Ubuntu 14.04 (w/ anaconda)

I tried many and finally succeeded in installing OpenCV python wrapper on Ubuntu 14.04. 

I use the Anaconda package for the main python library, thus all python-related dependencies would watch for the Anaconda package directory. That was the trouble for me. 

 

Useful references: 

1. Installing OpenCV 2.2 in Ubuntu 11.04 – Sebastian Montabone

2. LIBTIFF_4.0 link errors - OpenCV Q&A Forum

 

Procedure 

Preparation

First, download the installation package of OpenCV (for linux) from the official site. 

I used the OpenCV-2.4.10. 

Unpack it and go to the directory. Then, create a working directory for build. 

unzip opencv-2.4.10.zip

cd opencv-2.4.10

mkdir build

cd build

Next, prepare all necesarry libraries by apt-get. 

Please find the reference 1. Before apt-get install, you may remove "libopencv*" from your system (to avoid unnecesarry conflictions). 

cmake

Now we are ready to try building the OpenCV

We start from making the Makefiles by cmake. In cmake, you need to be careful on the option arguments because we rely on Anaconda package. 

Finally the command below yielded the successful installatoin: 

cmake -D BUILD_EXAMPLES=ON -D CMAKE_BUILD_TYPE=RELEASE \ 

-D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_1394=OFF \ 

-D WITH_IPP=ON -D WITH_TBB=ON -D WITH_V4L=OFF \ 

-D PYTHON_EXECUTABLE=(anaconda dir path)/bin/python

-D PYTHON_LIBRARY=(anaconda dir path)/lib/libpython2.7.so \

-D PYTHON_INCLUDE=(anaconda dir path)/include/python2.7 \ 

-D PYTHON_PACKAGES_PATH=(anaconda dir path)/lib/python2.7/site-packages \ 

-D BUILD_TIFF=ON \ 

-D CMAKE_C_COMPILER=/usr/bin/gcc

-D CMAKE_CXX_COMPILER=/usr/bin/g++ ../

 

Type the above command, and cmake wil return the specifications for making the OpenCV library. Read the specifications carefully, and correct the options if something is wrong. 

 

make and make install

If you are good, then make. This will take a while. After that, make install with sudo. 

make

sudo make install

If there are some errors during make, you need to fix it one by one. Typically I encountered with missing lib****, which we can solve instantly by apt-get.  

Test

First, check out if openCV module is loadable from your python (in anaconda):  

import cv2

If no errors, congratulation! You passed the first test. :-) 

 

Second, you would write a simple code that uses cv2 functions. Some of OpenCV functions may not be builded appropriately even if the installation finished without apparent errors && the cv2 module is loadable.

In my system I frequently encountered with problems on video (movie) processing functions :-( 

 

If you encounter the linker problem of GLIBC with libm.so.6 (like me), you may copy libm.so.6 from /lib/x86_64-linux-gunu/libm.so.6 to anadonda/bin/../lib/. 

Be sure to keep the original libm.so.6 (that of anadonca) as a different file!

Import Error: `GLIBC_2.15' not found - OpenCV Q&A Forum

 

Done. 

No errors? Have fun with OpenCV!! ;-)

Python: 外部コマンドの呼び出し方

普段はos.system('command')を使っていたのですが、


pythonで外部のシェルスクリプトやコマンドを実行する方法 - Qiita

 

これによると、commandsパッケージ使ったほうがいいみたいですね。

今度からそうします。

 

2015/03/13追記:

h-miyako様からコメントいただきました。

commandsはもう3.系にはないそうです。

os.sytemも使わない方が良くて、

subprocessモジュールを使うことが良いようです。

勉強しなおします。

 

勉強しなおしました

subprocesだと、subprocess.callを使えばいいです。

import subprocess

retcode = subprocess.call("ls") # ls する
recode2 = subprocess.call("ln", "-s", "./temp/neko", "./mike") "

# ln -s ./temp/neko ./mike してる

ポイントは、本当に最初の1つのコマンドだけくくりだして、のこりのargumentsは順番に与えていくことですね

Cython

Cython使ったことないんですけど。前はnumba使ったんですけど、

指導している子によると使える範囲せまいらしいので、

やっぱCythonかな~って。

 

というわけで@taki_taki__くんのブログエントリをメモっておく

そもそもomakeを知らないというところから始めなければ・・・

 


PyCharm上でCythonのビルドを簡単にするには | 左京区パラボラ日記

 


Cython開発とomake連携 | 左京区パラボラ日記

Java: args4jによるコマンドラインのパース

今まではString[] argsを使ってたけど、

今後はこれで決まりっぽいな。各種フラグを簡単に指定できるようになるのはいいね

 

Parsing command line options in JDK 5.0 style: args4j | Java.net