MacOS Xcode 10.2.1 configures OpenCV 4.1.0

command line installation

  1. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)
  2. brew install wget
  3. brew install cmake
  4. brew install opencv will automatically choose to install OpenCV 4.1.0 version

Xcode project configuration

  1. Create a new Command Line Tool project and select C++ as the language.
  2. Click on the project to find "Search Paths" and add related directories:
    a. Header Search Paths - add "/usr/local/include/opencv4"
    b. Library Search Paths - add "/usr/local/lib" and "/usr /local/Cellar/opencv/4.1.0_2/lib"
  3. Right-click the project to create a new folder (Group) and drag the "*.dylib" file in the "/usr/local/Cellar/opencv/4.1.0_2/lib" folder into it

test

#include <iostream>

#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, const char * argv[]) {
	//! 读入一个图片,在此其路径是"/Users/tang/testPic.jpg"
    Mat mat_image_src = imread("/Users/tang/testPic.jpg");
    imshow("before",mat_image_src);
    Mat mat_image_dst;
    Canny(mat_image_src, mat_image_dst, 20, 50);
    imshow("after Canny", mat_image_dst);
    waitKey();
    return 0;
}

result
insert image description here

Guess you like

Origin blog.csdn.net/weixin_41243045/article/details/93026124