c++ - 如何在 VSCODE 中使用 OpenCV C++

标签 c++ opencv visual-studio-code

基于此视频 https://www.youtube.com/watch?v=l4372qtZ4dc 我正在尝试在 vscode 中使用 OpenCV,但我无法包含 .lib 文件我应该怎么做

enter image description here

main.cpp

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

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{

  if( argc != 2)
  {
    cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
    return -1;
  }

  Mat image;
  image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

  if(! image.data )                              // Check for invalid input
  {
      cout <<  "Could not open or find the image" << std::endl ;
      return -1;
  }

  namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
  imshow( "Display window", image );                   // Show our image inside it.

  waitKey(0);                                          // Wait for a keystroke in the window
  return 0;
}

我收到这个错误

PS C:\Users\giorg\Documents\Development\Tests\node-addons-test\src\examples> g++ *.cpp main.cpp:1:33: fatal error: opencv2/core/core.hpp: No such file or directory #include ^ compilation terminated.

我设法包含了 dll,但找不到如何包含扩展名为 .lib 的文件。

这是我的 c_cpp_properties.json 文件

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/src/lib",
                "C:\\openCV\\opencv\\build\\include",
                "C:\\openCV\\opencv\\build\\x64\\vc15\\lib"  <=== this is the problem , how to include this
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17134.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

最佳答案

为什么不加一个CMakeLists.txt来使用cmake呢,而且还是跨平台的,简单易用。 我也使用 VS Code。我建议使用 cmake。

关于c++ - 如何在 VSCODE 中使用 OpenCV C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51564772/

相关文章:

c++ - 如何找到库以使用 dlopen 动态加载它们

c++ - OpenCV 到 FlyCapture2 图像

python-3.x - 使用图像的每个像素的每个位制作 8 个图像

git - Visual Studio Code 不允许更改 GitHub 用户 - Git :remote: Permission to Org/Rep denied

c++ - 错误 1 ​​错误 C4700 : uninitialized local variable 'rate' and 'hours' in C++

c++ - 随机选择字典单词

c++ - 在 C++ 中保存 QML 图像

python - cv2 imread 返回 None

visual-studio-code - 突出显示 Visual Studio Code C++ 扩展中的错误语法

c# - VS Code IntelliSense 不适用于 Unity3d