VScode編譯opencv(Cmake + MinGW)
1.環境搭建
1.MinGW
2.已經編譯的opencv,網上搜尋OpenCV-MinGW-Build-OpenCV-4.1.1-x64下載即可
3.VS code的外掛 Cmake tools
2.Cmake編譯檔案
CMakeLists.txt檔案如下:
cmake_minimum_required(VERSION 3.0.0)
project(isp VERSION 0.1.0)
include(CTest)
enable_testing()
#設定平臺 x86
set(platform x86)
#標頭檔案
set(OpenCV_INCLUDE_DIRS H:/project/algo/opencv/OpenCV-MinGW-Build-OpenCV-4.1.1-x64/include/)
include_directories(./ ./core ${OpenCV_INCLUDE_DIRS})
# 新增子目錄
#add_subdirectory(core) 子目錄需要有CMakeList.txt
# 新增資料夾及其檔案,自動新增資料夾中的檔案
aux_source_directory(. DIRSRCS)
add_executable(isp ${DIRSRCS})
#################################################opencv 部分 方式1 find #####################################
#指定OpenCV版本,程式碼如下
#find_package(OpenCV 3.3 REQUIRED)
#如果不需要指定OpenCV版本,程式碼如下
#set(CMAKE_MODULE_PATH H:\\project\\algo\\opencv\\OpenCV-MinGW-Build-OpenCV-3.4.5\\x86\\mingw\\lib\\)
#set(OpenCV_DIR H:\\project\\algo\\opencv\\OpenCV-MinGW-Build-OpenCV-3.4.5\\x86\\mingw\\lib\\)
#find_package(OpenCV REQUIRED)
#顯示OpenCV_INCLUDE_DIRS的值
#message(${OpenCV_INCLUDE_DIRS})
# 新增一個可執行程式
# 語法:add_executable( 程式名 原始碼檔案 )
#add_executable( isp ${DIRSRCS} )
# 將庫檔案連結到可執行程式上
#target_link_libraries( isp ${OpenCV_LIBS})
#################################################opencv 部分 方式2 #####################################
# 依賴庫
# 尋找OpenCV庫
set(OpenCV_DIR H:/project/algo/opencv/OpenCV-MinGW-Build-OpenCV-4.1.1-x64/x64/mingw/bin/)
SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
set(CMAKE_MODULE_PATH ${OpenCV_DIR})
set(CMAKE_PREFIX_PATH ${OpenCV_DIR})
# 連結OpenCV庫路徑
link_directories(${OpenCV_DIR})
#find_library(OpenCV_LIBS libopencv_core411 ${OpenCV_DIR} ) libopencv_imgproc411
find_library(OpenCV_LIBS1
NAMES libopencv_core411
PATHS ${OpenCV_DIR}
NO_DEFAULT_PATH)
find_library(OpenCV_LIBS
NAMES libopencv_imgproc411
PATHS ${OpenCV_DIR}
NO_DEFAULT_PATH)
find_library(OpenCV_LIBS2
NAMES libopencv_imgcodecs411
PATHS ${OpenCV_DIR}
NO_DEFAULT_PATH)
find_library(OpenCV_LIBS3
NAMES libopencv_highgui411
PATHS ${OpenCV_DIR}
NO_DEFAULT_PATH)
#message(STATUS "test")
message("${OpenCV_LIBS}")
message("${OpenCV_LIBS1}")
message("${OpenCV_LIBS2}")
# 連結OpenCV庫
#SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")
target_link_libraries(isp ${OpenCV_LIBS} ${OpenCV_LIBS1} ${OpenCV_LIBS2} ${OpenCV_LIBS3})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
H:/project/algo/opencv/OpenCV-MinGW-Build-OpenCV-4.1.1-x64/ 為在網上下載的已經編譯好的Opencv。
C++程式碼:
using namespace std;
using namespace cv;
#include <opencv2/opencv.hpp>
Mat img =imread("main.jpg");
imshow("image",img);
waitKey();
總結
主要難點在於CmakeList檔案的配置,有不少的坑。
1.必須逐個的find_library,再 target_link_libraries。
相關文章
- Windows平臺使用CMake+MinGW64編譯OpenCVWindows編譯OpenCV
- Windows下CMake編譯安裝OpenCVWindows編譯OpenCV
- CMake生成OpenCV解決方案&&編譯OpenCV原始碼OpenCV編譯原始碼
- Mingw GCC 編譯OpenCV報錯: Project files may be invalidGC編譯OpenCVProject
- Win10下Qt+OpenCV+Cmake編譯錯誤Win10QTOpenCV編譯
- 使用vs2015+cmake編譯opencv+opencv_contrib編譯OpenCV
- Windows下OpenCV4.3.0+MinGW64+Cmake具體過程【詳細】WindowsOpenCV
- MinGW GCC 5.3.0 編譯OpenCV4.5.5 執行到imshow時崩潰GC編譯OpenCV
- 如何用cmake編譯編譯
- CMake for Mac編譯工具Mac編譯
- windows下基於cmake配置opencv並使用visual studio編譯WindowsOpenCV編譯
- 配置QT Mingw & opencvQTOpenCV
- 用mingw編譯tcc原始碼編譯原始碼
- mingw編譯jsoncpp 轉載編譯JSON
- cmake編譯指定自己編譯的庫路徑編譯
- mingw64 cmake build commandUI
- MinGW環境編譯WonderTrader攻略編譯
- CMake入門指南-編譯教程編譯
- cmake編譯問題解決編譯
- 從編譯連結到cmake編譯
- 用mingw編譯lua5.3原始碼編譯原始碼
- qtCreator中配置opencv和mingwQTOpenCV
- cmake中新增 -g編譯選項編譯
- Qt 中有兩種方式編譯MinGW和MSVCQT編譯
- mingw下編譯zlib quazip動態庫編譯
- windows下用mingw編譯linux專案Windows編譯Linux
- CLion 配置 C C++ 編譯環境(MinGW)C++編譯
- CMake編譯Qt工程時的問題編譯QT
- opencv 編譯常見錯誤OpenCV編譯
- windows安裝cmake、opencv、qtWindowsOpenCVQT
- Matlab安裝MinGW-w64編譯器Matlab編譯
- mingw 編譯生成的dll 如何在vs中使用編譯
- 在WSL下為OpenWRT交叉編譯出CMake編譯
- 樹莓派編譯OpenCV報錯樹莓派編譯OpenCV
- Qt for Windows:Qt 5.8.0 MinGW 靜態編譯版本(包含OpenSSL)QTWindows編譯
- win10 VScode配置GCC(MinGW)Win10VSCodeGC
- [cmake]如何設定Debug和Release編譯模式編譯模式
- cmake使用教程(九)-關於安卓的交叉編譯安卓編譯