OpenCV + 实感:Visual Studio Link 2019 错误

OpenCV + Realsense : Visual Studio Link 2019 error

我无法将 OpenCV 与 Intel 集成 Realsense Viewer source code.

备注: 我目前在 Windows 10.

我正在使用 visual studio 2017.msvc 14.12

opencv 版本是 3.4.1(windows 包),这是为您预先构建的版本。

我构建并安装了 intel realsense sdk from github. This was successful. I also built and successfully install the OpenCV examples using openCV I downloaded

当我尝试 link OpenCV to the realsense viewer project

时出现问题

我尝试 link openCV 到 Intel Realsense Viewer 所遵循的步骤:

  1. 打开visual studio中的intel realsense sdk解决方案(就是那个叫librealsense2的.sln)

  2. 去visual studio

  3. 里面的'solution explorer'面板里面的realsense-vewier项目
  4. 右击项目'realsense-viewer'然后select属性

  5. 确保上面的2个下拉框有'x64'和'all configurations'

  6. 转到C/C++ -> 常规选项(从左边的白色框开始)然后转到'Additional Include Directories'

  7. 在目录%OpenCVDownloadRoot%/build/include和%OpenCVDownloadRoot%/build/include/opencv中添加(这是示例OpenCV项目的配置

此时,openCV 的一些函数没有在 'realsense-viewer' 项目中正确地 linked(这很奇怪,因为 SDK 中的 OpenCV 项目中的工作,即使属性是一样的,报错如下:

然后我执行了一些额外的步骤,看看我是否可以让它工作。

  1. 在属性对话框(我们刚刚进入的对话框)中,而不是 selecting C/C++,select 'Linker'

  2. 在'Additional Libraries Directories'selection中,加入%OpenCVDownloadRoot%/build/x64/vc15/lib

  3. 在 'Linker' 属性中,搜索输入(链接器 -> 输入)

  4. 在'opencv_world341d.lib'里面加上'Additional Dependencies'selection.

现在我们得到一个完全不同的错误:

现在无法识别实感库。除上述内容外,未修改其他属性。我可以确认第 10 步导致了所有这些错误。即使我在执行所有步骤后将步骤 10 的操作反转,上述错误仍然存​​在 -> 这一定是一个 visual studio 错误。

关于如何让 OpenCV 3.4.1 + realsense-viewer(来自 SDK)在 visual studio 2017 中工作的任何帮助或提示?

编辑:我已经阅读: What is an undefined reference/unresolved external symbol error and how do I fix it?

但我已经正确 linked glfw 和所有其他需要 linked 的东西,以便错误消息消失。我认为问题可能是 intel 的错误,或者是 vs 的错误,需要解决方法

在公园散步后找到的解决方案(假设您使用的是 windows 10,visual studio 2017 项目):

进入您本地的 librealsense 项目文件夹

转到C:\Users\yourName\to\your\local\realsense\folder\librealsense\tools\CMakeLists.txt

将此添加到文件末尾:

find_package(OpenCV REQUIRED)

list(APPEND DEPENDENCIES realsense2 ${OpenCV_LIBS})

所以整个文件是这样的:

minimum required cmake version: 3.1.0 cmake_minimum_required(VERSION 3.1.0)

project(RealsenseTools)

Save the command line compile commands in the build output set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

View the makefile commands during build

set(CMAKE_VERBOSE_MAKEFILE on)

This parameter is meant for disabling graphical examples when building for

save-to-disk targets. option(BUILD_GRAPHICAL_EXAMPLES "Build graphical examples." ON)

include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") elseif(COMPILER_SUPPORTS_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") endif()

if(BUILD_GRAPHICAL_EXAMPLES) find_package(OpenGL) if(NOT OPENGL_FOUND) message(FATAL_ERROR "\n\n OpenGL package is missing!\n\n") endif()

set(DEPENDENCIES realsense2 ${OPENGL_LIBRARIES})

if(WIN32)
    list(APPEND DEPENDENCIES glfw3)
else()
    # Find glfw header
    find_path(GLFW_INCLUDE_DIR NAMES GLFW/glfw3.h
        PATHS /usr/X11R6/include
              /usr/include/X11
              /opt/graphics/OpenGL/include
              /opt/graphics/OpenGL/contrib/libglfw
              /usr/local/include
              /usr/include/GL
              /usr/include
    )
    # Find glfw library
    find_library(GLFW_LIBRARIES NAMES glfw glfw3
            PATHS /usr/lib64
                  /usr/lib
                  /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
                  /usr/local/lib64
                  /usr/local/lib
                  /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
                  /usr/X11R6/lib
    )
    if(APPLE)
        find_library(COCOA_LIBRARY Cocoa)
        find_library(IOKIT_LIBRARY IOKit)
        find_library(COREVIDEO_LIBRARY CoreVideo)
        LIST(APPEND DEPENDENCIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
    endif()
    list(APPEND DEPENDENCIES m ${GLFW_LIBRARIES} ${LIBUSB1_LIBRARIES})
    include_directories(${GLFW_INCLUDE_DIR})
endif() else()
set(DEPENDENCIES realsense2)
if(NOT WIN32)
    list(APPEND DEPENDENCIES m ${LIBUSB1_LIBRARIES})
endif() endif()

allow this project to access opencv find_package(OpenCV REQUIRED)

find_package(OpenCV REQUIRED) set(DEPENDENCIES realsense2 ${OpenCV_LIBS})

add_subdirectory(terminal) add_subdirectory(fw-logger) add_subdirectory(enumerate-devices) add_subdirectory(realsense-viewer) add_subdirectory(data-collect) add_subdirectory(depth-quality) add_subdirectory(rosbag-inspector)

然后使用 cmake gui 重建项目