{"id":322,"date":"2014-04-29T21:11:08","date_gmt":"2014-04-29T12:11:08","guid":{"rendered":"http:\/\/blog.ymyzk.com\/?p=322"},"modified":"2015-07-03T15:33:51","modified_gmt":"2015-07-03T06:33:51","slug":"mac-os-x-opencv-python","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2014\/04\/mac-os-x-opencv-python\/","title":{"rendered":"Mac OS X \u3067 OpenCV + Python \u306e\u958b\u767a\u74b0\u5883\u3092\u6574\u5099\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"
Mac OS X \u3067 OpenCV + Python \u306e\u958b\u767a\u74b0\u5883\u3092\u6574\u5099\u3059\u308b\u65b9\u6cd5\u3092\u307e\u3068\u3081\u307e\u3059. \u4eca\u56de\u3053\u306e\u65b9\u6cd5\u3067\u5c0e\u5165\u30c6\u30b9\u30c8\u3092\u884c\u306a\u3063\u305f\u74b0\u5883\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059.<\/p>\n
Mac OS X \u3067 OpenCV 3 + Python 2\/3 \u3067\u306e\u74b0\u5883\u69cb\u7bc9\u306b\u3064\u3044\u3066\u306f\u3053\u3061\u3089<\/a>\u3092\u3054\u89a7\u4e0b\u3055\u3044.<\/p>\n <\/p>\n \u3053\u308c\u306b\u3064\u3044\u3066\u306f\u591a\u304f\u306e\u65b9\u304c\u65e2\u306b\u5c0e\u5165\u3055\u308c\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u7701\u7565\u3057\u307e\u3059. \u8a73\u3057\u304f\u306f Homebrew \u306e\u516c\u5f0f\u30b5\u30a4\u30c8<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044.<\/p>\n NumPy \u306f homebrew-python<\/a>, OpenCV \u306f homebred-science<\/a> \u306b Formula \u304c\u3042\u308b\u306e\u3067, \u305d\u308c\u305e\u308c tap \u3057\u3066\u304a\u304d\u307e\u3059.<\/p>\n Homebrew \u304b\u3089\u6700\u65b0\u5b89\u5b9a\u7248\u306e Python 2.7 \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059.<\/p>\n OS X \u306b\u5165\u3063\u3066\u3044\u308b Python \u3067\u306f\u306a\u304f, Homebrew \u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f Python \u3092\u5229\u7528\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059. Homebrew \u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092 \u3092\u5b9f\u884c\u3057\u3066,<\/p>\n \u304c\u8868\u793a\u3055\u308c\u308c\u3070 OK \u3067\u3059. OpenCV \u306e Python \u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u306f\u30c7\u30fc\u30bf\u3092\u6271\u3046\u305f\u3081\u306b NumPy \u3092\u5229\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u5c0e\u5165\u3057\u307e\u3059. virtualenv \u7b49\u306f\u7528\u3044\u305a\u306b, \u76f4\u63a5\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u306e\u304c\u826f\u3044\u3088\u3046\u3067\u3059.<\/p>\n OpenCV \u3092 Homebrew \u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059.<\/p>\n \u3092\u5b9f\u884c\u3057, \u5fc5\u8981\u306b\u5fdc\u3058\u3066 Optional \u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4e8b\u524d\u306b\u5c0e\u5165\u3057\u3066\u304a\u304d\u307e\u3059. OpenCV \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f<\/p>\n \u3067\u884c\u306a\u3048\u307e\u3059. \u4f9d\u5b58\u3059\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3082\u542b\u3081\u5c11\u3057\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3059.<\/p>\n OpenCV \u3092 Python \u304b\u3089\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u304b\u30c6\u30b9\u30c8\u3057\u307e\u3059. \u4ee5\u4e0b\u306e\u3088\u3046\u306b \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u958b\u767a\u7b49\u3067 virtualenv \u3092\u5229\u7528\u3057\u305f\u3044\u5834\u5408\u306f, \u901a\u5e38\u901a\u308a\u4eee\u60f3\u74b0\u5883\u3092\u4f5c\u6210\u3057, OpenCV \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u307f\u5225\u9014\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u3092\u4f5c\u6210\u3057\u3066\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059.<\/p>\n OS X Yosemite \u3067\u3082\u4e0a\u8a18\u306e\u65b9\u6cd5\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3057\u305f. \u74b0\u5883\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059.<\/p>\n Mac OS X \u3067 OpenCV + Python \u306e\u958b\u767a\u74b0\u5883\u3092\u6574\u5099\u3059\u308b\u65b9\u6cd5\u3092\u307e\u3068\u3081\u307e\u3059. \u4eca\u56de\u3053\u306e\u65b9\u6cd5\u3067\u5c0e\u5165\u30c6\u30b9\u30c8\u3092\u884c\u306a\u3063\u305f\u74b0\u5883\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059. OS X 10.9.2 (13C1021) Homebrew Pyt […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[21,48,15],"_links":{"self":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/322"}],"collection":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/comments?post=322"}],"version-history":[{"count":12,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"predecessor-version":[{"id":1016,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/322\/revisions\/1016"}],"wp:attachment":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Homebrew \u306e\u5c0e\u5165<\/h2>\n
\r\nbrew tap homebrew\/python\r\nbrew tap homebrew\/science\r\n<\/pre>\n
Python \u306e\u5c0e\u5165<\/h2>\n
\r\nbrew install python\r\n<\/pre>\n
\/usr\/local<\/code> \u4ee5\u4e0b (\u30c7\u30d5\u30a9\u30eb\u30c8) \u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u308b\u5834\u5408<\/p>\n
\r\nwhich python\r\n<\/pre>\n
\r\n\/usr\/local\/bin\/python\r\n<\/pre>\n
\/usr\/bin\/python<\/code> \u3068\u306a\u308b\u5834\u5408\u306f
PATH<\/code> \u306e\u8a2d\u5b9a\u304c\u51fa\u6765\u3066\u3044\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081, Homebrew \u306e\u5c0e\u5165\u624b\u9806\u3092\u518d\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044.<\/p>\n
NumPy \u306e\u5c0e\u5165<\/h2>\n
\r\npip install numpy\r\n<\/pre>\n
OpenCV \u306e\u5c0e\u5165<\/h2>\n
\r\nbrew info opencv\r\n<\/pre>\n
\r\nbrew install opencv\r\n<\/pre>\n
\u30c6\u30b9\u30c8<\/h2>\n
cv2<\/code> \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u8aad\u307f\u8fbc\u3081\u308c\u3070\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5b8c\u4e86\u3067\u3059.<\/p>\n
\r\n$ python\r\nPython 2.7.6 (default, Apr 9 2014, 11:48:52)\r\n[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin\r\nType "help", "copyright", "credits" or "license" for more information.\r\n>>> import cv2\r\n>>>\r\n<\/pre>\n
virtualenv \u304b\u3089 OpenCV \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5229\u7528\u3059\u308b<\/h2>\n
~\/venv<\/code> \u306b\u4f5c\u6210\u3057\u305f\u4eee\u60f3\u74b0\u5883\u3067 OpenCV \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5229\u7528\u51fa\u6765\u308b\u3088\u3046\u306b\u3059\u308b\u306b\u306f, \u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u3092\u4f5c\u6210\u3057\u307e\u3059.<\/p>\n
\r\n# \u4eee\u60f3\u74b0\u5883\u306e\u4f5c\u6210\r\nvirtualenv -p \/usr\/local\/bin\/python2.7 ~\/venv\r\n# NumPy \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\r\nsource ~\/venv\/bin\/activate\r\npip install numpy\r\n# OpenCV \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\r\ncd ~\/venv\/lib\/python2.7\/site-packages\r\nln -s \/usr\/local\/lib\/python2.7\/site-packages\/cv.py .\/\r\nln -s \/usr\/local\/lib\/python2.7\/site-packages\/cv2.so .\/\r\n<\/pre>\n
\u66f4\u65b0<\/h2>\n
\n
OS X Yosemite<\/h3>\n
\n