1.clion 配置mingw64編譯(mingw64下載地址:https://nuwen.net/mingw.html,而後bin路徑配置環境變量)html
2. cmake gui下載(下載地址:https://cmake.org/download/)c++
3.opencv 的源碼下載(opencv 下載地址:https://opencv.org/releases.html;opencv_contrib(有額外的功能)下載地 址: https://github.com/opencv/opencv_contrib/releases,兩個版本一致便可)git
4.打開cmake gui ,source code路徑選擇opencv路徑,build binaries選擇本身想要opencv build的路徑(自定義),而後點擊configure ,configure done後,點擊generate(若出現問題,google,通常的話可能須要去掉一些選項),generate done 後,找到opencv build路徑,在cmd環境中用mingw32-make -j8編譯(有問題google,通常仍是更改cmake gui 的一些選項),編譯完成後,在執行安裝mingw32-make install,安裝完成後,在clion 中配置cmakelists.txt,如:github
#cmake 最低版本要求 cmake_minimum_required(VERSION 3.13) #項目信息 project(play) #指定c++標準是c++ 11 set(CMAKE_CXX_STANDARD 11) ## where to find opencv set(OpenCV_DIR "D:\\22m\\opencv\\build\\install") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) #指定生成目標,將main.cpp編譯成play的可執行文件 add_executable(play cpp/main.cpp) # add libs you need set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs opencv_xfeatures2d) # linking target_link_libraries(play ${OpenCV_LIBS})
而後cpp調用:ui
//about opencv #include <opencv2/opencv.hpp> #include <opencv2/xfeatures2d.hpp> //namespace using namespace std; using namespace cv; using namespace cv::xfeatures2d; //start int main() { Mat img = imread("../img/desktop.jpg"); Ptr<SURF> surf; surf = SURF::create(800); imshow("desktop.jpg", img); waitKey(); return 0; }
最後終於完成了。google