如何将RealSense2/OpenCV源代码包含在CMake的编译中? [英] How do I include RealSense2/OpenCV source into compilation with CMake?

查看:864
本文介绍了如何将RealSense2/OpenCV源代码包含在CMake的编译中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将OpenCV和librealsense2的(未编译的)源文件与CMake捆绑在一起,以便可以在RPi上交叉编译(或根本不交叉编译),但是我对CMake还是陌生的,不知道怎么做.

I want to bundle the (uncompiled) source files for OpenCV and librealsense2 with CMake so I can cross compile it on RPi (or at all), but I am new to CMake and don't know how.

add_executable (CMakeRealSense "CMakeRealSense.cpp" "CMakeRealSense.h")

include_directories(opencv libs/opencv-master/include)
include_directories(realsense2 libs/librealsense-master/include)

这会产生大量与RS文件本身有关的错误(未在作用域上声明X).

This gives a bunch of errors related to RS files itself (X not declared on scope).

我目前正在尝试为Intel RealSense相机d435编写程序.我正在使用两个库. OpenCV和librealsense2(相机的实际库).我首先使用VCPKG加载软件包,并且该软件包可在本地计算机上使用,但无法在RPi 3上正确编译.我决定将源文件与项目捆绑在一起是个好主意,但我不能得到它的工作.我遇到了一个接一个的错误.

I am currently attempting to write a program for the Intel RealSense camera d435. There are two libraries I am using. OpenCV and librealsense2 (actual library for the camera). I first used VCPKG to load the packages in, and that works for my local machine, but I can't properly compile it on the RPi 3. I decided that bundling source files with the project would be good idea, but I can't get it to work. I'm getting one error after another.

在本地Windows机器上编译时,出现错误Cannot open include file: 'opencv2/opencv_modules.hpp': No such file or directory.而且,在我的pi上,它给出了一堆与RealSense文件本身有关的错误(没有检查所有错误,在那里有780个错误)

When I compile on my local windows machine I get error Cannot open include file: 'opencv2/opencv_modules.hpp': No such file or directory. And, on my pi it gives a bunch of errors related to RealSense files themselves (didn't check them all, there where 780 of them)

@squareskittles指出.我修复了与本地Windows版本有关的问题,但对于pi,我仍然遇到新错误的问题.

As pointed out by @squareskittles. I fixed the issue relating to my local windows version, but for the pi I still have issues with new errors.

从我可以告诉错误的状态来看,它找不到文件夹toolssrcexamples中的opengl_config.cmake文件夹(examples将被删除,因此问题).最后一个错误是

From what I can tell the error states that it can't find the opengl_config.cmake folder in folders tools, src and examples (examples will be removed down the line so not much of a issue). Last error is

CMake Error at libs/librealsense-master/CMake/install_config.cmake:4 (add_custom_target):
  add_custom_target cannot create target "uninstall" because another target
  with the same name already exists.  The existing target is a custom target
  created in source directory
  "/home/pi/.vs/CMakeRealSense/d6128cea-ef93-4c7b-83bb-89ee6315963f/src/libs/opencv-master".
  See documentation for policy CMP0002 for more details.

编辑4

因此,我首先只是添加了包含安装配置的cmake文件夹,该文件夹如何工作,第二个错误似乎是librealsenseopencv在卸载配置中都具有相同的名称.可以安全更改更改add_custom_target而不影响其余的cmake构建过程吗?

EDIT 4

So I firstly just added the cmake folder containing the install config and that works how, the 2nd error how ever seems to be that both librealsense and opencv have the same name in the uninstall config. Can the add_custom_target for uninstall be safely changed without effecting the rest of the cmake building process?

它成功编译了realsense2库(据我所知),但是无法打开opencv2/core.hpp源文件.不确定为什么找不到它.

It succesfully compiles the realsense2 libraries (as far as I can tell) but it cant open the opencv2/core.hpp source file. Not sure why it cant find it.

所以我做了很多挖掘工作,并且opencv使用头文件来检查您正在使用的模块,

So I did ALOT more digging and aperently opencv uses a header file to check which modules your using, problem is it doesnt properly generate one. I am not sure how to do this but ill do some more digging to find out

推荐答案

如果要将OpenCV和RealSense2源代码直接包含在CMake项目中,则应使用

If you want to include the OpenCV and RealSense2 source in your CMake project directly, you should use the add_subdirectory() command to tell CMake to look in each of the directories. Be sure to provide the path to the top-level CMakeLists.txt file in each of the other source repositories, or they will not be configured completely:

add_subdirectory(libs/opencv-master)
add_subdirectory(libs/librealsense-master)

稍后,在CMakeLists.txt文件中,您需要使用在每个子存储库中定义的CMake变量和目标,以便将这些库中的每个库包含在您的可执行文件中.例如:

Later on in your CMakeLists.txt file, you need to make use of the CMake variables and targets defined in each of these sub-repositories in order to include each of these libraries in your executable. For example:

# Define your CMake executable target.
add_executable(CMakeRealSense CMakeRealSense.cpp CMakeRealSense.h)

# Link the OpenCV components and RealSense targets to your executable target.
target_link_libraries(CMakeRealSense PRIVATE opencv_core realsense2)

根据所使用的OpenCV功能,您可能还必须链接其他OpenCV组件,例如opencv_imgprocopencv_dnnopencv_imgcodecsopencv_videoioopencv_highgui等.

You may also have to link additional OpenCV components, such as opencv_imgproc, opencv_dnn, opencv_imgcodecs, opencv_videoio, opencv_highgui, etc, depending on what OpenCV functionality you are using.

这篇关于如何将RealSense2/OpenCV源代码包含在CMake的编译中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆