1、官网下载Clion:https://www.jetbrains.com/clion/
2、Clion安装过程很简单,正常安装就行,...................
3、MinGW+OpenCV,若想根据自己的Win10环境编译OpenCV,需下载MinGW和OpenCV源码:
MinGW下载地址:MinGW-w64 - for 32 and 64 bit Windows
OpenCV源码下载地址:OpenCV-Releases
编译过程并不复杂,但是比较坎坷,具体过程可以参考这篇博文:CLion + OpenCV + cmake,源码编译及使用
4、博主则使用大佬编译好的版本,下载大佬编译好的相应MinGW版本的OpenCV,下载地址:OpenCV-MinGW-BuildOpenCV-MinGW-Build
下载OpenCV 4.1.0和对应的MinGW版本,并解压放到某个文件夹中(如:D:\ProgramData),在Clion中进行设置即可
5、打开安装好的Clion,依次点击 File----->settings----->Build,Execution,Deployment-------->Toolchains, 将下载并解压好的MinGW添加到编译环境中,如下图:
默认仅有Debug模式,可以依次点击 File----->settings----->Build,Execution,Deployment-------->Cmake, 创建 Release 模式:
6、分别在CmakeLists.txt和代码中配置OpenCV, 如图:
即:
project(demo)
#set(CMAKE_CXX_STANDARD 14)
add_executable(demo main.cpp)
cmake_minimum_required(VERSION 3.14)
set(CMAKE_CXX_STANDARD 15)
# 可以将下面的路径单独添加到环境变量OpenCV_DIR
set(OpenCV_DIR "D:\\ProgramData\\OepnCV\\OpenCV-MinGW-Build-OpenCV-4.1.0-x64")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
#set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# "test"与你工程的命名相关,注意和原来CMakeList.txt中的声明一致
target_link_libraries(demo ${OpenCV_LIBS})
在测试代码中包含OpenCV头文件,即:
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
string imagePath = "E:\\programme\\C_C++\\CLion\\demo\\hhhh.jpg";
// string imagePath = "hhhh.jpg";
Mat image = imread(imagePath);
resize(image, image, Size(1024, 1024));
namedWindow("TestOpenCV", 0);
imshow("TestOpenCV", image);
waitKey(0);
destroyAllWindows();
return 0;
}
7、若clion使用opencv导入成功运行时出错:Process finished with exit code -1073741515 (0xC0000135)
原因:OpenCV运行时,需要的.dell文件未加载到, 这些文件在...x64\mingw\bin 中
解决方案:
方法1、将.dell 所在文件夹的绝对路径添加到win10系统环境变量和用户变量中,重启Clion,运行程序即可
方法2、点击Edit Configurations:
选择 Environment variables:
填入opencv编译后的bin文件夹:
方法3、选择 Working directory,而不是方法2中的 Environment variables:
填入opencv编译后的bin文件夹:
至此,所有配置完成,可以愉快的运行代码了
Reference:
CLion + OpenCV + cmake,源码编译及使用
clion win10 msvc opencv报错Process finished with exit code -1073741515 (0xC0000135)
opencv Process finished with exit code -1073741515