Ayoung
Ayoung

Reputation: 351

How can I install opencv2 with brew under OSX

Recently, I installed opencv with the following command:

brew install opencv

I found opencv3 was installed in dir /usr/include and /usr/lib. But what I want is opencv2. How can install opencv2 with the brew command?

Upvotes: 18

Views: 21647

Answers (3)

Johnny Cheesecutter
Johnny Cheesecutter

Reputation: 2852

Unfortunately 'brew' stopped supporting downloading outdated package versions. However, if you really need a deprecated version of a package in some cases you may try to find it's formula on git/homebrew and manually install it.

For example this is a formula for 'opencv@2': https://github.com/Homebrew/homebrew-core/blob/5dfd4d4d69cc70e496f9b46801c96a66f4b008eb/Formula/opencv%402.rb

But in case of 'opencv2' this will be very problematic, because the package requires 'python v2' and another outdated package '[email protected]'. After that even if you'll manage to install all three packages from their formulas brew just won't be able to create correct symlinks between them...

Thus last time when I found a package that was depended on opencv@2 I found that it was far easier to make changes in the package C++ functions and make the package work with opencv v4.x (most recent one). Despite that I'm purely Python developer still this proved to be faster. OpenCV code doesn't change a lot, so most probably you will need to fix imports in the C++ / python code.

Upvotes: 0

Mark Setchell
Mark Setchell

Reputation: 207540

The easiest way to find the answer is to use brew search to look for available packages. So, in your case:

brew search opencv

There you will see the package opencv@2 listed. So, you need:

brew install opencv@2

Upvotes: 41

TravHola
TravHola

Reputation: 91

I can't give you a answer in context of using brew but I can assist you with a valuable resource that really helped me out when I was first started out with OpenCV that got me up and developing https://www.youtube.com/watch?v=U49CVY8yOxw

  1. Install Xcode , Install C-Make

  2. Download OpenCV source code https://github.com/opencv/opencv/releases/tag/3.1.0

  3. Build and install!

INSTRUCTIONS: Go inside OpenCV once downloaded create new folder called build. Next, open CMake GUI find the directory we just created " build " to build the binaries, Click configure, Select "Unix Makefiles" and use native default compilers. cd into out build directory in our OpenCV folder so something like this /Users/you/Desktop/openCvFolder/build and run the command "make" and go have a coffee! I hope this helps it helped me out when I first started experimenting a year ago with OpenCV

Upvotes: 2

Related Questions