vscode OpenCV环境搭建

cmake

官网https://cmake.org/files/

环境变量D:\Program Files\CMake\bin

w64devkit

官网https://github.com/skeeto/w64devkit/tags

环境变量D:\Program Files\w64devkit\bin

minGW32-make 拷贝并重命名为make

OpenCV

在执行完后,把关于python的都给取消勾选。勾选BUILD_opencv_world,WITH_OPENGL和BUILD_EXAMPLES,不勾选WITH_IPP、WITH_MSMF和ENABLE_PRECOMPILED_HEADERS(如果有的话),CPU_DISPATCH选空。

make -j 4

make install

环境变量D:\repocpp\opencv\build\x64\mingw\bin

vscode配置和测试

打开vscode按Ctrl+Shift+p,点击"C/C++:Edit Configurations(JSON)"就可以生成.vscode文件夹

launch.json

cpp 复制代码
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Program Files\\w64devkit\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        }
    ]
}

c_cpp_properties.json

cpp 复制代码
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include",
                "D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include\\opencv2"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}

tasks.json

cpp 复制代码
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "D:\\Program Files\\w64devkit\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-I",
                "D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include",
                "-I",
                "D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include\\opencv2",
                "-L",
                "D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\x64\\mingw\\lib",
                "-llibopencv_world455"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "调试器生成的任务。"
        },
    ],
    "version": "2.0.0"
}

测试

拷贝opencv_videoio_ffmpeg455_64.dll,libopencv_world455.dll到项目根目录,文件所在目录D:\repocpp\opencv\build\x64\mingw\install\x64\mingw\bin

cpp 复制代码
 
#include <opencv2/opencv.hpp>
#include <iostream>
 
using namespace cv;
using namespace std;
 
int main()
{
    VideoCapture cap(0);
    Mat img;
 
    while (1)
    {
        cap >> img;
        if (img.empty())
            break;
        namedWindow("img", WINDOW_NORMAL);
        imshow("img", img);
        if (27 == waitKey(20))
            break;
    }
 
    return 0;
}
 
相关推荐
小灰灰__1 小时前
IDEA加载通义灵码插件及使用指南
java·ide·intellij-idea
Mortal_hhh2 小时前
VScode的C/C++点击转到定义,不是跳转定义而是跳转声明怎么办?(内附详细做法)
ide·vscode·stm32·编辑器
无极程序员2 小时前
PHP常量
android·ide·android studio
凤枭香5 小时前
Python OpenCV 傅里叶变换
开发语言·图像处理·python·opencv
小黄人软件5 小时前
android浏览器源码 可输入地址或关键词搜索 android studio 2024 可开发可改地址
android·ide·android studio
ctrey_6 小时前
2024-11-4 学习人工智能的Day21 openCV(3)
人工智能·opencv·学习
可均可可6 小时前
C++之OpenCV入门到提高004:Mat 对象的使用
c++·opencv·mat·imread·imwrite
蒙娜丽宁7 小时前
《Python OpenCV从菜鸟到高手》——零基础进阶,开启图像处理与计算机视觉的大门!
python·opencv·计算机视觉
plmm烟酒僧7 小时前
Windows下QT调用MinGW编译的OpenCV
开发语言·windows·qt·opencv