在这里,前期已经在rk3588上搭建好了livox hap的环境,搭建好了ros环境,搭建好了rknn环境,接下来搭建PCL环境,因为后期的点云数据处理基本上都要用到PCL库处理点云数据。这里的搭建是看了下面博主的内容,抄过来只是为了以后再次搭建时方便查阅,本文为了方便对以下博客作了略微的改变。
ubuntu20.04安装pcl_ubuntu20.04 pcl1.12+vtk9.1+qt6-CSDN博客
具体步骤如下:
1.先安装各种依赖(有的安装会报错,不用管)
sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
其他依赖
sudo apt-get install libqhull* libgtest-dev
sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install libopenni-dev
sudo apt-get install libopenni2-dev
2.源码安装vtk库
(很重要!!!apt安装的方式会出现.so文件缺失的情况!)
2.1首先安装依赖项X11,OpenGL,CMake-gui
- x11
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
- OpenGL
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
- cmake
sudo apt-get install cmake cmake-gui
2.2下载vtk源码
$ git clone https://github.com/PointCloudLibrary/pcl.git
2.3 切换文件目录到vtk-7.1.1文件夹下的build文件夹,然后打开cmd窗口,输入:
make -j8
sudo make install
完成vtk库的安装.
3.安装pcl
去pcl官方github下载需要的pcl版本放到主目录下
然后:
cd pcl
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=None ..
make (如果速度太慢用 make -j8 ;默认使用单核make,-j8启用8核)
sudo make install
4.pcl 测试
把pcl_test.cpp和CMakeLists.txt放在同一个文件夹里,并创建build文件夹,如下图
测试代码pcl_test.cpp内容如下:
#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>
int main(int argc, char **argv) {
std::cout << "Test PCL !!!" << std::endl;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
uint8_t r(255), g(15), b(15);
for (float z(-1.0); z <= 1.0; z += 0.05)
{
for (float angle(0.0); angle <= 360.0; angle += 5.0)
{
pcl::PointXYZRGB point;
point.x = 0.5 * cosf (pcl::deg2rad(angle));
point.y = sinf (pcl::deg2rad(angle));
point.z = z;
uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
point.rgb = *reinterpret_cast<float*>(&rgb);
point_cloud_ptr->points.push_back (point);
}
if (z < 0.0)
{
r -= 12;
g += 12;
}
else
{
g -= 12;
b += 12;
}
}
point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();
point_cloud_ptr->height = 1;
pcl::visualization::CloudViewer viewer ("test");
viewer.showCloud(point_cloud_ptr);
while (!viewer.wasStopped()){ };
return 0;
}
CMakeLists.txt文件内容如下:(直接输入以下代码)
cmake_minimum_required(VERSION 2.6)
project(pcl_test)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcl_test pcl_test.cpp)
target_link_libraries (pcl_test ${PCL_LIBRARIES})
install(TARGETS pcl_test RUNTIME DESTINATION bin)
执行如下命令:
cd build
cmake ..
make
./pcl_test
就可以看到一个漂亮的3D模型