LoginSignup
12
16

More than 5 years have passed since last update.

homebrewを用いてMacにOpenCVを導入

Last updated at Posted at 2015-09-07

概要

OpenCVをhomebrewを用いて環境構築した時のメモ.
初期設定〜サンプルの実行まで.

環境

Mac mini(2012),OS X Yosemite(10.10.5)
OpenCV2

初めに

homebrewをインストールしておきます.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
xcodeを起動したことない人は

You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:
sudo xcodebuild -license

というメッセージが出るので,xcodeを起動します.

OpenCVとPythonのダウンロード&インストール

Python関連のインストール
brew tap homebrew/science
brew install python
pip install numpy

OpenCV関連のインストール
brew install cmake automake celt faac fdk-aac git lame libass libtool libvorbis libvpx libvo-aacenc opencore-amr openjpeg opus sdl schroedinger shtool speex texi2html theora wget x264 xvid yasm

brew install ffmpeg --with-fdk-aac --with-libvo-aacenc --with-libvorbis --with-libvpx --with-openjpeg --with-theora --with-opencore-amr

brew install eigen
brew install jasper
brew install tbb
brew install qt
brew install opencv --with-eigen --with-jasper --with-libtiff --with-qt --with-tbb --with-ffmpeg

サンプルを試す

画像を読み込み,グレー画像に変換,出力.
※同じディレクトリに test1.jpg を置いておく.

test.py
import cv2
import numpy as np
import sys

cv2.namedWindow('edge')
img = cv2.imread('test1.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thrs1 =1000
thrs2 =10
edge = cv2.Canny(gray, thrs1, thrs2, apertureSize=5)
cv2.imshow('edge', edge)

cv2.waitKey(0)
cv2.destroyAllWindows()

無事に実行されたはずです.

関連・参考

OS X に OpenCV を Homebrew で入れて python で動画入出力をする
Homebrew でOpenCVをインストールする方法

その他

余談ですが,次はUbuntuのOpenCVの環境構築に挑戦したいと思います.

12
16
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
12
16