Mac clion configuring opencv environment

Start by installing OpenCV4.0.1 with Homebrew

$ brew install opencv

If Open3.4.5 is installed

brew install opencv@3

** If you need –with OpenGL ** you need to [download] to [email protected] and change the compilation configuration.
brew install ./[email protected]
Update if you find any updates;
Then configure it in the CLion project cmMakelists.txt as follows:

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})

Then you can write main.cpp to verify that:

#include <iostream>
#include <opencv2/opencv.hpp>

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;
}

You can display the photo, but if you can’t find the photo, change the path to the absolute path.
the original: https://blog.csdn.net/u010319740/article/details/79012810

Read More: