mac os 下边 opencv3.4.1 编译

opnecv_contrib 里边包含了新的扩展,所以编译时要加进去,否则一些sift ORB
算法不能用。

1. 下载 opencv source 3.4.1 从官网下载 

2.下载 opencv_contrib   https://github.com/opencv/opencv_contrib

3.cd opencv 

4.mkdir build

5.cd build

 

Try this:---
You need opencv_contrib also
$ cd ..
$ git clone https://github.com/Itseez/opencv_contrib.git
$ cd opencv_contrib
$ git checkout 3.4.1

Note :- replace 3.4.1 with your opencv version

$ cd ~/opencv
$ mkdir build
$ cd build

cmake -G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-D BUILD_EXAMPLES=OFF ..

 

7. make -j4

8. sudo make install 

这里在xcode 写测试代码

新建工程: 在工程当中加入下边内容

设置Header Search Paths: /usr/local/include 
设置Library Search Paths: /usr/local/lib 
设置Other Linker Flags: (如图)

-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab

// 测试代码

#include

#include

using namespace cv;

int  main()

{

    Mat img = imread("/tmp/1.jpg", CV_LOAD_IMAGE_UNCHANGED);

    

    if(img.empty())

    {

        fprintf(stderr, "failed to load input image\n");

        return -1;

    }

    

    imshow("Display Image", img);

    waitKey(0);

    

    return 1;

}

如果是opencv 3.4.3 编译用:

cmake -G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE=RELEASE \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-D BUILD_EXAMPLES=OFF ..

你可能感兴趣的:(mac os 下边 opencv3.4.1 编译)