如何使用Visual Studio Code编译Opencv?

时间:2016-11-29 17:12:34

标签: opencv g++ visual-studio-code

我用brew安装了opencv3。我多次尝试设置pkg-config但是我无法成功编译。我在网上搜索过但我找不到。

任务如下:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "showOutput": "always",
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "build",
            "isBuildCommand": true,
            "args": [
                `pkg-config --libs opencv --cflags opencv`,
                "-o", 
                "vsc",
                "${workspaceRoot}/main.cpp",
                "-g" // Debug
            ],
            "showOutput": "always"
        }
    ]
}

我的pkg-config如下所示:

pkg-config --libs

$ pkg-config --libs opencv
-L/usr/local/Cellar/opencv3/3.1.0_3/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lippicv -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core

pkg-config --cflags

$ pkg-config --cflags opencv
-I/usr/local/Cellar/opencv3/3.1.0_3/include/opencv -I/usr/local/Cellar/opencv3/3.1.0_3/include

您知道如何使用Visual Studio Code编译opencv吗?

1 个答案:

答案 0 :(得分:1)

操作系统: Ubuntu 16.04 ,OpenCV版本: 3.2.0 ,程序文件名:videocapture_starter.cpp,输出文件名:videocapture_starter

要构建我使用了以下task.json文件

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "g++", "isShellCommand": true, "showOutput": "always", "args": ["-g", "videocapture_starter.cpp", "-o", "videocapture_starter", "-I/usr/local/include/opencv", "-I/usr/local/include","-I/usr/include", "-L/usr/local/lib", "-lopencv_shape", "-lopencv_stitching", "-lopencv_objdetect", "-lopencv_superres", "-lopencv_videostab", "-lopencv_calib3d", "-lopencv_features2d", "-lopencv_highgui", "-lopencv_videoio", "-lopencv_imgcodecs", "-lopencv_video", "-lopencv_photo", "-lopencv_ml", "-lopencv_imgproc", "-lopencv_flann", "-lopencv_core"] }

为了调试程序,我使用了以下的launch.json文件 “{   “版本”:“0.2.0”,   “配置”:[

{
  "name": "C++ Launch",
  "type": "cppdbg",
  "request": "launch",
  "program": "${workspaceRoot}/videocapture_starter",
  "args": ["0"],
  "stopAtEntry": false,
  "cwd": "${workspaceRoot}",
  "environment": [],
  "externalConsole": true,
  "linux": {
    "MIMode": "gdb",
    "includePath": ["/usr/include", "/usr/local/include/opencv", "/usr/local/include"],
    "setupCommands": [
      {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": true
      }]
  }
},
{
  "name": "C++ Attach",
  "type": "cppdbg",
  "request": "attach",
  "program": "${workspaceRoot}/a.out",
  "processId": "${command:pickProcess}",
  "linux": {
    "MIMode": "gdb",
    "setupCommands": [
      {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": true
      }]
  }}]}'