と言っても、さすがMacなので、brew で一発OK。
$ brew install opencv
こんだけ。
ただしこのままだと、ライブラリにパスが通っていないため、import 時にエラーになります。
ということでPython配下にライブラリをコピーします。
$ cp /usr/local/Cellar/opencv/2.3.1a/lib/python2.6/site-packages/cv2.so /Library/Python/2.6/site-packages/.
せっかくなのでラプラシアンフィルタをかけてみました。
こんな感じ。
ちなみに動かしたソースは以下。
#! /usr/bin python # -*- coding: utf-8 -*- import sys import getopt import os from cv2 import cv def main(argv): org_path = './test.jpg' dst_path = './out.jpg' org_image = cv.LoadImage(org_path) org_width = org_image.width org_heght = org_image.height org_channels = org_image.channels new_image = cv.CreateImage((org_width, org_heght), cv.IPL_DEPTH_16S, org_channels) cv.Laplace(org_image, new_image) cv.SaveImage(dst_path, new_image) return if __name__ == "__main__": main(sys.argv)
インストール時のログを念のため貼り付けておきます。Errorがチラッと見えたけど、気にしないw
$ brew list opencv /usr/local/Library/Homebrew/global.rb:43: warning: Insecure world writable dir /usr/local in PATH, mode 040777 /usr/local/bin/brew:73: warning: Insecure world writable dir /usr/local in PATH, mode 040777 Error: No such keg: /usr/local/Cellar/opencv $ $ $ brew install opencv /usr/local/Library/Homebrew/global.rb:43: warning: Insecure world writable dir /usr/local in PATH, mode 040777 /usr/local/bin/brew:73: warning: Insecure world writable dir /usr/local in PATH, mode 040777 Warning: It appears you have MacPorts or Fink installed. Software installed with other package managers causes known problems for Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again. ==> Installing opencv dependency: cmake /usr/local/Library/Homebrew/build.rb:7: warning: Insecure world writable dir /usr/local in PATH, mode 040777 ==> Downloading http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz ######################################################################## 100.0% ==> ./bootstrap --prefix=/usr/local/Cellar/cmake/2.8.6 --system-libs --no-system ==> make ==> make install Warning: m4 macros were installed to "share/aclocal". Homebrew does not append "/usr/local/share/aclocal" to "/usr/share/aclocal/dirlist". If an autoconf script you use requires these m4 macros, you'll need to add this path manually. ==> Summary /usr/local/Cellar/cmake/2.8.6: 628 files, 29M, built in 8.0 minutes ==> Installing opencv dependency: pkg-config /usr/local/Library/Homebrew/build.rb:7: warning: Insecure world writable dir /usr/local in PATH, mode 040777 ==> Downloading http://pkg-config.freedesktop.org/releases/pkg-config-0.25.tar.g ######################################################################## 100.0% ==> ./configure --disable-debug --prefix=/usr/local/Cellar/pkg-config/0.25 --wit ==> make install Warning: m4 macros were installed to "share/aclocal". Homebrew does not append "/usr/local/share/aclocal" to "/usr/share/aclocal/dirlist". If an autoconf script you use requires these m4 macros, you'll need to add this path manually. ==> Summary /usr/local/Cellar/pkg-config/0.25: 8 files, 248K, built in 42 seconds ==> Installing opencv dependency: libtiff /usr/local/Library/Homebrew/build.rb:7: warning: Insecure world writable dir /usr/local in PATH, mode 040777 ==> Downloading http://download.osgeo.org/libtiff/tiff-3.9.5.zip ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/libtiff/3.9.5 --mandir=/usr/local/Cel ==> make install /usr/local/Cellar/libtiff/3.9.5: 235 files, 3.5M, built in 50 seconds ==> Installing opencv dependency: jpeg /usr/local/Library/Homebrew/build.rb:7: warning: Insecure world writable dir /usr/local in PATH, mode 040777 ==> Downloading http://www.ijg.org/files/jpegsrc.v8c.tar.gz ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/jpeg/8c ==> make install /usr/local/Cellar/jpeg/8c: 17 files, 1.6M, built in 41 seconds ==> Installing opencv dependency: jasper /usr/local/Library/Homebrew/build.rb:7: warning: Insecure world writable dir /usr/local in PATH, mode 040777 ==> Downloading http://slackware.sukkology.net/packages/jasper/jasper-1.900.1.zi ######################################################################## 100.0% ==> Patching patching file src/libjasper/jpc/jpc_dec.c ==> ./configure --disable-debug --enable-shared --prefix=/usr/local/Cellar/jaspe ==> make install /usr/local/Cellar/jasper/1.900.1: 33 files, 1.2M, built in 49 seconds ==> Installing opencv dependency: tbb /usr/local/Library/Homebrew/build.rb:7: warning: Insecure world writable dir /usr/local in PATH, mode 040777 ==> Downloading http://threadingbuildingblocks.org/uploads/77/177/4.0%20update%2 ######################################################################## 100.0% ==> make tbb_build_prefix=BUILDPREFIX CONLY=/usr/bin/gcc-4.2 CPLUS=/usr/bin/g++- /usr/local/Cellar/tbb/4.0u1: 85 files, 1.4M, built in 29 seconds ==> Installing opencv /usr/local/Library/Homebrew/build.rb:7: warning: Insecure world writable dir /usr/local in PATH, mode 040777 ==> Downloading http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/ ######################################################################## 100.0% ==> Patching patching file modules/highgui/src/grfmt_exr.hpp ==> cmake . -DCMAKE_INSTALL_PREFIX='/usr/local/Cellar/opencv/2.3.1a' -DCMAKE_BUI ==> make ==> make install ==> Caveats The OpenCV Python module will not work until you edit your PYTHONPATH like so: export PYTHONPATH="/usr/local/lib/python2.6/site-packages:$PYTHONPATH" To make this permanent, put it in your shell's profile (e.g. ~/.profile). ==> Summary /usr/local/Cellar/opencv/2.3.1a: 147 files, 43M, built in 9.5 minutes $