Opencv For Mac

OpenCV is a computer vision library used extensively by people in the computer vision field. Until a couple of years ago, OpenCV was a bit hacky and the usage was not very straightforward. But determined efforts by multiple companies finally standardized the process and now it is nice and clean. Computer vision algorithms are computationally intensive, requiring lot of processing power to run in real time. Before OpenCV came along, the efforts were very fragmented and repetitive, and there was no standard library as such. Hence Intel decided to do something about it and came up with OpenCV. The advantage of OpenCV is that the algorithms are highly optimized and the library is available on almost all the popular platforms. I have outlined the procedure below to get OpenCV up and running on your Mac.

Apr 08, 2018  How to Install OpenCV on Mac OS with PYTHON This is a step-by-step tutorial on how to install OpenCV for your Mac computer. Install guide: https://kirr.co/uu. Before we can compile OpenCV on our system, we first need to install Xcode, Apple’s set of software development tools for the Mac Operating System. The easiest method to download Xcode is to open up the App Store application on your desktop, search for “Xcode” in the search bar, and then click the “Get” button. Jan 10, 2015  3. Using Macports to install OpenCV – it’s easier and perfect. Terminal is the best for entire installation. Tutorial: Step 1: Check XCode and Mac OSx. Make sure you are using stable version of Mac OSx and XCode. In my case, I’m using Mac OSx 10.10 Yosemite and XCode 6.1.1. Also install Command Line tools for your XCode!

Prerequisites

  • Make sure you have git command line tool installed on your machine. If not, I have described the procedure here.
  • Make sure Macports is installed on your machine. If not, you can get it here. Install it before you proceed.
  • If you don’t have cmake, run the following command to install it (this command uses Macports):

Downloading OpenCV

We are now ready to install OpenCV. Download the latest version of OpenCV from here. Make sure you download the version for your platform (Mac, Windows, etc). You will get a directory named opencv-2.x.x, depending on the latest version number.

If you don’t want to worry about downloading every time a new version is released, you can download the OpenCV git repo. This way, you can easily maintain and update your OpenCV version with a simple command. Open the terminal, go to a convenient location and download the OpenCV source code using the following command:

It will create a directory called “opencv” and download all the files here. When you want to update to a new version, just go to this folder and type the following command:

Preheat the oven to 400F. Put a large pot of water on the stove to boil. How to make cheese sauce from scratch.

This will update your repo to the latest version.

Installing OpenCV

Now that we have the source code for OpenCV, we need to build it. Run the following commands:

We need to place the libraries in the correct locations so that they are accessible. Run the following command:

This will install everything in the /usr/local/ directory. That’s it! OpenCV is now installed on your machine.

OpenCV with Xcode

Now that we have installed OpenCV, we are ready to use it in our C/C++ code. Xcode is the most popular IDE on Mac OS X, so we would naturally want to see how to use OpenCV on Xcode. I have outlined the procedure below:

  1. Open Xcode
  2. Select Xcode -> New -> Project.
  3. A new window will pop up. On the left sidebar, under “OS X”, select “Application” and choose “Command Line Utility”. Click “Next”
  4. In the next window, give a name for the project and make sure the “Type” field at the bottom is set to C++. Click “Next”
  5. In the left sidebar, you should be able to see your project name next to a small Xcode icon. Double click on the project. This should open the Build Settings tab (located on the top of the new window).
  6. In the “Architectures” section, make sure it is set to “Native architecture of the build machine”.
  7. Scroll down to the “Search Paths” section and set “Header Search Paths” to: /usr/local/include. You can do this by double-clicking on the blank space right next to “Header Search Paths” and clicking on the “+” symbol at the bottom left. After you add it, make sure you select “recursive” located on the end of the same row.
  8. Close this window.
  9. In the left sidebar, you should be able to see your project name with a folder icon next to it. If you expand it, you will see main.cpp. Now right click on this project and select “New group”. Name it “OpenCV Libraries”.
  10. Right click on “OpeCV Libraries” and select Add Files to “Project” … (the word “Project” would have been replaced with your project name)
  11. Press the “/” key to get the “Go to” folder prompt. Enter the following path: /usr/local/lib
  12. Select all the files whose names are of the form libopencv_*.dylib.
    Note: Although you don’t have to worry about this, it’s better to know anyway. There will be aliases in that file list as well. So before selecting a file, look at the file icon. If there’s an arrow on the icon, it means that this file is an alias. You don’t have to add these files, since they are just aliases (and not real files).
  13. Click “Add” and you are done!

Go to main.cpp and write a simple piece of OpenCV code. Check if it runs. If you see an error, read on.

Undefined symbols for architecture x86_64

When I first upgraded my Xcode to version 4.6, I got the following error:

I didn’t face any such problem in Xcode 4.4. Apparently a build setting seems to default to a different thing in Xcode 4.6. In fact, this started happening from Xcode 4.5 onwards. There is a simple fix for it.

Open Build Settings by double-clicking on the project name with the Xcode icon. In this window, under “Architectures” section, set “Base SDK” to “Current OX S”. Now scroll down to “Apple LLVM compiler 4.1 – Language” section. In “C++ Language Dialect”, change it to “Compiler Default”. In “C++ Standard Library”, change it from “libc++ (LLVM …)” to “libstdc++ (GNU C++ …)”.

That should do the trick for you. If not, there is another way to run OpenCV code. Keep reading!

Running OpenCV Code From Command Line

This is the last sure shot way of running OpenCV code, but you will miss out on the niceness of an IDE. You can use cmake to build and run OpenCV code. Open the Finder and create a folder for your project. Place your .cpp file there. Create a file called “CMakeLists.txt” and place the following lines in that file:

In the above lines, replace “PROJECT_NAME” with your project name and replace filename by your source code file name. For example, if your project name is “OBJECT_TRACKING” and your filename is “tracker.cpp”, then the contents of CMakeLists.txt should be:

Once you create this file, run the following commands in the same directory:

You should now be able to see the executable with the same name as the your .cpp file. Now open the terminal and just type the following to run the code:

If you have any command line arguments that you are taking in your .cpp file, give them here:

Opencv

And there you go! You are all set to do some OpenCV coding.

————————————————————————————————-

OpenCV is a computer vision library used extensively by people in the computer vision field. Until a couple of years ago, OpenCV was a bit hacky and the usage was not very straightforward. But determined efforts by multiple companies finally standardized the process and now it is nice and clean. Computer vision algorithms are computationally intensive, requiring lot of processing power to run in real time. Before OpenCV came along, the efforts were very fragmented and repetitive, and there was no standard library as such. Hence Intel decided to do something about it and came up with OpenCV. The advantage of OpenCV is that the algorithms are highly optimized and the library is available on almost all the popular platforms. I have outlined the procedure below to get OpenCV up and running on your Mac.

Download Opencv For Mac

Prerequisites

  • Make sure you have git command line tool installed on your machine. If not, I have described the procedure here.
  • Make sure Macports is installed on your machine. If not, you can get it here. Install it before you proceed.
  • If you don’t have cmake, run the following command to install it (this command uses Macports):

Downloading OpenCV

We are now ready to install OpenCV. Download the latest version of OpenCV from here. Make sure you download the version for your platform (Mac, Windows, etc). You will get a directory named opencv-2.x.x, depending on the latest version number.

If you don’t want to worry about downloading every time a new version is released, you can download the OpenCV git repo. This way, you can easily maintain and update your OpenCV version with a simple command. Open the terminal, go to a convenient location and download the OpenCV source code using the following command:

Download Opencv For Mac Os

It will create a directory called “opencv” and download all the files here. When you want to update to a new version, just go to this folder and type the following command:

This will update your repo to the latest version.

Installing OpenCV

Now that we have the source code for OpenCV, we need to build it. Run the following commands:

We need to place the libraries in the correct locations so that they are accessible. Run the following command:

This will install everything in the /usr/local/ directory. That’s it! OpenCV is now installed on your machine.

OpenCV with Xcode

Now that we have installed OpenCV, we are ready to use it in our C/C++ code. Xcode is the most popular IDE on Mac OS X, so we would naturally want to see how to use OpenCV on Xcode. I have outlined the procedure below:

  1. Open Xcode
  2. Select Xcode -> New -> Project.
  3. A new window will pop up. On the left sidebar, under “OS X”, select “Application” and choose “Command Line Utility”. Click “Next”
  4. In the next window, give a name for the project and make sure the “Type” field at the bottom is set to C++. Click “Next”
  5. In the left sidebar, you should be able to see your project name next to a small Xcode icon. Double click on the project. This should open the Build Settings tab (located on the top of the new window).
  6. In the “Architectures” section, make sure it is set to “Native architecture of the build machine”.
  7. Scroll down to the “Search Paths” section and set “Header Search Paths” to: /usr/local/include. You can do this by double-clicking on the blank space right next to “Header Search Paths” and clicking on the “+” symbol at the bottom left. After you add it, make sure you select “recursive” located on the end of the same row.
  8. Close this window.
  9. In the left sidebar, you should be able to see your project name with a folder icon next to it. If you expand it, you will see main.cpp. Now right click on this project and select “New group”. Name it “OpenCV Libraries”.
  10. Right click on “OpeCV Libraries” and select Add Files to “Project” … (the word “Project” would have been replaced with your project name)
  11. Press the “/” key to get the “Go to” folder prompt. Enter the following path: /usr/local/lib
  12. Select all the files whose names are of the form libopencv_*.dylib.
    Note: Although you don’t have to worry about this, it’s better to know anyway. There will be aliases in that file list as well. So before selecting a file, look at the file icon. If there’s an arrow on the icon, it means that this file is an alias. You don’t have to add these files, since they are just aliases (and not real files).
  13. Click “Add” and you are done!

Go to main.cpp and write a simple piece of OpenCV code. Check if it runs. If you see an error, read on.

Undefined symbols for architecture x86_64

When I first upgraded my Xcode to version 4.6, I got the following error:

I didn’t face any such problem in Xcode 4.4. Apparently a build setting seems to default to a different thing in Xcode 4.6. In fact, this started happening from Xcode 4.5 onwards. There is a simple fix for it.

Open Build Settings by double-clicking on the project name with the Xcode icon. In this window, under “Architectures” section, set “Base SDK” to “Current OX S”. Now scroll down to “Apple LLVM compiler 4.1 – Language” section. In “C++ Language Dialect”, change it to “Compiler Default”. In “C++ Standard Library”, change it from “libc++ (LLVM …)” to “libstdc++ (GNU C++ …)”.

That should do the trick for you. If not, there is another way to run OpenCV code. Keep reading!

Running OpenCV Code From Command Line

This is the last sure shot way of running OpenCV code, but you will miss out on the niceness of an IDE. You can use cmake to build and run OpenCV code. Open the Finder and create a folder for your project. Place your .cpp file there. Create a file called “CMakeLists.txt” and place the following lines in that file:

In the above lines, replace “PROJECT_NAME” with your project name and replace filename by your source code file name. For example, if your project name is “OBJECT_TRACKING” and your filename is “tracker.cpp”, then the contents of CMakeLists.txt should be:

Once you create this file, run the following commands in the same directory:

You should now be able to see the executable with the same name as the your .cpp file. Now open the terminal and just type the following to run the code:

Formatting external hard drive for mac and pc. This is one of the most widely recognized file system formats. FAT32 – a file system normally used on USB disks.

Opencv For Machine Vision

If you have any command line arguments that you are taking in your .cpp file, give them here:

Opencv For Linux/mac

And there you go! You are all set to do some OpenCV coding.

Opencv For Mac Python

————————————————————————————————-