gpt4 book ai didi

opencv - 如何使用 Visual Studio Code 编译 Opencv?

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:09 26 4
gpt4 key购买 nike

我用 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 吗??

最佳答案

操作系统: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 文件

{
"version": "0.2.0",
"configurations": [
{
"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
}]
}
}
]
}

关于opencv - 如何使用 Visual Studio Code 编译 Opencv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40871782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com