Clion+OpenCV(以Visual Studio为编译环境)

1 首先在Clion中配置Visual Studio编译环境Clion+OpenCV(以Visual Studio为编译环境)_第1张图片

2 创建一个控制台程序

Clion+OpenCV(以Visual Studio为编译环境)_第2张图片

3 编写CMakeList.txt文件

cmake_minimum_required(VERSION 3.13)
project(demo_c)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES, main.cpp)

set(OpenCV_DIR E://opencv//build) # 路径为自己下载的OpenCV路径
find_package(OpenCV 3 REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(demo_c main.cpp)
target_link_libraries(demo_c ${OpenCV_LIBS})

编译的结果如图所示
Clion+OpenCV(以Visual Studio为编译环境)_第3张图片

4 编写程序验证

#include 
using namespace std;
using namespace cv;
int main()
{

    Mat img = imread("E:\\demo_c\\test.png"); 
    if(img.empty())
    {
        fprintf(stderr, "Can not load image\n");
        return -1;
    }
    imshow("image", img);
    waitKey();
    return 0;
}

你可能感兴趣的:(Clion+OpenCV(以Visual Studio为编译环境))