PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.99k stars 4.62k forks source link

[compile error] "Compile PCL with librealsense support" #5427

Open Gibtnix opened 2 years ago

Gibtnix commented 2 years ago

Hello everyone,

I have a problem regarding the Intel RealSense module.

I know that there are differences between the first librealsense and the librealsense2 versions: The former supports several old cameras that are not supported by the newer librealsense2 releases and newer cameras are only supported by the librealsense2 releases. Hence, I have to select the appropriate version. However at least according to my understanding for the CMake options WITH_RSSDK and WITH_RSSDK2, PCL should support both. I have different cameras available and some are only supported by the first librealsense version, thus my tests aimed particularly at this version. I also tried the same with the latest librealsense2 release with mainly the same results, still for explained reasoning my main aim is the old librealsense version.

In preparation to use it with PCL, I downloaded the latest version 1.12.4 from the librealsense GitHub repository and compiled it (Windows 10, Visual Studio 2022, 64 bit). Running the Install target creates a usual library structure containing header files, import libraries (*.lib), the DLL and a few programs that open the camera and show a live image. This verifies that the installation worked and that the SDK is usable.

Next, I tried to compile PCL with support for this library and this is where my problems start. I know how to setup PCL and compile its dependencies from source. I have a working VS solution to compile PCL and its included apps (still without Qt support for the moment, i.e. some sample programs are missing, but this is also independent from my problem). My problem is only: How to get PCL working with my build of the librealsense library?

I activated the WITH_RSSDK flag and defined RSSDK_LIBRARY as well as RSSDK_DIR accordingly: The former I set to the fully qualified path to the import library realsense.lib, the latter I tried different options but I think it should point to the include path. Still, none of them worked. Whatever I select here, the solution contains no RealSense bindings. Next I inspected the FindRSSDK.cmake script and it expects a file pcxversion.h that contains a definition of a library version. Still, this file is not contained in the build / install output of the librealsense library. To proceed somehow, I created it only containing the content #define PCX_VERSION_1 inside the librealsense include directory. Thereafter, running Configure / Generate in the CMake GUI creates a solution that seems to contain RealSense bindings, at least there is a pcl_real_sense_viewer project in the solution. However, this does not compile. It tries to include the files pcximage.h and pcxsession.h which do not exist.

Therefore I would like to ask: How can I use the librealsense build in combination with PCL or what else is missing here?

Your Environment (please complete the following information):

If PCL was compiled from source or failure in compiling PCL itself:

Possible Solution

Unknown.

Additional context

Compilation errors only refer to the librealsense integration. PCL itself (i.e. without librealsense support) compiles and runs fine.

mvieth commented 2 years ago

I don't have any experience with the old RSSDK, but here are my ideas: I don't think librealsense 1.x.y is what is meant with RSSDK. I think that would still count as RSSDK2, and RSSDK is something else. I found a repository (https://github.com/crosswalk-project/libpxc) that contains the necessary headers, but that is not an official Intel source. Intel seems to only offer the new librealsense ("RSSDK2"). You might be able to use the OpenNI(2) grabbers, depending on which cameras you want to use. Maybe @larshg or @UnaNancyOwen can tell you more

Gibtnix commented 2 years ago

Thanks for your response. :+1: I tested to integrate these headers, however including the headers only yields link errors. To fix these, the libpxc library needs to be compiled as well. Unluckily, it does not come with a CMakeLists.txt such that I don't know how to compile it. I also tried to use OpenNI, the latest Librealsense2 releases should come with OpenNI2 bindings. I compiled them as explained in the respective build instructions and copied the DLLs into the OpenNI2 binary directory, still OpenNI2 does not find the RealSense cameras. I'm still hoping that anybody knows how to integrate the RealSense bindings into PCL...

mvieth commented 2 years ago

Unluckily, it does not come with a CMakeLists.txt such that I don't know how to compile it

Something like this might already do the trick:

add_library(libpxc "src/libpxc/libpxc.cpp")
target_include_directories(libpxc PUBLIC include)
Gibtnix commented 2 years ago

Yes, I also tried something similar by adding the libpxc.cpp to the pcl_io project. Unluckily, I don't know the appropriate settings/defines. Adding the files yields compile errors, something about invalid conversions between different string data types. But I can lookup the actual error if it might be fixed.

Gibtnix commented 2 years ago

Just a quick updated: I retested to compile libpxc.cpp and it results in casting errors between LPCSTR, LPCWSTR and wchar_t*. I suspect they require the correct preprocessor defines.

Zhangxh251 commented 1 year ago

@Gibtnix may be Add RSSDK 2.0 (librealsense2) grabber can slove your problem. If you don't want to use PCL:realsense2gabber in your code, you can rewrite rs-pcl which is a Intel realsense official tutorial.

Gibtnix commented 1 year ago

Thanks for this comment, I think I will give rs-pcl a try. Regarding the RSSDK 2.0 comment: But this refers to the new RealSense SDK and thus, does not help with older cameras that are only supported by the legacy SDK. Or am I wrong here?