【macOS Sierra】OpenCV 3をbrewでインストールできない

よくある手順通りに進めていたところインストールでだいぶ躓いたのでメモ。

環境

  • macOS Sierra 10.12.1
  • Homebrew 1.1.2
  • OpenCV stable 3.1.0(結果的に入ったやつ)

問題

Python3で使用したかったので、追加のオプションを入れつつインストール命令実行。

$ brew install opencv3 --with-python3

実行の結果出てきたエラーっぽいやつら。

/tmp/opencv3-20161207-28854-41wt3t/opencv-3.1.0/modules/videoio/src/cap_qtkit.mm:46:9: fatal error: 'QTKit/QTKit.h' file not found
#import <QTKit/QTKit.h>
        ^
1 error generated.
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_qtkit.mm.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2

READ THIS: https://git.io/brew-troubleshooting

These open issues may also help:
opencv3 missing xz dependency in linuxbrew https://github.com/Homebrew/homebrew-science/issues/2642
opencv3: fix build with vtk https://github.com/Homebrew/homebrew-science/pull/3749
opencv3 python3 wrappers can not be generated https://github.com/Homebrew/homebrew-science/issues/3302
opencv3 misconfigures cmake because brew incorrectly sets $PYTHONPATH https://github.com/Homebrew/homebrew-science/issues/3329
OpenCV and OpenCV3 fail to build with ximea camera support https://github.com/Homebrew/homebrew-science/issues/3395
import cv2 fails and cannot find module once OpenCV3 has been installed via homebrew on Mac OS Sierra with xcode 8.1 https://github.com/Homebrew/homebrew-science/issues/4571
opencv3 PYTHON_PATH and other variables set incorrectly in some cases https://github.com/Homebrew/homebrew-science/issues/2846
opencv3 build fails without clear error message on OSX 10.10.5 https://github.com/Homebrew/homebrew-science/issues/3119

エラーメッセージで検索した結果出てきたissueを参考に、オプション追加。

$ brew install --HEAD opencv3 --with-python3

無事成功。
インストール後のbrew infoの結果。

$ brew info opencv3
homebrew/science/opencv3: stable 3.1.0, HEAD [keg-only]
Open source computer vision library, version 3
http://opencv.org/
/usr/local/Cellar/opencv3/HEAD-300f923_4 (286 files, 48.8M)
  Built from source on 2016-12-07 at 18:09:15 with: --with-python3

恐らく最新版では修正済みの期間限定エラーだったのだと思われる。
やめて頂きたい。

参照

Updated PR #7159 (OSX AVFoundation support) by alalek · Pull Request #7266 · opencv/opencv · GitHub