当前位置: 首页 > news >正文

windows下的vscode + opencv4.8.0(C++) 配置

1.添加环境变量
D:\mingw64\bin

2.安装vscode

3.下载opencv 4.8.0

4.程序引用第三方库(opencv为例)

打开CMakeLists.txt,引入头文件,使用include_directories 加入头文件所在目录。静态链接库link_directories

# 头文件
include_directories(D:/opencv4.8.0/opencv/build/include)
# 静态链接库
link_directories(D:/opencv4.8.0/opencv/build/x64/vc16/lib)

在main 函数所在文件 添加 #pragma comment(lib,“xxx.lib”),如果当前程序是Debug
加 opencv_world480d.lib;否则加opencv_world480.lib

#pragma comment(lib, "opencv_world480d.lib")

5.测试代码

#include <opencv2/opencv.hpp>
#include <iostream>
#pragma comment(lib, "opencv_world480d.lib")
using namespace cv;
using namespace std;int main(int argc, char** argv) {Mat src = imread("D:/Work/opencv_test/images/1.jpeg");if (src.empty()) {cout << "could not load image..." << endl;return -1;}imshow("input", src);waitKey(0);return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.28.0)
project(cpp_test)set(CMAKE_GENERATOR "MinGW Makefiles")
# 头文件
include_directories(D:/opencv4.8.0/opencv/build/include)
# 静态链接库
link_directories(D:/opencv4.8.0/opencv/build/x64/vc16/lib)
add_executable(app test01.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

tasks.json

{"version": "2.0.0","options": {"cwd": "${workspaceFolder}/build"},"tasks": [{"type": "shell","label": "cmake","command": "cmake","args": [".."]},{"label": "make","group": "build","command": "make","args": [],"problemMatcher": []},{"label": "Build","dependsOrder": "sequence","dependsOn": ["cmake","make"]},{"type": "cppbuild",//"label": "C/C++: g++ 生成活动文件","label": "Build",// "command": "/usr/bin/g++","command": "D://mingw64//bin//g++.exe","args": ["-fdiagnostics-color=always","-g","-o","${workspaceFolder}/bin/Debug/app.exe","-fexec-charset=GBK"],"options": {"cwd": "${workspaceFolder}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "D://mingw64//bin//g++.exe"}]
}

launch.json

{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "(gdb) 启动","type": "cppdbg","request": "launch","program": "${workspaceFolder}/bin/Debug/app.exe","args": ["-I", "D:\\opencv4.8.0\\opencv\\build\\include",//改成你自己的"-I", "D:\\opencv4.8.0\\opencv\\build\\include\\opencv2",//改成你自己的],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true},],"preLaunchTask": "Build","miDebuggerPath": "D://mingw64//bin//gdb.exe", // 修改为你的 gdb 路径},]
}

参考文章:

VScode编写C++概述(VScode 使用opencv与Eigen为例)_vscode c++使用opencv msvc-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/euphorias/article/details/120783669

windows环境下cmake创建MinGW类型makefile报错_cmake error: error: generator : mingw makefiles-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_48876595/article/details/129414407

http://www.lryc.cn/news/326060.html

相关文章:

  • 微信小程序之多视频暂停播放,超出可视区域停止播放视频在自定义组件中实现案例
  • Java 加载外部 Jar 中的类并通过反射调用类中的方法
  • Arduino+ESP8266+华为云物联网平台实现智能开关
  • 使用 python 拆分 excel 文件
  • uniapp小程序中onShareAppMessage(OBJECT)实现带参数的分享功能
  • 5个免费的3D钣金CAD软件
  • 3.26学习总结
  • Cisco Catalyst3850交换机RTU license使用方法
  • 简明 Python 教程(第5章 函数)
  • flutter 保存一堆多语言翻译词条,由key和value组成
  • 3月25日,每日信息差
  • Git常用指令使用
  • 数据结构与算法 顺序表的基本运算
  • docker部署nacos(单机与集群)
  • 开启Safari手势支持
  • Amuse:.NET application for stable diffusion
  • Java冒泡排序详细讲解
  • python数据解析xpath
  • 工业镜头常用参数之实效F(Fno.)和像圈
  • what is apache?
  • 【二叉树】Leetcode 94. 二叉树的中序遍历【简单】
  • Linux进程控制(等待)
  • 结构体-C语言
  • Unity DOTS中的baking(四)blob assets
  • 第三十天-Flask模板 Jinja2
  • 在项目中数据库如何优化?【MySQL主从复制(创建一个从节点复制备份数据)】【数据库读写分离ShardingJDBC(主库写,从库读)】
  • Fragment 与 ViewPager的联合应用(2)
  • OriginBot智能机器人开源套件
  • Java Web-Maven
  • .Net 异步委托