{"id":1150,"date":"2013-07-19T15:35:13","date_gmt":"2013-07-19T07:35:13","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1150"},"modified":"2014-03-28T13:02:06","modified_gmt":"2014-03-28T05:02:06","slug":"build-opencv-on-mac-osx","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2013\/07\/19\/build-opencv-on-mac-osx\/","title":{"rendered":"Build OpenCV on Mac OSX"},"content":{"rendered":"<p>When I posted the use of <a href=\"http:\/\/www.magicandlove.com\/blog\/2013\/04\/04\/opencv-2-4-4-and-processing\/\">OpenCV in Processing<\/a>, there were a number of queries about installing and building OpenCV in OSX. In this post, I try to summary the process. It assumes basic understandings of the Unix environment of the OSX system with the use of the Terminal command. Here are the steps.<\/p>\n<p><!--more--><\/p>\n<p>You need to have a login password for your current account and it should be an administrator. The password is required for the <strong>sudo<\/strong> command in later step.<\/p>\n<p>Open the <strong>Terminal<\/strong> command line interface from <strong>\/Applications\/Utilities<\/strong> folder.<\/p>\n<p>Show the hidden files in your OSX system following the steps in <a href=\"http:\/\/www.mikesel.info\/show-hidden-files-mac-os-x-10-7-lion\/\">this reference<\/a>. You are going to check the files installed in the folders <strong>\/usr\/bin<\/strong> and <strong>\/usr\/local<\/strong>.<\/p>\n<p>Install the <strong>cmake<\/strong> software. I use the <strong>Homebrew<\/strong> system to install it. You can refer the <a href=\"http:\/\/mxcl.github.io\/homebrew\/\">Homebrew website<\/a> for the installation of the Homebrew system. It is just a line in the Terminal window:<\/p>\n<pre>ruby -e \"$(curl -fsSL https:\/\/raw.github.com\/mxcl\/homebrew\/go)\"<\/pre>\n<p>It requires you to enter your login password. To install the <a href=\"http:\/\/www.cmake.org\/\">cmake<\/a> software, use the <strong>brew <\/strong>command in the Terminal window:<\/p>\n<pre>brew install cmake<\/pre>\n<p>After the installation, you can use the <strong>brew list<\/strong> command to verify.<\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv002.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1155\" title=\"brew list\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv002-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/opencv.org\/downloads.html\">Download<\/a> the Mac\/Linux version of the OpenCV. The current one I am using is 2.4.6.1.<\/p>\n<p>Unpack the file in your hard disk. The folder name is opencv-2.4.6.1.<\/p>\n<p>In the Terminal window, use <strong>cd<\/strong> command to change the current directory to the opencv-2.4.6.1 folder.<\/p>\n<p>Create a <strong>build<\/strong> folder and change current directory to it.<\/p>\n<pre>\r\nmkdir build\r\ncd build\r\n<\/pre>\n<p>Verify that you have the <strong>gcc<\/strong> and <strong>g++<\/strong> compilers in the \/usr\/bin folder.<\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv003.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1159\" title=\"compilers\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv003-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>They are actually two aliases that point to the correct compilers as shown in the next figure.<\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv004.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1161\" title=\"native compilers\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv004-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>Now, we can use the interactive <strong>ccmake<\/strong> to configure the build options:<\/p>\n<pre>\r\nccmake .. -DCMAKE_C_COMPILER=\/usr\/bin\/gcc -DCMAKE_CXX_COMPILER=\/usr\/bin\/g++\r\n<\/pre>\n<p>Type the &#8216;c&#8217; key to enter the configuration process. I use minimal options to configure the build process as shown in the following screenshots.<\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv005.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1164\" title=\"option 1\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv005-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv006.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1165\" title=\"option 2\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv006-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv007.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1168\" title=\"option 3\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv007-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv008.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1170\" title=\"option 4\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv008-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv009.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1172\" title=\"option 5\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv009-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv010.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1174\" title=\"option 6\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv010-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv011.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1176\" title=\"option 7\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv011-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>Type the key &#8216;c&#8217; again to validate all the options. After it is done, type the key &#8216;g&#8217; to generate the files for building OpenCV.<\/p>\n<p>In the <strong>Terminal<\/strong> window command line, enter <strong>make<\/strong> to start the building process. It may take some time.<\/p>\n<pre>\r\nmake\r\n<\/pre>\n<p>When it is 100% done with success, proceed to the installation step by:<\/p>\n<pre>\r\nsudo make install\r\n<\/pre>\n<p>It will prompt for the password. The process will install the files into proper folders of the Unix system.<\/p>\n<p>For the Java related files, they will be in the <strong>bin<\/strong> and <strong>lib<\/strong> sub-folders of the <strong>build<\/strong> folder. The <strong>opencv-246.jar<\/strong> file will be in the <strong>bin<\/strong> folder.<\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv014.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1182\" title=\"opencv-246.jar\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv014-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>The <strong>libopencv_java246.dylib<\/strong> will be in the <strong>lib<\/strong> folder.<\/p>\n<p><a href=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv015.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-1184\" title=\"libopencv_java246.dylib\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2013\/07\/opencv015-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>These two files:<\/p>\n<ul>\n<li>opencv-246.jar<\/li>\n<li>libopencv_java246.dylib<\/li>\n<\/ul>\n<p>will be in the <strong>code<\/strong> folder of the Processing sketch to work.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I posted the use of OpenCV in Processing, there were a number of queries about installing and building OpenCV in OSX. In this post, I try to summary the process. It assumes basic understandings of the Unix environment of the OSX system with the use of the Terminal command. Here are the steps.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[90],"tags":[3],"class_list":["post-1150","post","type-post","status-publish","format-standard","hentry","category-teaching","tag-opencv"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=1150"}],"version-history":[{"count":26,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1150\/revisions"}],"predecessor-version":[{"id":1278,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1150\/revisions\/1278"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1150"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}