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
- 使用vs2015+cmake編譯opencv+opencv_contrib編譯OpenCV
- Mingw GCC 編譯OpenCV報錯: Project files may be invalidGC編譯OpenCVProject
- Win10下Qt+OpenCV+Cmake編譯錯誤Win10QTOpenCV編譯
- MinGW GCC 5.3.0 編譯OpenCV4.5.5 執行到imshow時崩潰GC編譯OpenCV
- windows下基於cmake配置opencv並使用visual studio編譯WindowsOpenCV編譯
- Windows下OpenCV4.3.0+MinGW64+Cmake具體過程【詳細】WindowsOpenCV
- mingw編譯jsoncpp 轉載編譯JSON
- MinGW環境編譯WonderTrader攻略編譯
- 配置QT Mingw & opencvQTOpenCV
- 如何用cmake編譯編譯
- CMake for Mac編譯工具Mac編譯
- mingw64 cmake build commandUI
- cmake編譯指定自己編譯的庫路徑編譯
- mingw下編譯zlib quazip動態庫編譯
- 從編譯連結到cmake編譯
- Qt 中有兩種方式編譯MinGW和MSVCQT編譯
- cmake中新增 -g編譯選項編譯
- mingw 編譯生成的dll 如何在vs中使用編譯
- win10 VScode配置GCC(MinGW)Win10VSCodeGC
- opencv 編譯常見錯誤OpenCV編譯
- CMake編譯Qt工程時的問題編譯QT
- vscode+C 編譯除錯VSCode編譯除錯
- windows安裝cmake、opencv、qtWindowsOpenCVQT
- 樹莓派編譯OpenCV報錯樹莓派編譯OpenCV
- [cmake]如何設定Debug和Release編譯模式編譯模式
- 在WSL下為OpenWRT交叉編譯出CMake編譯
- Vim+CMake+MinGW配置C/C++開發環境C++開發環境
- 使用CMake命令編譯Android平臺下的包編譯Android
- gRPC cmake Visual Studio編譯安裝 (全命令列)RPC編譯命令列
- protobuf cmake Visual Studio 編譯安裝 (全命令列)編譯命令列
- 編譯Sophus時cmake出現警告deprecated-declarations編譯
- ubuntu系統編譯安裝OpenCV 4.4Ubuntu編譯OpenCV
- windows下使用mingw和msvc靜態編譯Qt5.15.xxWindows編譯QT
- vscode在ctrl+shift+b選擇cmake編譯後怎麼快速切回terminal執行一把?VSCode編譯
- 編譯OpenCV——ubuntu x86_64平臺編譯OpenCVUbuntu
- <<Modern CMake>> 翻譯 2. CMake 基礎