mrgloom
mrgloom

Reputation: 21602

How to set path to opencv on Mac OS?

I'm using mac os 10.10 and I need to build some code via make, but it give me an error

make
gcc `pkg-config --cflags opencv` -O3 `pkg-config --libs opencv` -o congealReal congealReal.cpp
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
congealReal.cpp:87:10: fatal error: 'cv.h' file not found
#include <cv.h>

but I have already installed opencv via brew

brew install opencv
Warning: homebrew/science/opencv-2.4.11_2 already installed

so how can I set up environment to opencv in mac os?

Upvotes: 1

Views: 13111

Answers (3)

Pooya Panahandeh
Pooya Panahandeh

Reputation: 638

I had a same problem and I solved it with the following steps. First Update Homebrew.

brew update

Second Step: Install package config:

brew install pkg-config

Third Step: install OpenCV if you didn't

brew install opencv@2

Fourth Step: Now you need to add OpenCV to your pkg-config

export PKG_CONFIG_PATH="/usr/local/opt/opencv@2/lib/pkgconfig"

Upvotes: 6

tamtam
tamtam

Reputation: 701

Something that might be helpful after you have installed pkg-config...

brew most likely installed your opencv to /usr/local/Cellar/opencv/3.4.3.

You might also have multiple opencv's installed (either through brew or source code, etc). If you run

pkg-config --cflags --libs opencv

it might say -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_shape which indicates that the opencv that is being pointed to is not the one you installed with brew.

Therefore, replace the above with

pkg-config --cflags --libs /usr/local/Cellar/opencv/3.4.3/lib/pkgconfig/opencv.pc

Adjust your brew directory and opencv version as necessary. This matters because packages could be different across opencv installations.

Upvotes: 1

rs_
rs_

Reputation: 453

You probably don't have pkg-config installed. Please do,

brew install pkg-config

This should remove the pkg-config: command not found errors.

After installing this, add the path of opencv.pc file into the .profile or .bash_profile file.

Upvotes: 0

Related Questions