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;
}
 
相关推荐
wmd1316430671228 分钟前
IDEA插件CamelCase,快速转变命名格式
java·ide·intellij-idea
蓝黑202010 小时前
IntelliJ IDEA常用快捷键
java·ide·intellij-idea
锅巴编程11 小时前
VsCode 插件推荐(个人常用)
ide·vscode·编辑器
做个爱笑的大男孩11 小时前
VScode clangd插件安装
ide·vscode·编辑器
弗锐土豆12 小时前
工业生产安全-安全帽第二篇-用java语言看看opencv实现的目标检测使用过程
java·opencv·安全·检测·面部
如若12312 小时前
利用 `OpenCV` 和 `Matplotlib` 库进行图像读取、颜色空间转换、掩膜创建、颜色替换
人工智能·opencv·matplotlib
威桑14 小时前
CMake + mingw + opencv
人工智能·opencv·计算机视觉
大白要努力!15 小时前
Android opencv使用Core.hconcat 进行图像拼接
android·opencv
小林想被监督学习15 小时前
idea怎么打开两个窗口,运行两个项目
java·ide·intellij-idea
HoneyMoose15 小时前
IDEA 2024.3 版本更新主要功能介绍
java·ide·intellij-idea