Clion 2022.1 已经自带Mingw环境,无需再配置。
请使用Clion自带的mingw环境或者自己安装mingw环境。Cygwin目前还没有已经编译好的可用。需要自己编译。
GitHub - huihut/OpenCV-MinGW-Build: MinGW 32bit and 64bit version of OpenCV compiled on Windows. Including OpenCV 3.3.1, 3.4.1, 3.4.1-x64, 3.4.5, 3.4.6, 3.4.7, 3.4.8-x64, 3.4.9, 4.0.0-alpha-x64, 4.0.0-rc-x64, 4.0.1-x64, 4.1.0, 4.1.0-x64, 4.1.1-x64, 4.5.0-with-contrib, 4.5.2-x64https://github.com/huihut/OpenCV-MinGW-Build点击zip下载 例如:
https://github.com/huihut/OpenCV-MinGW-Build/archive/refs/tags/OpenCV-4.5.5-x64.zip
解压后,放到一个目录下,环境变量Path中添加OpenCV根目录\x64\mingw\bin
例如,我解压到C:\Program Files\OpenCV
那么将C:\Program Files\OpenCV\x64\mingw\bin添加到path中。
Clion 新建项目,在CMakeList.txt中,添被***包围的3行代码,其中OpenCV_DIR 为解压后的OpenCV根目录。
例如,我解压到C:\Program Files\OpenCV
那么,OpenCV_DIR 就是C:\\Program Files\\OpenCV
注意使用双\\
cmake_minimum_required(VERSION 3.21)
project(opencv)
set(CMAKE_CXX_STANDARD 14)
# ************
set(OpenCV_DIR C:\\Program Files\\OpenCV)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# ************
add_executable(opencv main.cpp)
target_link_libraries(opencv ${OpenCV_LIBS})
记得重启Clion
记得重启Clion
记得重启Clion
不然提示编译能通过,运行时显示代码-14****。
#include "iostream"
#include
using namespace std;
using namespace cv;
int main() {
Mat img = imread(R"(C:\Users\a\Desktop\fig1.png)");
imshow("aaa",img);
waitKey();
return 0;
}
0.使用Clio高版本自带的Mingw环境或者自己下mingw环境。
1.下载OpenCV-MinGW
https://github.com/huihut/OpenCV-MinGW-Build/archive/refs/tags/OpenCV-4.5.5-x64.zip
2.解压
解压到C:\Program Files\OpenCV
3.环境变量配置
Path中添加C:\Program Files\OpenCV\x64\mingw\bin
4.Clion CMakeList.txt改一下代码
cmake_minimum_required(VERSION 3.21)
project(opencv)
set(CMAKE_CXX_STANDARD 14)
# ************
set(OpenCV_DIR C:\\Program Files\\OpenCV)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# ************
# add_executable、target_link_libraries 项目名是opencv,根据实际项目名称修改
add_executable(opencv main.cpp)
# ************
target_link_libraries(opencv ${OpenCV_LIBS})
# ************
5.重启Clion