如何在 VSCODE 中使用 OpenCV c

新手上路,请多包涵

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

在此处输入图像描述

主文件

#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: 致命错误: opencv2/core/core.hpp: 没有这样的文件或目录#include ^ 编译终止。

我设法包含了 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
}

原文由 George C. 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 581
1 个回答

当您使用 CMake 时,您使用的编辑器/IDE 并不重要。在 CMake 中添加外部库的方法有很多:

  1. 使用 FindPackage
  2. 使用 子模块
  3. 使用 手动将 .h/.hpp 和 lib(dll/so/a/lib) 文件添加到您的项目中
  4. 甚至更多

向项目添加外部库的最简单方法之一是子模块。只需搜索子模块并学习它,然后您就可以轻松地使用项目中的任何库。

这是一个 .cmake 文件,您可以使用它来更轻松地进行子模块 https://www.scivision.dev/cmake-git-submodule/

以及这里的教程:

https://web.archive.org/web/20210703145609/https://github.blog/2016-02-01-working-with-submodules/

原文由 SdSaati 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题