1. 程式人生 > >如何在macOS mojave上安裝opencv4給vscode使用

如何在macOS mojave上安裝opencv4給vscode使用

 

 

first, install opcv4, the newest one. but brew install opencv will only get a version 3,

Another way is to use source code and compile it locally, but it's slow.

My way is from https://gocv.io/getting-started/macos/

 

 then another pit is to include opencv header file:

in vscode, there should be a c_cpp_properties.json

add line 7

 

in this folder, there's a folder /opencv4/opencv2/...

here one easy way might be #include <opencv4/opencv2/...> all the time, but actually it will fail to some opcv's reasons.

So we have to either move opencv2 folder to /include/ or do a soft link:

ln -sf opencv4/opencv2 opencv2

 

at last, when we are going to compile file including opencv, we should use:

g++ -std=c++11 main.cpp -o a.out `pkg-config --cflags --libs opencv4`

## cautious: use opencv4 rather than opencv, because in /usr/local/lib/pkgconfig, there's only the file named opencv4.pc