LoginSignup
19
18

More than 5 years have passed since last update.

MacOSX に Otama (類似画像検索エンジン) をインストールする

Last updated at Posted at 2014-08-28

Otama とは

類似画像検索エンジン。
https://github.com/nagadomi/otama

たまたまCBIRについて調べ事をしてて見つけたけど、それまでは知らなかった。

  • メンテナンスが継続されている。
  • デモがいくつかあり、使い方のイメージがしやすかった。
  • C、Ruby、Python、Go、Python などのインターフェースがある。

とりあえず手元のMacにインストールしてみたメモを残します。

MacOSX にインストール

ソースコードからビルドする手順が記載されていたので、これに沿ってすすめる。
https://github.com/nagadomi/otama/wiki/Building%20from%20source

homebrew で必要なライブラリ類をインストール

$ brew tap homebrew/versions
$ brew install gcc48
~/.bashrc
export CC=gcc-4.8
export CXX=g++-4.8
$ source ~/.bashrc
$ brew install autoconf automake libtool libpng jpeg giflib leveldb libyaml

eiioのインストール

$ curl -OJL https://github.com/nagadomi/eiio/archive/v0.5.6.tar.gz
$ tar -xzvf eiio-0.5.6.tar.gz
$ cd eiio-0.5.6
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install

nvのインストール

$ curl -OJL https://github.com/nagadomi/nv/archive/v2.2.0.tar.gz
$ tar -xzvf nv-2.2.0.tar.gz
$ cd nv-2.2.0
$ ./autogen.sh
$ ./configure
$ make

make時にエラーが発生

/var/folders/f2/03j9bq3d12sggdzyltdghtjr0000gn/T//cc382zKB.s:58:no such instruction: `vcomiss LC2(%rip), %xmm0'
/var/folders/f2/03j9bq3d12sggdzyltdghtjr0000gn/T//cc382zKB.s:60:no such instruction: `vmovss LC0(%rip), %xmm0'
/var/folders/f2/03j9bq3d12sggdzyltdghtjr0000gn/T//cc382zKB.s:64:no such instruction: `vmovss LC1(%rip), %xmm0'
/var/folders/f2/03j9bq3d12sggdzyltdghtjr0000gn/T//cc382zKB.s:146:no such instruction: `vmulss LC5(%rip), %xmm0,%xmm0'
make[2]: *** [libnv_la-nv_core_util.lo] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

試行錯誤した結果、--with-arch=genericをオプションにつけることで解消。

genericを指定することで一部のドライバの性能が著しく低下すると記載されているので、各環境で適切な指定をするのが良さそうです。
https://github.com/nagadomi/otama/wiki/Building%20from%20source#--with-archarch-name

--enable-opencvを指定すると、OpenCVを使用するようにできる(?)

$ ./configure --with-arch=generic
$ make
$ sudo make install

Otama のインストール

$ curl -OJL https://github.com/nagadomi/otama/archive/v0.7.3.tar.gz
$ tar -xzvf otama-0.7.3.tar.gz
$ cd otama-0.7.3
$ ./autogen.sh
$ ./configure
$ make

ここでもmake時にエラー

make[3]: *** [libnvcolorex_la-nv_color_boc.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

これも、nvと同様に、--with-arch=genericをオプションにつけることで解消。

$ ./configure --with-arch=generic
$ make
$ make check
$ sudo make install

※ MySQLを利用する場合は--enable-mysql、PostgreSQLを利用する場合は--enable-pgsqlを指定する。

試してみる

サンプルコードを動かす

$ git clone https://github.com/nagadomi/otama.git
$ cd otama/examples/example-webapp/

ImageMagick, libmagic が入っていない場合はインストール

$ brew install libmagic imagemagick

sudo bundle install をしてしまうとグローバルにgemがインストールされてしまうので、このプロジェクト以下にインストールする

$ bundle install --path=./vendor/bundle

検索対象となる画像が入ったディレクトリを指定し、インポート

$ find ~/Desktop/samples/ \( -name \*.jpg -o -name \*.png -o -name \*.jpeg \) -print > filelist.txt
$ nohup ./import.sh &

止まってる...?

nohupのログを参照すると、./config.yamldriver.data_dirを手動でつくる必要がある様子。

$ mkdir ./data
$ ./import.sh &

WEBサーバーを起動

$ bundle exec rackup

ブラウザで動作を確認

19
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18