Win10+MinGW+Clion+Opencv完美安装

     最近由于图像识别项目需要装OpenCV,平时都是用java开发。习惯了www.jetbrains.com的intellij idea。因此这次也选择该公司的Clion。毕竟学生党来说VS还是太巨量,不太方便。

      一,Clion 安装,配置

   参考  https://blog.csdn.net/qq_38013968/article/details/70660349。注册成功

   二,MinGW

 http://kent.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/6.3.0/threads-posix/seh/x86_64-6.3.0-release-win32-seh-rt_v5-rev1.7z

   安装完成将bin目录放进环境变量


     三,Opencv

      https://www.opencv.org/releases.html

     四,CMake 

     https://cmake.org  打开C:\Program Files\CMake\bin中 cmake-gui.exe

   Win10+MinGW+Clion+Opencv完美安装_第1张图片

     文件夹分别选择opencv目录下的sources和build目录 ,然后configure  。完成之后再generate;

     完成之后打开CMD窗口 定位到 opencv/build/目录下  执行命令  mingw32-make;

Win10+MinGW+Clion+Opencv完美安装_第2张图片

   

如果报如下错误:'thread' is not a member of 'std



If you are compiling this on windows, you will need Mingw-Builds v4.8.1 with posix-threads: sourceforge.net/projects/mingwbuilds/files/host-windows/… You can choose between sjlj and seh. Seh is only x64 and sjlj is both x32 and x64.

 就是说mingw版本不对,我在这里纠结了半天,终于找到一个老外的回答。赶紧回头重新下载了一个 。一次通过 。


Win10+MinGW+Clion+Opencv完美安装_第3张图片

好了 建个项目试试,打开Clion  File-settings  配置MinGW。

新建项目,再cmakelists.txt 添加如下代码:

cmake_minimum_required(VERSION 3.8)
project(untitled)
set (CMAKE_CXX_STANDARD 11)
set(OpenCV_DIR "D:\\opencv\\build\\install")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(untitled main.cpp)
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
target_link_libraries(untitled ${OpenCV_LIBS})

Reload Cmake  project

测试代码如下:

#include
using namespace std;
using namespace cv;



int main() {
    Mat a=imread("../res/board.jpg",CV_8UC4);
    namedWindow("test",WINDOW_AUTOSIZE);
    imshow("test",a);
    waitKey(0);
    return 0;


}

Win10+MinGW+Clion+Opencv完美安装_第4张图片


你可能感兴趣的:(opencv)