AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

opencv库配置,windows,vscode

作者: 作者的头像   东非肛肠科主任 ,  2023-05-16 14:50:48 ,  所有人可见 ,  阅读 188


1


1.去gitee上下载,opencv 的release 版本
https://gitee.com/mirrors_huihut/OpenCV-MinGW-Build

2 解压
opencv1.png

3.将动态链接库加入到环境变量
新建 %OPENCV_LIB_HOME%
值为 D:\dev\C++Lib\OpenCV-MinGW-Build-OpenCV-4.5.2-x64\x64\mingw\bin

将 %OPENCV_LIB_HOME% 加入到Path 中去

g++ 参数简介:
-g: debug 信息

-I: 告诉编译器,头文件里的 #include<…> 去哪儿找

-L: 告诉编译器,添加一个要动态链接的目录

-l: 指定具体的动态链接库的名称

VS Code 项目配置

c_cpp_properties.json
参数说明:
includePath 头文件位置
/** 表示递归查找子目录

defines : 宏定义

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:\\dev\\C++Lib\\OpenCV-MinGW-Build-OpenCV-4.5.2-x64\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\BasicSoftware\\mingw64\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "g++ build",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-I",
                "D:\\dev\\C++Lib\\eigen-3.4.0",
                "-I",
                "D:\\dev\\C++Lib\\OpenCV-MinGW-Build-OpenCV-4.5.2-x64\\include",
                "-L",
                "D:\\dev\\C++Lib\\OpenCV-MinGW-Build-OpenCV-4.5.2-x64\\x64\\mingw\\bin",
                "-l",
                "libopencv_calib3d452",
                "-l",
                "libopencv_core452",
                "-l",
                "libopencv_dnn452",
                "-l",
                "libopencv_features2d452",
                "-l",
                "libopencv_flann452",
                "-l",
                "libopencv_gapi452",
                "-l",
                "libopencv_highgui452",
                "-l",
                "libopencv_imgcodecs452",
                "-l",
                "libopencv_imgproc452",
                "-l",
                "libopencv_ml452",
                "-l",
                "libopencv_objdetect452",
                "-l",
                "libopencv_photo452",
                "-l",
                "libopencv_stitching452",
                "-l",
                "libopencv_video452",
                "-l",
                "libopencv_videoio452",
                "-l",
                "opencv_videoio_ffmpeg452_64"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "build task"
        }
    ],
    "version": "2.0.0"
}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) 启动",// 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppvsdbg",// 配置类型,这里只能为 cppdbg
            "request": "launch",//请求配置类型,可以为 launch(启动)或 attach(附加)
            "program": "${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "console": "externalTerminal"
        }



    ]
}

main.cpp

#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>

using namespace cv;

int main()
{
    Mat img = imread("abc.png");
    imshow("image", img);
    waitKey();
    return 0;
}

运行效果
opencv2.png

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息