Windows Clion配置OpenCV环境

OpenCV

计算机视觉库

官网:https://opencv.org/

CMake官网:https://cmake.org/

MinGW-64:https://sourceforge.net/projects/mingw-w64/files/

编译思路:使用cmake将源码编译成mingw版本,在使用mingw install到本地,最后在clion中在CMakeLists.txt配置

MinGW在Windows上编译的OpenCV的32位和64位版本

编译好的,直接在clion中使用即可

OpenCV-MinGW-Build:https://github.com/huihut/OpenCV-MinGW-Build

Clion配置

下载OpenCV-MinGW-Build

Windows Clion配置OpenCV环境_第1张图片

添加至环境变脸

在系统环境变量PATH中加上刚才解压的opencv的目录

D:\Applications\OpenCV-MinGW-Build-OpenCV-4.0.0-rc-x64\x64\mingw\bin

CMakeLists.txt

注意

cmake_minimum_required(VERSION 3.15)
# 项目名称
project(opencv_demo)

set(CMAKE_CXX_STANDARD 14)

add_executable(untitled2 main.cpp)
# OpenCV-MinGW-Build
set(OpenCV_DIR D:/Applications/OpenCV-MinGW-Build-OpenCV-4.0.0-rc-x64)
FIND_PACKAGE(OpenCV REQUIRED)
# 项目名称
TARGET_LINK_LIBRARIES(opencv_demo ${OpenCV_LIBS})

测试程序

#include 
#include 
#include 

using namespace std;

int main()
{
    cv::Mat srcImage=cv::imread("D:\\CLionProjects\\untitled2\\1.png");
    imshow("源图像",srcImage);
    cv::waitKey(0);
    return 0;
}

Reference

CLion + OpenCV + cmake,源码编译及使用:https://blog.csdn.net/bby1987/article/details/108985356

你可能感兴趣的:(安装教程,opencv,windows,c++)