windows下使用vscode+cmake调用opencv
3.1 使用cmake构建项目。
·
1、编写CMakeLists.txt
cmake_minimum_required(VERSION 3.20) # 指定运行的cmake最低版本
project(demo_cpp)
set(OpenCV_DIR G:/Install_package/opencv/build) # 设置OpenCV_DIR的路径
find_package(OpenCV) #cmake会到OpenCV_DIR目录下寻找OpenCVConfig.cmake文件,自动配置opencv
include_directories(${OpenCV_INCLUDE_DIRS}) # 包含头文件
message(${OpenCV_INCLUDE_DIRS})
message(${OpenCV_LIBS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS}) # 链接文件
2、编写main.cpp
#include <iostream>
#include "opencv2/opencv.hpp"
int main()
{
std::cout << "hello,world" << std::endl;
cv::Mat Image = cv::imread("D:/6_cuda_code/cuda-image-preprocess/lena.jpg");
std::cout << "Image.cols:" <<Image.cols << ",Image.cols:"<< Image.rows<< std::endl;
return 0;
}
3、编译运行程序
3.1 使用cmake构建项目
cmake -B build -G"Visual Studio 16 2019"
3.2 编译项目
cmake --build build
3.3 运行exe
.\build\Debug\main.exe
更多推荐
所有评论(0)