Mac CLion配置OpenCV环境

首先用Homebrew安装opencv4.0.1

$ brew install opencv

如果安装open3.4.5

brew install opencv@3

** 如果需要 --with opengl ** 需要【下载】到本地:[email protected] ,修改里面的编译配置。
brew install ./[email protected]

如果发现有更新就更新;

然后在CLion项目中的CMakeLists.txt中配置如下:

cmake_minimum_required(VERSION 3.9)
project(untitled1)

set(CMAKE_CXX_STANDARD 11)

#find_library(OpenCV)
find_package(OpenCV)

include_directories(${OpenCV_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)

add_executable(untitled1 main.cpp)

target_link_libraries(untitled1 ${OpenCV_LIBS})

然后就可以写个main.cpp验证下:

#include 
#include 

using namespace std;
using namespace cv;

int main() {
    Mat srcImage = imread("your_img_path.jpg");
    if (!srcImage.data) {
        std::cout << "Image not loaded";
        return -1;
    }
    imshow("[img]", srcImage);
    waitKey(0);
    return 0;
}

能显示照片即可,注意如果找不到照片的话,改为路径使用绝对路径。
原文:https://blog.csdn.net/u010319740/article/details/79012810

你可能感兴趣的:(opencv)